当前位置: 首页>>代码示例>>C#>>正文


C# CommandLineApplication.Option方法代码示例

本文整理汇总了C#中CommandLineApplication.Option方法的典型用法代码示例。如果您正苦于以下问题:C# CommandLineApplication.Option方法的具体用法?C# CommandLineApplication.Option怎么用?C# CommandLineApplication.Option使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CommandLineApplication的用法示例。


在下文中一共展示了CommandLineApplication.Option方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        public static int Main(string[] args)
        {
            var app = new CommandLineApplication
            {
                Name = "guardrex-json-to-csproj-converter",
                FullName = "GuardRex JSON to CSPROJ Converter",
                Description = "Converts project.json into a .csproj file for the project",
            };
            app.HelpOption("-h|--help");

            var frameworkOption = app.Option("-f|--framework <FRAMEWORK>", "Target framework of application being published", CommandOptionType.SingleValue);
            var configurationOption = app.Option("-c|--configuration <CONFIGURATION>", "Target configuration of application being published", CommandOptionType.SingleValue);
            var projectPath = app.Argument("<PROJECT>", "The path to the project (project folder or project.json) being published. If empty the current directory is used.");

            app.OnExecute(() =>
            {
                var exitCode = new ConvertCommand(frameworkOption.Value(), configurationOption.Value(), projectPath.Value).Run();

                return exitCode;
            });

            try
            {
                return app.Execute(args);
            }
            catch (Exception e)
            {
                Reporter.Error.WriteLine(e.Message.Red());
                Reporter.Output.WriteLine(e.ToString().Yellow());
            }

            return 1;
        }
开发者ID:GuardRex,项目名称:GuardRex.JsonToCsprojConverter,代码行数:33,代码来源:Program.cs

示例2: Main

        static void Main(string[] args)
        {
            CommandLineApplication commandLineApplication = new CommandLineApplication(throwOnUnexpectedArg: false);
            CommandArgument directory = commandLineApplication.Argument("directory", "The directory to search for assemblies");
            CommandOption dgmlExport = commandLineApplication.Option("-dg|--dgml <filename>", "Export to a dgml file", CommandOptionType.SingleValue);
            CommandOption nonsystem = commandLineApplication.Option("-n|--nonsystem", "List system assemblies", CommandOptionType.NoValue);
            CommandOption all = commandLineApplication.Option("-a|--all", "List all assemblies and references.", CommandOptionType.NoValue);
            CommandOption noconsole = commandLineApplication.Option("-nc|--noconsole", "Do not show references on console.", CommandOptionType.NoValue);
            CommandOption silent = commandLineApplication.Option("-s|--silent", "Do not show any message, only warnings and errors will be shown.", CommandOptionType.NoValue);

            commandLineApplication.HelpOption("-? | -h | --help");
            commandLineApplication.OnExecute(() =>
            {
                var consoleLogger = new ConsoleLogger(!silent.HasValue());

                var directoryPath = directory.Value;
                if (!Directory.Exists(directoryPath))
                {
                    consoleLogger.LogMessage(string.Format("Directory: '{0}' does not exist.", directoryPath));
                    return -1;
                }

                var onlyConflicts = !all.HasValue();
                var skipSystem = nonsystem.HasValue();

                IDependencyAnalyzer analyzer = new DependencyAnalyzer() { DirectoryInfo = new DirectoryInfo(directoryPath) };

                consoleLogger.LogMessage(string.Format("Check assemblies in: {0}", analyzer.DirectoryInfo));

                var result = analyzer.Analyze(consoleLogger);

                if (!noconsole.HasValue())
                {
                    IDependencyVisualizer visualizer = new ConsoleVisualizer(result) { SkipSystem = skipSystem, OnlyConflicts = onlyConflicts };
                    visualizer.Visualize();
                }

                if (dgmlExport.HasValue())
                {
                    IDependencyVisualizer export = new DgmlExport(result, string.IsNullOrWhiteSpace(dgmlExport.Value()) ? Path.Combine(analyzer.DirectoryInfo.FullName, "references.dgml") : dgmlExport.Value(), consoleLogger);
                    export.Visualize();
                }

                return 0;
            });
            try
            {
                if (args == null || args.Length == 0)
                    commandLineApplication.ShowHelp();
                else
                    commandLineApplication.Execute(args);
            }
            catch (CommandParsingException cpe)
            {
                Console.WriteLine(cpe.Message);
                commandLineApplication.ShowHelp();
            }
        }
