Beispiel #1
0
        //---------------------------------------------------------------------
        public static CommandLineOptions Parse(string[] args)
        {
            var cmdOptions = new CommandLineOptions();
            var app        = new CommandLineApplication();

            var simulate = app.Option("-s|--simulate", "perform a simulation dumping to standard output (does not affect any file!)", CommandOptionType.NoValue);
            var output   = app.Option("-o|--output", "output folder. default is current directory.", CommandOptionType.SingleValue);

            RootCommandConfiguration.Configure(app, cmdOptions);

            int    result = 1;
            string error  = "error!";

            try
            {
                result = app.Execute(args);
            }
            catch (Exception ex)
            {
                error = ex.Message;
            }

            if (result != 0)
            {
                Console.Error.WriteLine(error);
                return(null);
            }

            cmdOptions.Globals.Simulate     = simulate.HasValue();
            cmdOptions.Globals.OutputFolder = output.Value() ?? Directory.GetCurrentDirectory();

            return(cmdOptions);
        }
Beispiel #2
0
        public static CommandLineOptions Parse(string[] args)
        {
            var options = new CommandLineOptions();

            var app = new CommandLineApplication
            {
                Name     = "vsts-gitops",
                FullName = "VSTS GitOps command line utility"
            };

            app.HelpOption("-?|-h|--help");



            var enthousiasticSwitch = app.Option("-e|--enthousiastically",
                                                 "Whether the app should be enthousiastic.",
                                                 CommandOptionType.NoValue);



            RootCommandConfiguration.Configure(app, options);

            var result = app.Execute(args);

            if (result != 0)
            {
                return(null);
            }

            options.IsEnthousiastic = enthousiasticSwitch.HasValue();

            return(options);
        }
Beispiel #3
0
        public static CommandLineOptions Parse(string[] args)
        {
            var options = new CommandLineOptions();

            var app = new CommandLineApplication();

            RootCommandConfiguration.Configure(app, options);

            var result = app.Execute(args);

            if (result != 0 || options.Command == null)
            {
                Console.Error.WriteLine("Fail");
                return(null);
            }

            return(options);
        }
Beispiel #4
0
        public static CommandLineOptions Parse(string[] args)
        {
            var options = new CommandLineOptions();

            var app = new CommandLineApplication
            {
                Name     = "cassandra-migrate",
                FullName = ".NET Core Cassandra migrator"
            };

            app.HelpOption("-?|-h|--help");

            var hosts = app.Option("-H|--host",
                                   "The cassandra hosts to connect to",
                                   CommandOptionType.MultipleValue);

            var port = app.Option("-p|--port",
                                  "The cassandra port",
                                  CommandOptionType.SingleValue);

            var user = app.Option("-u|--user",
                                  "The username",
                                  CommandOptionType.SingleValue);

            var password = app.Option("-P|--password",
                                      "The username",
                                      CommandOptionType.SingleValue);

            RootCommandConfiguration.Configure(app, options);

            var result = app.Execute(args);

            if (result != 0)
            {
                return(null);
            }

            options.Host     = hosts.Values;
            options.Port     = port.Value();
            options.Username = user.Value();
            options.Password = password.Value();

            return(options);
        }
Beispiel #5
0
        public static CommandLineOptions Parse(IServiceProvider serviceProvider, string[] args)
        {
            var options = new CommandLineOptions();

            var app = new CommandLineApplication(throwOnUnexpectedArg: false)
            {
                Name     = "mpv",
                FullName = "mpv - A tool to help with your multi-package .NET projects"
            };

            app.HelpOption("-?|-h|--help");

            RootCommandConfiguration.Configure(app, options, serviceProvider);

            int result = app.Execute(args);

            return(result != 0
                ? null
                : options);
        }
        /// <summary>
        /// Parses the specified arguments.
        /// </summary>
        /// <param name="args">The arguments.</param>
        /// <returns></returns>
        public static CommandLineOptions Parse(string[] args)
        {
            var options = new CommandLineOptions();

            var app = new CommandLineApplication
            {
                Name     = "people-search",
                FullName = "People Search Console"
            };

            app.HelpOption("-?|-h|--help");

            RootCommandConfiguration.Configure(app, options);

            var result = app.Execute(args);

            if (result != 0)
            {
                return(null);
            }

            return(options);
        }
