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


C# CommandLineApplication.HelpOption方法代码示例

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


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

示例1: Main

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

            var app = new CommandLineApplication();
            app.Name = "dotnet init";
            app.FullName = ".NET Initializer";
            app.Description = "Initializes empty project for .NET Platform";
            app.HelpOption("-h|--help");

            var dotnetInit = new Program();
            app.OnExecute((Func<int>)dotnetInit.CreateEmptyProject);

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

示例2: Main

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

            var app = new CommandLineApplication();
            app.Name = "dotnet compile csc";
            app.FullName = "CSharp compiler";
            app.Description = "CSharp Compiler for the .NET Platform";
            app.HelpOption("-h|--help");

            var responseFileArg = app.Argument("<CONFIG>", "The response file to pass to the compiler.");

            app.OnExecute(() =>
            {
                // Execute CSC!
                var result = RunCsc($"-noconfig @\"{responseFileArg.Value}\"")
                    .ForwardStdErr()
                    .ForwardStdOut()
                    .Execute();

                return result.ExitCode;
            });

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

示例3: Run

        private static void Run(CommandLineApplication cmd)
        {
            cmd.Description = "Set imports for project.json files";

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

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

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

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

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

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

示例4: Run

        public static int Run(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 buildBasePath = app.Option("-b|--build-base-path <OUTPUT_DIR>", "Directory in which to place temporary outputs", CommandOptionType.SingleValue);
            var output = app.Option("-o|--output <OUTPUT_PATH>", "Path in which to publish the app", CommandOptionType.SingleValue);
            var versionSuffix = app.Option("--version-suffix <VERSION_SUFFIX>", "Defines what `*` should be replaced with in version field in project.json", 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);
            var noBuild = app.Option("--no-build", "Do not build projects before publishing", CommandOptionType.NoValue);

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

                publish.Framework = framework.Value();
                publish.Runtime = runtime.Value();
                publish.BuildBasePath = buildBasePath.Value();
                publish.OutputPath = output.Value();
                publish.Configuration = configuration.Value() ?? Constants.DefaultConfiguration;
                publish.NativeSubdirectories = nativeSubdirectories.HasValue();
                publish.ProjectPath = projectPath.Value;
                publish.VersionSuffix = versionSuffix.Value();
                publish.ShouldBuild = !noBuild.HasValue();

                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:krytarowski,项目名称:cli,代码行数:60,代码来源:Program.cs

示例5: Main

        public int Main(string[] args)
        {
            try
            {
                var app = new CommandLineApplication
                {
                    Name = "razor-tooling",
                    FullName = "Microsoft Razor Tooling Utility",
                    Description = "Resolves Razor tooling specific information.",
                    ShortVersionGetter = GetInformationalVersion,
                };
                app.HelpOption("-?|-h|--help");

                ResolveProtocolCommand.Register(app);
                ResolveTagHelpersCommand.Register(app, _assemblyLoadContext);

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

                return app.Execute(args);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error: {Environment.NewLine}{ex.Message}.");
                return 1;
            }
        }
开发者ID:IlyaKhD,项目名称:RazorTooling,代码行数:30,代码来源:Program.cs

示例6: 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

示例7: Main

        public int Main(string[] args)
        {
            try
            {
                var description = "Creates table and indexes in Microsoft SQL Server database " +
                    "to be used for distributed caching";

                var app = new CommandLineApplication();
                app.Name = "sqlservercache";
                app.Description = description;

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

                app.Command("create", command =>
                {
                    command.Description = description;
                    var connectionStringArg = command.Argument(
                        "[connectionString]",
                        "The connection string to connect to the database.");
                    var schemaNameArg = command.Argument("[schemaName]", "Name of the table schema.");
                    var tableNameArg = command.Argument("[tableName]", "Name of the table to be created.");
                    command.HelpOption("-?|-h|--help");

                    command.OnExecute(() =>
                    {
                        if (string.IsNullOrEmpty(connectionStringArg.Value)
                        || string.IsNullOrEmpty(schemaNameArg.Value)
                        || string.IsNullOrEmpty(tableNameArg.Value))
                        {
                            _logger.LogWarning("Invalid input");
                            app.ShowHelp();
                            return 2;
                        }

                        _connectionString = connectionStringArg.Value;
                        _schemaName = schemaNameArg.Value;
                        _tableName = tableNameArg.Value;

                        CreateTableAndIndexes();

                        return 0;
                    });
                });

                // Show help information if no subcommand/option was specified.
                app.OnExecute(() =>
                {
                    app.ShowHelp();
                    return 2;
                });

                return app.Execute(args);
            }
            catch (Exception exception)
            {
                _logger.LogCritical("An error occurred. {Message}", exception.Message);
                return 1;
            }
        }
开发者ID:benaadams,项目名称:Caching,代码行数:59,代码来源:Program.cs

示例8: 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

示例9: Main

        public int Main(string[] args)
        {
            var app = new CommandLineApplication
            {
                Name = "dnx Azure",
                FullName = "Azure Message Queue Utils"
            };

            app.HelpOption(HELP_TEMPLATE);

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

            app.Command("send", send =>
            {
                send.Description = "Send a message";
                send.HelpOption(HELP_TEMPLATE);

                var queueName = send.Argument("[queueName]", "The name of the queue");
                var message = send.Argument("[message]", "The message to send");
                var connectionString = send.Argument("[connectionString]", "The connection string");

                send.OnExecute(() =>
                {
                    var factory = MessagingFactory.CreateFromConnectionString(connectionString.Value);
                    var queue = factory.CreateQueueClient(queueName.Value);
                    var packet = new BrokeredMessage(message.Value);

                    queue.Send(packet);

                    return 0;
                });
            });

            app.Command("receive", receive =>
            {
                receive.Description = "Receive a message";
                receive.HelpOption(HELP_TEMPLATE);

                var queueName = receive.Argument("[queueName]", "The name of the queue");
                var connectionString = receive.Argument("[connectionString]", "The connection string");

                receive.OnExecute(() =>
                {
                    var factory = MessagingFactory.CreateFromConnectionString(connectionString.Value);
                    var queue = factory.CreateQueueClient(queueName.Value);
                    var message = queue.Receive();

                    Console.WriteLine(message.GetBody<string>());

                    message.Complete(); // must signal to queue that the message has been handled

                    return 0;
                });
            });

            return app.Execute(args);
        }
开发者ID:Kieranties,项目名称:MessagingPlayground,代码行数:57,代码来源:Program.cs

示例10: 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

示例11: Main

        public static void Main(string[] args)
        {
            var app = new CommandLineApplication
            {
                Name = "Project.Json.Patcher",
                Description = "Patch project.json files with new version and release notes",
                FullName = "Project.Json Patcher"
            };

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

            app.Command("Patch", commandAppConfing =>
            {
                commandAppConfing.Description = "Patches the project.json file";

                CommandOption fileOption = commandAppConfing.Option("-f|--File <FilePath>",
                    "OPTIONAL. Path to project.json", CommandOptionType.SingleValue);

                CommandOption versionOption = commandAppConfing.Option("-v|--Version <Version>",
                    "Target version of project.json", CommandOptionType.SingleValue);

                CommandOption releaseNotesOption = commandAppConfing.Option("-r|--RealeaseNotes <ReleaseNotes>",
                    "OPTIONAL. Release notes of this version", CommandOptionType.SingleValue);

                commandAppConfing.HelpOption("-h|--help");

                commandAppConfing.OnExecute(() =>
                {

                    string filePath = GetFilePath(fileOption);

                    string version = GetVersion(versionOption);

                    string releaseNotes = releaseNotesOption.Value();

                    Console.WriteLine($"FilePath: {filePath}, " +
                                      $"Version: {version}, " +
                                      $"ReleaseNotes: {releaseNotes}");

                    Patch(filePath, version, releaseNotes);

                    Console.WriteLine("Patching Complete");
                    return 0;
                });

            });

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

            app.Execute(args);
        }
开发者ID:bilal-fazlani,项目名称:Project.Json.Patcher,代码行数:55,代码来源:Program.cs

示例12: Main

        public static int Main(string[] args)
        {
            #if DEBUG
            if (args.Contains("--debug"))
            {
                args = args.Skip(1).ToArray();
                while (!Debugger.IsAttached)
                {

                }
                Debugger.Break();
            }
            #endif

            var app = new CommandLineApplication();
            app.Name = "trestle";
            app.FullName = "Trestle";
            app.HelpOption("-h|--help");
            app.VersionOption("--version", typeof(Program).GetTypeInfo().Assembly.GetName().Version.ToString());

            PublishCommand.Register(app);
            NormalizeCommand.Register(app);
            ImportsCommand.Register(app);
            UpdatePackageCommand.Register(app);
            UpdateReleaseLabelCommand.Register(app);
            RemovePackageCommand.Register(app);
            CompilationOptionsCommand.Register(app);

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

            var exitCode = 0;

            try
            {
                exitCode = app.Execute(args);
            }
            catch (CommandParsingException ex)
            {
                ex.Command.ShowHelp();
            }
            catch (Exception ex)
            {
                exitCode = 1;
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex);
            }

            return exitCode;
        }
开发者ID:emgarten,项目名称:Trestle,代码行数:53,代码来源:Program.cs

示例13: Main

        public int Main(string[] args)
        {
            try
            {
                var app = new CommandLineApplication();
                app.Name = "project-stats";
                app.FullName = "Project Stats";
                app.Description = "Shows stats about a project such as number of files and SLOC";
                app.ShortVersionGetter = () => "1.0.0";
                app.HelpOption("-h");

                app.Command("files", c =>
                {
                    c.Description = "Gets stats about filetypes";

                    var optionProject = c.Option("-p|--project <PATH>", "Path to the project, default is current directory", CommandOptionType.SingleValue);

                    c.HelpOption("-h");

                    c.OnExecute(() =>
                    {
                        var projectPath = optionProject.Value() ?? Directory.GetCurrentDirectory();

                        return new FilesCommand().Execute(projectPath);
                    });
                });

                app.Command("sloc", c =>
                {
                    c.Description = "Gets stats about source lines of code";

                    var optionProject = c.Option("-p|--project <PATH>", "Path to the project, default is current directory", CommandOptionType.SingleValue);
                    var fileTypeArgs = c.Argument("[filetypes]", "Filetype(s) to include, e.g. .cs .json", multipleValues: true);

                    c.HelpOption("-h");

                    c.OnExecute(() =>
                    {
                        var projectPath = optionProject.Value() ?? Directory.GetCurrentDirectory();
                        var typesFilters = fileTypeArgs.Values;

                        return new SlocCommand().Execute(projectPath, typesFilters);
                    });
                });

                return app.Execute(args);
            }
            catch (Exception)
            {
                return 0;
            }
        }
开发者ID:jlandersen,项目名称:dnx-project-stats-application,代码行数: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 int Main(string[] args)
        {
            DebugHelper.HandleDebugSwitch(ref args);

            var app = new CommandLineApplication();
            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.");

            app.OnExecute(() => Run(script.Value));
            return app.Execute(args);
        }
开发者ID:shahid-pk,项目名称:cli,代码行数:14,代码来源:Program.cs


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