开发者ID:mikehadlow,项目名称:AsmSpy,代码行数:58,代码来源:Program.cs

示例3: Main

        public static int Main(string[] args)
        {
            DebugHelper.HandleDebugSwitch(ref args);

            var app = new CommandLineApplication();
            app.Name = "dotnet publish";
            app.FullName = ".NET Publisher";
            app.Description = "Publisher for the .NET Platform";
            app.HelpOption("-h|--help");

            var framework = app.Option("-f|--framework <FRAMEWORK>", "Target framework to compile for", CommandOptionType.SingleValue);
            var runtime = app.Option("-r|--runtime <RUNTIME_IDENTIFIER>", "Target runtime to publish for", CommandOptionType.SingleValue);
            var output = app.Option("-o|--output <OUTPUT_PATH>", "Path in which to publish the app", CommandOptionType.SingleValue);
            var configuration = app.Option("-c|--configuration <CONFIGURATION>", "Configuration under which to build", CommandOptionType.SingleValue);
            var projectPath = app.Argument("<PROJECT>", "The project to publish, defaults to the current directory. Can be a path to a project.json or a project directory");
            var nativeSubdirectories = app.Option("--native-subdirectory", "Temporary mechanism to include subdirectories from native assets of dependency packages in output", CommandOptionType.NoValue);

            app.OnExecute(() =>
            {
                var publish = new PublishCommand();

                publish.Framework = framework.Value();
                // TODO: Remove default once xplat publish is enabled.
                publish.Runtime = runtime.Value() ?? RuntimeIdentifier.Current;
                publish.OutputPath = output.Value();
                publish.Configuration = configuration.Value() ?? Constants.DefaultConfiguration;
                publish.NativeSubdirectories = nativeSubdirectories.HasValue();

                publish.ProjectPath = projectPath.Value;
                if (string.IsNullOrEmpty(publish.ProjectPath))
                {
                    publish.ProjectPath = Directory.GetCurrentDirectory();
                }

                if (!publish.TryPrepareForPublish())
                {
                    return 1;
                }

                publish.PublishAllProjects();
                Reporter.Output.WriteLine($"Published {publish.NumberOfPublishedProjects}/{publish.NumberOfProjects} projects successfully");
                return (publish.NumberOfPublishedProjects == publish.NumberOfProjects) ? 0 : 1;
            });

            try
            {
                return app.Execute(args);
            }
            catch (Exception ex)
            {
                Reporter.Error.WriteLine(ex.Message.Red());
                Reporter.Verbose.WriteLine(ex.ToString().Yellow());
                return 1;
            }
        }
开发者ID:yonglehou,项目名称:cli-1,代码行数:55,代码来源:Program.cs

示例4: Main

        public static int Main(string[] args)
        {
            DebugHelper.HandleDebugSwitch(ref args);

            var app = new CommandLineApplication();
            app.Name = "dotnet pack";
            app.FullName = ".NET Packager";
            app.Description = "Packager for the .NET Platform";
            app.HelpOption("-h|--help");

            var output = app.Option("-o|--output <OUTPUT_DIR>", "Directory in which to place outputs", CommandOptionType.SingleValue);
            var intermediateOutput = app.Option("-t|--temp-output <OUTPUT_DIR>", "Directory in which to place temporary outputs", CommandOptionType.SingleValue);
            var configuration = app.Option("-c|--configuration <CONFIGURATION>", "Configuration under which to build", CommandOptionType.SingleValue);
            var project = app.Argument("<PROJECT>", "The project to compile, defaults to the current directory. Can be a path to a project.json or a project directory");

            app.OnExecute(() =>
            {
                // Locate the project and get the name and full path
                var path = project.Value;
                if (string.IsNullOrEmpty(path))
                {
                    path = Directory.GetCurrentDirectory();
                }

                if(!path.EndsWith(Project.FileName))
                {
                    path = Path.Combine(path, Project.FileName);
                }

                if(!File.Exists(path))
                {
                    Reporter.Error.WriteLine($"Unable to find a project.json in {path}");
                    return 1;
                }

                var configValue = configuration.Value() ?? Cli.Utils.Constants.DefaultConfiguration;
                var outputValue = output.Value();

                return BuildPackage(path, configValue, outputValue, intermediateOutput.Value()) ? 1 : 0;
            });

            try
            {
                return app.Execute(args);
            }
            catch (Exception ex)
            {
            #if DEBUG
                Console.Error.WriteLine(ex);
            #else
                Console.Error.WriteLine(ex.Message);
            #endif
                return 1;
            }
        }
