0
我試圖使用Plossum CommandLine
解析器來解析C#
中的數組,但它似乎不起作用。使用C中的Plossum CommandLine解析數組#
以下代碼是一個例子的精簡版本我在源代碼中發現某處:
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;
}
}
}
的syntaxed我用來調用上面的代碼是:
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:Win 7的64位
.NET:4
Plossum:從的NuGet
一個我可能只是無法看到在我面前的牆。