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


C# CommandLineParser.PrintHelp方法代码示例

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


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

示例1: Time

        public Time(string[] args)
        {
            CommandLineParser parser = new CommandLineParser();

            var format = new CommandLineStringOption("format", "f");
            format.Help = "Specify output format, possibly overriding the format specified in the environment variable TIME.";
            format.ExpectedValue = "format";
            parser.AddOption(format);
            format.ShortName = "X";

            var portability = new CommandLineBoolOption("portability", "p");
            portability.Help = "Use the portable output format.";
            //parser.AddOption(portability);

            var output = new CommandLineStringOption("output", "o");
            output.Help = "Do not send the results to stderr, but overwrite the specified file.";
            output.ExpectedValue = "file";
            output.Required = true;
            //parser.AddOption(output);

            var append = new CommandLineBoolOption("append", "a");
            append.Help = "(Used together with -o.) Do not overwrite but append.";
            //parser.AddOption(append);

            var verbose = new CommandLineBoolOption("verbose", "v");
            verbose.Help = "Give very verbose output about all the program knows about.";
            verbose.Required = true;
            //verbose.ParameterType = ParameterType.Required;
            //parser.AddOption(verbose);

            var help = new CommandLineBoolOption("help");
            help.Help = "Print a usage message on standard output and exit successfully.";
            //parser.AddOption(help);

            var version = new CommandLineBoolOption("version", "V");
            version.Help = "Print version information on standard output, then exit successfully.";
            //parser.AddOption(version);

            List<string> extraParameters;

            try
            {
                extraParameters = parser.Parse(args);
            }
            catch (ParsingException ex)
            {
                if (ex.Option != null)
                {
                    Console.WriteLine("An error occurred in parameter " + ex.Option.Name);
                }
                Console.WriteLine("Message: " + ex.Message);
                return;
            }

            if ((args.Length == 0) || (help.Present))
            {
                parser.PrintHelp();
                return;
            }

            Console.WriteLine("Format: " + format.Value);
            Console.WriteLine("Verbose: " + verbose.Present);
            Console.WriteLine("Output: " + output.Value);
        }
开发者ID:elenfant,项目名称:mff-programming-practices,代码行数:64,代码来源:Program.cs


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