Beispiel #7
0
        public static CommandLineOptions Parse(string[] args)
        {
            var options = new CommandLineOptions();

            var app = new CommandLineApplication
            {
                Name     = "TRuDI.HanAdapter.Test",
                FullName = "TRuDI HAN Adapter Test Application"
            };

            app.HelpOption("-?|-h|--help");

            var logFileOption  = app.Option("-l|--log <log-file>", "Logmeldungen werden in die angegebene Datei geschrieben.", CommandOptionType.SingleValue);
            var logConsole     = app.Option("--log-console", "Logmeldungen werden auf der Konsole ausgegeben.", CommandOptionType.NoValue);
            var logLevelOption = app.Option("--loglevel <log-level>", "Log Level: verbose, debug, info, warning, error, fatal. Standard ist info.", CommandOptionType.SingleValue);
            var testFileOption = app.Option("-t|--test <test-config>", "Aktiviert den Test-HAN-Adapter mit der angegebenen Konfigurationsdatei.", CommandOptionType.SingleValue);

            var outputFile = app.Option("-o|--output <output-file>", "Ausgabedatei.", CommandOptionType.SingleValue);

            RootCommandConfiguration.Configure(app, options);

            var result = app.Execute(args);

            if (result != 0)
            {
                return(null);
            }

            // Init logging...
            var logLevelSwitch = new LoggingLevelSwitch {
                MinimumLevel = LogEventLevel.Information
            };

            if (logLevelOption.HasValue())
            {
                switch (logLevelOption.Value().ToLowerInvariant())
                {
                case "verbose":
                    logLevelSwitch.MinimumLevel = LogEventLevel.Verbose;
                    break;

                case "debug":
                    logLevelSwitch.MinimumLevel = LogEventLevel.Debug;
                    break;

                case "info":
                    logLevelSwitch.MinimumLevel = LogEventLevel.Information;
                    break;

                case "warning":
                    logLevelSwitch.MinimumLevel = LogEventLevel.Warning;
                    break;

                case "error":
                    logLevelSwitch.MinimumLevel = LogEventLevel.Error;
                    break;

                case "fatal":
                    logLevelSwitch.MinimumLevel = LogEventLevel.Fatal;
                    break;
                }
            }

            if (logFileOption.HasValue())
            {
                if (logConsole.HasValue())
                {
                    Log.Logger = new LoggerConfiguration().MinimumLevel.ControlledBy(logLevelSwitch)
                                 .WriteTo.Trace()
                                 .WriteTo.ColoredConsole()
                                 .WriteTo.File(logFileOption.Value())
                                 .CreateLogger();
                }
                else
                {
                    Log.Logger = new LoggerConfiguration().MinimumLevel.ControlledBy(logLevelSwitch)
                                 .WriteTo.Trace()
                                 .WriteTo.File(logFileOption.Value())
                                 .CreateLogger();
                }
            }
            else
            {
                if (logConsole.HasValue())
                {
                    Log.Logger = new LoggerConfiguration().MinimumLevel.ControlledBy(logLevelSwitch)
                                 .WriteTo.Trace()
                                 .WriteTo.ColoredConsole()
                                 .CreateLogger();
                }
                else
                {
                    Log.Logger = new LoggerConfiguration().MinimumLevel.ControlledBy(logLevelSwitch)
                                 .WriteTo.Trace()
                                 .CreateLogger();
                }
            }

            // Output file
            if (outputFile.HasValue())
            {
                options.OutputFile = outputFile.Value();
            }

            return(options);
        }