2016-09-19 7 views
0

C#の配列を解析するのにPlossum CommandLineパーサを使用しようとしていますが、動作していないようです。C#でPlossum CommandLineを使用して配列を解析する

次のコードは、どこかのソースコードに見られる例の機能縮小版である:私は上記のコードを呼び出すために使用syntaxed

using Plossum.CommandLine; 
using System; 
using System.Collections.Generic; 

namespace PlossumCommandLine 
{ 
    [CommandLineManager(ApplicationName = "Example 2", Copyright = "Copyright (C) Peter Palotas 2007", 
EnabledOptionStyles = OptionStyles.Group | OptionStyles.LongUnix)] 
    [CommandLineOptionGroup("commands", Name = "Commands", Require = OptionGroupRequirement.ExactlyOne)] 
    [CommandLineOptionGroup("options", Name = "Options")] 
    class Options 
    { 
     [CommandLineOption(Name = "filter", RequireExplicitAssignment = true, 
      Description = "Specifies a filter on which files to include or exclude", GroupId = "options")] 
     public List<string> Filters 
     { 
      get { return mFilters; } 
      set { mFilters = value; } 
     } 

     [CommandLineOption(Name = "h", Aliases = "help", MinOccurs = 0, Description = "Shows this help text", GroupId = "commands")] 
     public bool Help 
     { 
      get { return mHelp; } 
      set { mHelp = value; } 
     } 

     private bool mHelp; 

     private List<string> mFilters = new List<string>(); 
    } 
    class Program 
    { 
     static int Main(string[] args) 
     { 
      Options options = new Options(); 
      CommandLineParser parser = new CommandLineParser(options); 
      parser.Parse(); 

      if (options.Help) 
      { 
       Console.WriteLine(parser.UsageInfo.ToString(78, false)); 
       return 0; 
      } 
      else if (parser.HasErrors) 
      { 
       Console.WriteLine(parser.UsageInfo.ToString(78, true)); 
       return -1; 
      } 

      // No errors present and all arguments correct 
      // Do work according to arguments 
      Console.WriteLine("Filters: " + string.Join(",", options.Filters.ToArray())); 
      return 0; 
     } 
    } 
} 

ことである:

program.exe --filter abc 

そして結果は次のとおりです。

Example 2 version 1.0.0.0 
Copyright (C) Peter Palotas 2007 

Errors: 
    * Missing required value for option "filter" 
    * One of the options "h" must be specified 

Commands: 
    -h, --help Shows this help text 

Options: 
    --filter  Specifies a filter on which files to include or exclude 

私のシステム:

VS:2015
OS:勝つ7のx64
.NET:4
Plossum:私はおそらくちょうど私の目の前にある壁を見ることができませんnuGet

から1。

答えて

0

オプションOptionStyles.LongUnixすると、コマンドラインは次のようになります。

program.exe --filter=abc 
関連する問題