static int Main(string[] args)
        {
            CommandLine commandLine = null;

            try {
                commandLine = new CommandLine(description: "Example command line app")
                              .SetTraceFn(Console.WriteLine);

                var commandA = new Command <CommandAParams>(name: "cmd-a", description: "A command")
                               .SetHandler(HandlerA)
                               .AddParameter(new Parameter <string>(name: "name", description: "A name")
                                             .AddAlias("n"))
                               .AddParameter(new Parameter <int>(name: "count", description: "A count")
                                             .AddAlias("c"))
                               .AddParameter(new Parameter <float>(name: "factor", description: "A factor")
                                             .AddAlias("f"))
                               .AddParameter(new Parameter <DateTime>(name: "date-time", description: "A date-time")
                                             .AddAlias("dt")
                                             .SetOptional(DateTime.Now))
                               .AddParameter(new Parameter <bool>(name: "debug", description: "A debug flag")
                                             .AddAlias("d")
                                             .SetOptional(false))
                               .AddParameter(new Parameter <Bar>(name: "bar", description: "A bar")
                                             .AddAlias("b"));

                var commandB = new Command <CommandBParams>(name: "cmd-b", description: "Another command")
                               .SetHandler(HandlerB)
                               .AddParameter(new Parameter <string>(name: "thing", description: "A thing")
                                             .AddAlias("t"))
                               .AddParameter(new Parameter <TimeSpan>(name: "duration", description: "An amount of time")
                                             .AddAlias("d"));

                commandLine.AddCommand(commandA);
                commandLine.AddCommand(commandB);

                return(commandLine.Invoke(args));
            }
            catch (CommandLineSpecException e) {
                Console.WriteLine();
                Console.WriteLine(e.ToPrettyString(types: false, stackTrace: false));
                return(1);
            }
            catch (CommandLineException e) {
                Console.WriteLine();
                Console.WriteLine(e.ToPrettyString(types: false, stackTrace: false));
                Console.WriteLine(commandLine.Usage());
                return(1);
            }
            catch (Exception e) {
                Console.WriteLine();
                Console.WriteLine(e.ToPrettyString());
                return(1);
            }
        }
示例#2
0
/// <summary>
/// Update user interface with plugin additions
/// </summary>

        public static void UpdateUI()
        {
            if (PluginList == null)
            {
                return;
            }

            foreach (Plugin p in PluginList)
            {
                if (!p.Visible)
                {
                    continue;
                }

                foreach (ExtensionPoint e in p.ExtensionPoints)
                {
                    if (Lex.Ne(e.Type, "Mobius.Action"))
                    {
                        continue;
                    }

                    if (e.MenuBarPath != "")                     // add menu item
                    {
                        SessionManager.Instance.MainMenuControl.AddToolsMenuPluginItem(e.Label, "PluginCommand " + e.Id, e.Image, p.Visible, p.Enabled);
                    }

                    else if (e.CommandName != "" && p.Visible && p.Enabled)                     // add command line command
                    {
                        CommandLine.AddCommand(e.CommandName, e, 0, false, true);
                    }
                }
            }
        }
        private int Main(string[] args, Action <dynamic> asserts)
        {
            var commandLine = new CommandLine(description: "Example two command command line");

            var command1 =
                new Command <Command1Params>(name: "cmd1", description: "Command 1")
                .AddParameter(new Parameter <string>(name: "foo", description: "The foo string value"))
                .SetHandler(@params => Handler <Command1Params>(@params, asserts));

            var command2 =
                new Command <Command2Params>(name: "cmd2", description: "Command 2")
                .AddParameter(new Parameter <int>(name: "bar", description: "The bar int value"))
                .SetHandler(@params => Handler <Command2Params>(@params, asserts));

            commandLine.AddCommand(command1);
            commandLine.AddCommand(command2);

            return(commandLine.Invoke(args));
        }