开发者ID:Sridhar-MS,项目名称:cli,代码行数:55,代码来源:Program.cs

示例5: Main

        public static int Main(string[] args)
        {
            DebugHelper.HandleDebugSwitch(ref args);

            var app = new CommandLineApplication(throwOnUnexpectedArg: false);
            app.Name = "dotnet run";
            app.FullName = ".NET Executor";
            app.Description = "Runner for the .NET Platform";
            app.HelpOption("-h|--help");

            var framework = app.Option("-f|--framework <FRAMEWORK>", "Compile a specific framework", CommandOptionType.MultipleValue);
            var configuration = app.Option("-c|--configuration <CONFIGURATION>", "Configuration under which to build", CommandOptionType.SingleValue);
            var preserveTemporaryOutput = app.Option("-t|--preserve-temporary", "Keep the output's temporary directory around", CommandOptionType.NoValue);
            var project = app.Option("-p|--project <PROJECT_PATH>", "The path to the project to run (defaults to the current directory)", CommandOptionType.SingleValue);

            app.OnExecute(() =>
            {
                // Locate the project and get the name and full path
                var path = Directory.GetCurrentDirectory();
                if(project.HasValue())
                {
                    path = project.Value();
                }

                var contexts = ProjectContext.CreateContextForEachFramework(path);
                if (!framework.HasValue())
                {
                    return Run(contexts.First(), configuration.Value() ?? Constants.DefaultConfiguration, app.RemainingArguments, preserveTemporaryOutput.HasValue());
                }
                else
                {
                    var context = contexts.FirstOrDefault(c => c.TargetFramework.Equals(NuGetFramework.Parse(framework.Value())));
                    return Run(context, configuration.Value() ?? Constants.DefaultConfiguration, app.RemainingArguments, preserveTemporaryOutput.HasValue());
                }
            });

            try
            {
                return app.Execute(args);
            }
            catch (Exception ex)
            {
            #if DEBUG
                Console.Error.WriteLine(ex);
            #else
                Console.Error.WriteLine(ex.Message);
            #endif
                return 1;
            }
        }
开发者ID:krwq,项目名称:cli-1,代码行数:50,代码来源:Program.cs

示例6: Run

        public static int Run(string[] args)
        {
            var app = new CommandLineApplication();
            app.Name = "dotnet-projectmodel-server";
            app.Description = ".NET Project Model Server";
            app.FullName = ".NET Design Time Server";
            app.Description = ".NET Design Time Server";
            app.HelpOption("-?|-h|--help");

            var verbose = app.Option("--verbose", "Verbose ouput", CommandOptionType.NoValue);
            var hostpid = app.Option("--host-pid", "The process id of the host", CommandOptionType.SingleValue);
            var hostname = app.Option("--host-name", "The name of the host", CommandOptionType.SingleValue);
            var port = app.Option("--port", "The TCP port used for communication", CommandOptionType.SingleValue);

            app.OnExecute(() =>
            {
                try
                {
                    if (!MonitorHostProcess(hostpid))
                    {
                        return 1;
                    }

                    var intPort = CheckPort(port);
                    if (intPort == -1)
                    {
                        return 1;
                    }

                    if (!hostname.HasValue())
                    {
                        Reporter.Error.WriteLine($"Option \"{hostname.LongName}\" is missing.");
                        return 1;
                    }

                    var program = new ProjectModelServerCommand(intPort, hostname.Value());
                    program.OpenChannel();
                }
                catch (Exception ex)
                {
                    Reporter.Error.WriteLine($"Unhandled exception in server main: {ex}");
                    throw;
                }

                return 0;
            });

            return app.Execute(args);
        }
开发者ID:akrisiun,项目名称:dotnet-cli,代码行数:49,代码来源:Program.cs

