zoukankan      html  css  js  c++  java
  • 推荐一个.NET 命令行参数Parser 库

    Command Line Parser Library 是个很简洁方便的 命令参数解析的类库,代码也不多,只两个cs文件,但功能一点也不少.
    先看下QuickStart:

    Test.exe, Program.cs:

    class Options
      {
          [Option("d", "debug", DefaultValue = false, HelpText = "Debug Mode.")]
          public bool Debug { get; set; }
          [Option("h", "help", DefaultValue = false, HelpText = "Show Help")]
          public bool ShowHelp { get; set; }
          [HelpOption]
          public string GetUsage()
          {
              var usage = new StringBuilder();
              usage.AppendLine("Use -d or -debug to Debug");
              return usage.ToString();
          }
      }
      class Program
      {
          static void Main(string[] args)
          {
              var options = new Options();
              CommandLineParser.Default.ParseArguments(args, options);
              if (options.ShowHelp)
              {
                  Console.WriteLine(options.GetUsage());
                  return;
              }
              if (options.Debug)
              {
                  Console.WriteLine("debug");
              }
           }
      }

    其中,d参数是debug的全称,可以使用-d或者-debug.并可以指定默认值
    测试:
    Test.exe –d
    Test.exe –h  显示使用帮助信息

    除了简单的参数外,还支持列表参数,数组等,详细的用法,参照:
    http://commandline.codeplex.com/documentation
    现在这个代码库已迁移到GitHub. Git现在越来越红了,连Codeplex现在也开始支持Git了

  • 相关阅读:
    Move Zeroes
    Intersection of Two Arrays II
    Intersection of Two Arrays
    Create Maximum Number
    Leetcode version 2
    JDBC学习笔记
    九章算法基础班
    九章算法强化班
    LeetCode
    Amazon High Frequent 9 problems
  • 原文地址:https://www.cnblogs.com/solo/p/2539771.html
Copyright © 2011-2022 走看看