示例#1
0
        private void InitCommands()
        {
            Command cmdOpen = new Command("Open", "open", description: "Opens a result with the default application.");

            cmdOpen.Parameters.Add(new ParamDef("index", null, typeof(int), description: "The index of the item to open."));
            cmdOpen.OnExecuted += OpenResult;

            commandLine.Register(cmdOpen);

            Command cmdClear = new Command("Clear", "clear", Aliases.Create("cls"), "Clears the window.");

            cmdClear.OnExecuted += data => console.Clear();

            commandLine.Register(cmdClear);

            Command cmdExit = new Command("Exit", "exit", Aliases.Create("q", "quit", "stop"), "Exits the fsu shell.");

            cmdExit.OnExecuted += data => cli.IsRunning = false;

            commandLine.Register(cmdExit);

            Command cmSim = new Command("Simulate", "simulate", Aliases.Create("sim"), "Enable/disable simulation mode.");

            cmSim.Parameters.Add(new ParamDef("value", string.Empty, typeof(string), "True to enable simulation mode, leave blank for toggle"));
            cmSim.OnExecuted += data => {
                string value = data.Parameters.Get <string>("value");
                if (string.IsNullOrWhiteSpace(value))
                {
                    fsu.Pipeline.Simulate = !fsu.Pipeline.Simulate;
                }
                else if (bool.TryParse(value, out bool simulate))
                {
                    fsu.Pipeline.Simulate = simulate;
                }
                data.Output.WriteLine(Level.Info, $"Simulation mode is {(fsu.Pipeline.Simulate ? "&-a;on" : "&-c;off")}&-^;");
            };
            commandLine.Register(cmSim);

            Command cmdPersistent = new Command("Persistent", "persistent", Aliases.Create("p", "pstore"), "Enable/disable persistent property store.");

            cmdPersistent.Parameters.Add(new ParamDef("value", string.Empty, typeof(string), "True to enable persistent mode, leave blank for toggle"));
            cmdPersistent.OnExecuted += data => {
                string value = data.Parameters.Get <string>("value");
                if (string.IsNullOrWhiteSpace(value))
                {
                    fsu.PersistentStore = !fsu.PersistentStore;
                }
                else if (bool.TryParse(value, out bool persistentStore))
                {
                    fsu.PersistentStore = persistentStore;
                }
                data.Output.WriteLine(Level.Info, $"Persistent store mode is {(fsu.PersistentStore ? "&-a;on" : "&-c;off")}&-^;");
            };
            commandLine.Register(cmdPersistent);

            Command cmdPurge = new Command("Purge", "purge", Aliases.Create("clean"), "Clears the property store.");

            cmdPurge.OnExecuted += data => {
                fsu.PropertyStore.ClearAll();
                data.Output.WriteLine(Level.None, "&-c;Property store purged!&-^;");
            };
            commandLine.Register(cmdPurge);

            Command cmdStore = new Command("Store", "store", Aliases.Create("summary"), "Displays a summary of properties within the property store.");

            cmdStore.OnExecuted += data => {
                if (fsu.PropertyStore.Count == 0)
                {
                    data.Output.WriteLine(Level.None, "&-c;Property store is empty!&-^;");
                }
                else
                {
                    data.Output.WriteLine(Level.None, "\n------------- Property Store Summary --------------");
                    foreach (KeyValuePair <string, PropertyItem> item in fsu.PropertyStore)
                    {
                        data.Output.WriteLine(Level.None, $"{item.Key}: {item.Value.Value}");
                    }
                }
            };
            commandLine.Register(cmdStore);
        }