示例7: Run

        private static void Run(CommandLineApplication cmd)
        {
            cmd.Description = "Update a package version.";

            var packageId = cmd.Option(
                "-i|--id <id>",
                "package id",
                CommandOptionType.SingleValue);

            var packageVersion = cmd.Option(
                "-v|--version <version>",
                "package version",
                CommandOptionType.SingleValue);

            var argRoot = cmd.Argument(
                "[root]",
                "directory",
                multipleValues: true);

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

            cmd.OnExecute(() =>
            {
                cmd.ShowRootCommandFullNameAndVersion();

                if (string.IsNullOrEmpty(packageId.Value()))
                {
                    throw new ArgumentException($"Missing value: {packageId.LongName}");
                }

                VersionRange version;
                if (!VersionRange.TryParse(packageVersion.Value(), out version))
                {
                    throw new ArgumentException($"Invalid value for: {packageVersion.LongName}");
                }

                foreach (var arg in argRoot.Values)
                {
                    var dir = new DirectoryInfo(arg);

                    foreach (var file in dir.GetFiles("project.json", SearchOption.AllDirectories))
                    {
                        Process(file, packageId.Value(), version);
                    }
                }

                return 0;
            });
        }
开发者ID:emgarten,项目名称:Trestle,代码行数:49,代码来源:UpdatePackageCommand.cs

示例8: Create

        public static CommandLineApplication Create(ref string[] args)
        {
            EnsureValidDispatchRecipient(ref args);

            var app = new CommandLineApplication()
            {
                // Technically, the real "dotnet-ef.dll" is in Microsoft.EntityFrameworkCore.Tools,
                // but this name is what the help usage displays
                Name = "dotnet ef",
                FullName = "Entity Framework .NET Core CLI Commands"
            };

            app.HelpOption();
            app.VerboseOption();
            app.VersionOption(GetVersion);

            var commonOptions = new CommonCommandOptions
            {
                // required
                Assembly = app.Option(AssemblyOptionTemplate + " <ASSEMBLY>",
                     "The assembly file to load."),

                // optional
                StartupAssembly = app.Option(StartupAssemblyOptionTemplate + " <ASSEMBLY>",
                     "The assembly file containing the startup class."),
                DataDirectory = app.Option(DataDirectoryOptionTemplate + " <DIR>",
                    "The folder used as the data directory (defaults to current working directory)."),
                ProjectDirectory = app.Option(ProjectDirectoryOptionTemplate + " <DIR>",
                    "The folder used as the project directory (defaults to current working directory)."),
                ContentRootPath = app.Option(ContentRootPathOptionTemplate + " <DIR>",
                    "The folder used as the content root path for the application (defaults to application base directory)."),
                RootNamespace = app.Option(RootNamespaceOptionTemplate + " <NAMESPACE>",
                    "The root namespace of the target project (defaults to the project assembly name).")
            };

            app.Command("database", c => DatabaseCommand.Configure(c, commonOptions));
            app.Command("dbcontext", c => DbContextCommand.Configure(c, commonOptions));
            app.Command("migrations", c => MigrationsCommand.Configure(c, commonOptions));

            app.OnExecute(
                () =>
                {
                    WriteLogo();
                    app.ShowHelp();
                });

            return app;
        }
开发者ID:RickyLin,项目名称:EntityFramework,代码行数:48,代码来源:ExecuteCommand.cs

示例9: Run

        private static void Run(CommandLineApplication cmd)
        {
            cmd.Description = "Update a release label across pacakges.";

            var find = cmd.Option(
                "-f|--find <label>",
                "release label. Ex: alpha-100",
                CommandOptionType.SingleValue);

            var replace = cmd.Option(
                "-r|--replace <label>",
                "release label. Ex: alpha-101",
                CommandOptionType.SingleValue);

            var argRoot = cmd.Argument(
                "[root]",
                "directory",
                multipleValues: true);

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

            cmd.OnExecute(() =>
            {
                cmd.ShowRootCommandFullNameAndVersion();

                if (string.IsNullOrEmpty(find.Value()))
                {
                    throw new ArgumentException($"Missing value: {find.LongName}");
                }

                if (string.IsNullOrEmpty(replace.Value()))
                {
                    throw new ArgumentException($"Missing value: {replace.LongName}");
                }

                foreach (var arg in argRoot.Values)
                {
                    var dir = new DirectoryInfo(arg);

                    foreach (var file in dir.GetFiles("project.json", SearchOption.AllDirectories))
                    {
                        Process(file, find.Value(), replace.Value());
                    }
                }

                return 0;
            });
        }
开发者ID:emgarten,项目名称:Trestle,代码行数:48,代码来源:UpdateReleaseLabelCommand.cs

