Exemple #1
0
        static int Main(string[] args)
        {
            var app = ShellHelper.CreateConsoleApp(APP_NAME, "Command line for Proxmox VE");

            ShellCommands.Commands(app);
            return(app.ExecuteConsoleApp(args));
        }
        private static bool ParseLine(string input,
                                      PveClient client,
                                      ClassApi classApiRoot,
                                      AliasManager aliasManager,
                                      bool onlyResult)
        {
            if (string.IsNullOrWhiteSpace(input))
            {
                return(false);
            }
            input = input.Trim();

            //comment
            if (input.StartsWith("#"))
            {
                return(false);
            }

            using (var app = new CommandLineApplication())
            {
                var exit = false;

                app.Name        = "";
                app.Description = "Corsinvest Interactive Shell API for Proxmox VE";
                app.DebugOption();
                app.DryRunOption();
                app.UsePagerForHelpText = false;
                app.HelpOption(true);

                ShellCommands.SumCommands(app, client, classApiRoot);

                //fix help text
                foreach (var command in app.Commands)
                {
                    command.FullName            = app.Description;
                    command.ExtendedHelpText    = "";
                    command.UsePagerForHelpText = false;
                }

                //create command from alias
                CreateCommandFromAlias(app, client, classApiRoot, aliasManager, onlyResult);

                #region Commands base
                app.Command("quit", cmd =>
                {
                    cmd.AddName("exit");
                    cmd.Description          = "Close application";
                    cmd.OnExecute(() => exit = true);
                });

                app.Command("clear", cmd =>
                {
                    cmd.AddName("cls");
                    cmd.Description = "Clear screen";
                    cmd.OnExecute(() => Console.Clear());
                });

                app.Command("help", cmd =>
                {
                    cmd.Description = "Show help information";
                    cmd.OnExecute(() => app.ShowHelp());
                });

                CmdAlias(app, aliasManager);
                CmdHistory(app, onlyResult);
                #endregion

                app.OnExecute(() => app.ShowHint());

                //execute command
                try { app.Execute(StringHelper.TokenizeCommandLineToList(input).ToArray()); }
                catch (CommandParsingException ex) { Console.Out.WriteLine(ex.Message); }
                catch (Exception) { }

                return(exit);
            }
        }