Example #1
0
        public static void Configure(CommandLineApplication app)
        {
            app.Name = "dbtool";
            app.HelpOption("-?|-h|--help");

            var options = new GlobalOptions();

            options.LocalConfigFilePathOption =
                app.Option("--config|-c",
                           "Config file path",
                           CommandOptionType.SingleValue)
                .Accepts(configure => configure.ExistingFile("Configuration file does not exist"));

            options.FormatOption = app.Option("--format|-f",
                                              "Exporting/importing format (xml | json)",
                                              CommandOptionType.SingleValue)
                                   .Accepts(config => config.Values(ignoreCase: true, "xml", "json"));


            // Register commands
            app.Command("export", c => ExportCommand.Configure(c, options));
            app.Command("import", c => ImportCommand.Configure(c, options));
            app.Command("connections", c => ConnectionsCommand.Configure(c, options));

            app.OnExecute(new RootCommand(app, options).Run);
        }
        public static void Configure(CommandLineApplication command, GlobalOptions options)
        {
            command.Description = "Manipulates with connections (add, remove, list)";
            command.HelpOption("-?|-h|--help");

            // add local config option
            command.Options.Add(options.LocalConfigFilePathOption);

            // add connections subcommands
            command.Command("add", c => ConnectionsAddCommand.Configure(c, options));
            command.Command("remove", c => ConnectionsRemoveCommand.Configure(c, options));
            command.Command("list", c => ConnectionsListCommand.Configure(c, options));

            Func <int> runCommandFunc = new ConnectionsCommand(command).Run;

            command.OnExecute(runCommandFunc);
        }