示例10: AddOption

        private static CommandOption AddOption(CommandLineApplication app, string optionName, string description, CommandOptionType optionType)
        {
            string argSuffix = optionType == CommandOptionType.MultipleValue ? "..." : null;
            string argString = optionType == CommandOptionType.BoolValue ? null : $" <arg>{argSuffix}";

            return app.Option($"--{optionName}{argString}", description, optionType);
        }
开发者ID:akrisiun,项目名称:dotnet-cli,代码行数:7,代码来源:CommonCompilerOptionsCommandLine.cs

示例11: Main

        public static int Main(string[] args)
        {
            var app = new CommandLineApplication
            {
                Name = "dotnet publish-iis",
                FullName = "Asp.Net Core IIS Publisher",
                Description = "IIS Publisher for the Asp.Net Core web applications",
            };
            app.HelpOption("-h|--help");

            var publishFolderOption = app.Option("-p|--publish-folder", "The path to the publish output folder", CommandOptionType.SingleValue);
            var frameworkOption = app.Option("-f|--framework <FRAMEWORK>", "Target framework of application being published", CommandOptionType.SingleValue);
            var configurationOption = app.Option("-c|--configuration <CONFIGURATION>", "Target configuration of application being published", CommandOptionType.SingleValue);
            var projectPath = app.Argument("<PROJECT>", "The path to the project (project folder or project.json) being published. If empty the current directory is used.");

            app.OnExecute(() =>
            {
                var publishFolder = publishFolderOption.Value();
                var framework = frameworkOption.Value();

                if (publishFolder == null || framework == null)
                {
                    app.ShowHelp();
                    return 2;
                }

                Reporter.Output.WriteLine($"Configuring the following project for use with IIS: '{publishFolder}'");

                var exitCode = new PublishIISCommand(publishFolder, framework, configurationOption.Value(), projectPath.Value).Run();

                Reporter.Output.WriteLine("Configuring project completed successfully");

                return exitCode;
            });

            try
            {
                return app.Execute(args);
            }
            catch (Exception e)
            {
                Reporter.Error.WriteLine(e.Message.Red());
                Reporter.Output.WriteLine(e.ToString().Yellow());
            }

            return 1;
        }
开发者ID:aspnet,项目名称:IISIntegration,代码行数:47,代码来源:Program.cs

示例12: Main

        public static int Main(string[] args)
        {
            DebugHelper.HandleDebugSwitch(ref args);

            var app = new CommandLineApplication(throwOnUnexpectedArg: false);
            app.Name = "dotnet repl csi";
            app.FullName = "C# REPL";
            app.Description = "C# REPL for the .NET platform";
            app.HelpOption("-h|--help");

            var script = app.Argument("<SCRIPT>", "The .csx file to run. Defaults to interactive mode");
            var framework = app.Option("-f|--framework <FRAMEWORK>", "Compile a specific framework", CommandOptionType.SingleValue);
            var configuration = app.Option("-c|--configuration <CONFIGURATION>", "Configuration under which to build", CommandOptionType.SingleValue);
            var preserveTemporary = app.Option("-t|--preserve-temporary", "Preserve the temporary directory containing the compiled project", CommandOptionType.NoValue);
            var project = app.Option("-p|--project <PROJECT>", "The path to the project to run. Can be a path to a project.json or a project directory", CommandOptionType.SingleValue);

            app.OnExecute(() => Run(script.Value, framework.Value(), configuration.Value(), preserveTemporary.HasValue(), project.Value(), app.RemainingArguments));
            return app.Execute(args);
        }
开发者ID:alexanderkyte,项目名称:cli,代码行数:19,代码来源:Program.cs

示例13: Main

        static void Main(string[] args)
        {
            var mainModule = System.Diagnostics.Process.GetCurrentProcess().MainModule;
            var app = new CommandLineApplication();
            app.Name = System.IO.Path.GetFileName(mainModule.FileName);
            app.FullName = "DemoApp For this CommandLineApplication";

            var optionVerbose = app.Option("-v|--verbose", "Show verbose output", CommandOptionType.NoValue);

            // Show help information if no subcommand/option was specified
            app.OnExecute(() =>
            {
                if (optionVerbose.HasValue())
                {
                    Console.WriteLine("You've specified the verbose option");
                }

                Console.WriteLine("Do something");
                return 0;
            });

            app.Command("subcommand", command =>
            {
                command.Description = "Produce something in the subcomamnd";

                var optionNames = command.Argument("[names]", "A list of files names you want to process.", multipleValues: true);
                var optionOut = command.Option("--out <OUTPUT_DIR>", "Output directory", CommandOptionType.SingleValue);
                command.HelpOption("-?|-h|--help");

                command.OnExecute(() =>
                {
                    if (optionOut.HasValue())
                    {
                        Console.WriteLine($"Your output directory is {optionOut.Value()}");
                    }

                    Console.WriteLine($"Your names are {string.Join(",", optionNames.Values)}");
                    Console.WriteLine("Do something in the sub command");

                    return 0;
                });
            });

            app.HelpOption("-?|-h|--help");
            app.VersionOption("--version",
                () => mainModule.FileVersionInfo.ProductVersion,
                () => $"File Version: {mainModule.FileVersionInfo.FileVersion}{Environment.NewLine}Product Version:{mainModule.FileVersionInfo.ProductVersion}");

            app.OnException(HandleException);

            app.Execute(args);
        }
开发者ID:jijiechen,项目名称:DnxCommandLineUtils,代码行数:52,代码来源:Program.cs

示例14: Main

        public static int Main(string[] args)
        {

            var app = new CommandLineApplication();
            app.Name = "nuget3";
            app.FullName = "NuGet Command Line";
            app.HelpOption(XPlatUtility.HelpOption);
            app.VersionOption("--version", typeof(Program).GetTypeInfo().Assembly.GetName().Version.ToString());

            var verbosity = app.Option(XPlatUtility.VerbosityOption, "The verbosity of logging to use. Allowed values: Debug, Verbose, Information, Minimal, Warning, Error.", CommandOptionType.SingleValue);

            XPlatUtility.SetConnectionLimit();

            XPlatUtility.SetUserAgent();

            EnsureLog(XPlatUtility.GetLogLevel(verbosity));

            RestoreCommand.Register(app, Log);

            app.OnExecute(() =>
            {
                app.ShowHelp();
                return 0;
            });

            var exitCode = 0;

            try
            {
                exitCode = app.Execute(args);
            }
            catch (Exception e)
            {
                EnsureLog(XPlatUtility.GetLogLevel(verbosity));

                // Log the error
                Log.LogError(ExceptionUtilities.DisplayMessage(e));

                // Log the stack trace as verbose output.
                Log.LogVerbose(e.ToString());

                exitCode = 1;
            }

            // Limit the exit code range to 0-255 to support POSIX
            if (exitCode < 0 || exitCode > 255)
            {
                exitCode = 1;
            }

            return exitCode;
        }
开发者ID:zhili1208,项目名称:lzhi-test,代码行数:52,代码来源:Program.cs

示例15: Main

        public static void Main(string[] args)
        {
            CommandLineApplication app = new CommandLineApplication();
            app.HelpOption("--help|-h|-?"); // 使其支持显示帮助信息
            app.VersionOption("--version|-v", "1.0.0"); // 使其支持显示版本信息。为了简化起见,直接返回静态的 1.0.0

            // 添加 argument,这里我们允许传入这个 argument 的多个值。
            CommandArgument argOperator = app.Argument("operator", "算式类型,有效值:加、减、乘、除,可以设置多个类型", multipleValues: true);

            // 添加多个 options,注意设置全写和简写的方式,很简单。这应该是基于约定的解析处理方式。
            CommandOption optMin = app.Option("--minValue -min <value>", "最小值,默认为0", CommandOptionType.SingleValue);
            CommandOption optMax = app.Option("--maxValue -max <value>", "最大值,默认为100", CommandOptionType.SingleValue);
            CommandOption optCount = app.Option("--count -c <value>", "生成的算式数量,默认为10", CommandOptionType.SingleValue);

            // 传入一个委托方法,当下面的 Execute 执行后会执行我们的委托方法,完成我们需要处理的工作。 委托方法需要返回一个 int,反映执行结果,一如经典的控制台程序需要的那样。
            app.OnExecute(() =>
            {
                return OnAppExecute(argOperator, optMin, optMax, optCount);
            });

            // 开始执行,把控制台传入的参数直接传递给 CommandLineApplication。
            app.Execute(args);
        }
开发者ID:RickyLin,项目名称:Demos,代码行数:23,代码来源:Program.cs


注:本文中的CommandLineApplication.Option方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。