本文整理汇总了C#中CommandLine.Parser类的典型用法代码示例。如果您正苦于以下问题:C# CommandLine.Parser类的具体用法?C# CommandLine.Parser怎么用?C# CommandLine.Parser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CommandLine.Parser类属于命名空间,在下文中一共展示了CommandLine.Parser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Failed_verb_parsing_prints_particular_help_screen
public void Failed_verb_parsing_prints_particular_help_screen()
{
string invokedVerb = null;
object invokedVerbInstance = null;
var options = new OptionsWithVerbsHelp();
var testWriter = new StringWriter();
ReflectionHelper.AssemblyFromWhichToPullInformation = Assembly.GetExecutingAssembly();
var parser = new CommandLine.Parser(with => with.HelpWriter = testWriter);
var result = parser.ParseArguments(new string[] { "clone", "--no_hardlinks" }, options,
(verb, subOptions) =>
{
invokedVerb = verb;
invokedVerbInstance = subOptions;
});
result.Should().BeFalse();
var helpText = testWriter.ToString();
Console.WriteLine(helpText);
var lines = helpText.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
// Verify just significant output
lines[5].Trim().Should().Be("--no-hardlinks Optimize the cloning process from a repository on a local");
lines[6].Trim().Should().Be("filesystem by copying files.");
lines[7].Trim().Should().Be("-q, --quiet Suppress summary message.");
invokedVerb.Should().Be("clone");
invokedVerbInstance.Should().Be(null);
}
示例2: Main
static void Main(string[] args)
{
// Parse command line options
var mpOptions = new CommandLineOptions();
var parser = new CommandLine.Parser(with => with.HelpWriter = Console.Out);
parser.ParseArgumentsStrict(args, mpOptions, () => Environment.Exit(1));
List<string> products = new List<string>
{
"MediaPortal Setup TV", // Legacy folders for TVE3 support
"MediaPortal TV Server", // Legacy folders for TVE3 support
"MP2-Client",
"MP2-Server",
"MP2-ClientLauncher",
"MP2-ServiceMonitor"
};
string dataPath = !string.IsNullOrEmpty(mpOptions.DataDirectory) ?
mpOptions.DataDirectory :
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
string outputPath = !string.IsNullOrEmpty(mpOptions.OutputDirectory) ?
mpOptions.OutputDirectory :
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "MediaPortal2-Logs");
try
{
CollectLogFiles(dataPath, outputPath, products);
}
catch (Exception ex)
{
Console.WriteLine("Exception while collecting log files: {0}", ex);
}
}
示例3: Main
/// <summary>
/// 应用程序入口
/// </summary>
/// <param name="args">命令行参数</param>
static void Main(string[] args)
{
System.DateTime startTime = System.DateTime.Now;
//-- 分析命令行参数
var options = new Options();
var parser = new CommandLine.Parser(with => with.HelpWriter = Console.Error);
if (parser.ParseArgumentsStrict(args, options, () => Environment.Exit(-1)))
{
//-- 执行导出操作
try
{
Run(options);
}
catch (Exception exp)
{
Console.WriteLine("Error: " + exp.Message);
}
}
//-- 程序计时
System.DateTime endTime = System.DateTime.Now;
System.TimeSpan dur = endTime - startTime;
Console.WriteLine(
string.Format("[{0}]:\t转换完成[{1}毫秒].",
Path.GetFileName(options.ExcelPath),
dur.Milliseconds)
);
}
示例4: Parse_verbs_create_instance
public void Parse_verbs_create_instance()
{
string invokedVerb = null;
object invokedVerbInstance = null;
var options = new OptionsWithVerbs();
options.AddVerb.Should().BeNull();
var parser = new CommandLine.Parser();
var result = parser.ParseArguments(new string[] {"add", "-p", "untracked.bin"} , options,
(verb, subOptions) =>
{
invokedVerb = verb;
invokedVerbInstance = subOptions;
});
result.Should().BeTrue();
invokedVerb.Should().Be("add");
invokedVerbInstance.Should().BeOfType<AddSubOptions>();
// Parser has built instance for us
options.AddVerb.Should().NotBeNull();
options.AddVerb.CreationProof.Should().NotHaveValue();
options.AddVerb.Patch.Should().BeTrue();
options.AddVerb.FileName[0].Should().Be("untracked.bin");
}
示例5: Parse_verbs_using_instance
public void Parse_verbs_using_instance()
{
string invokedVerb = null;
object invokedVerbInstance = null;
var proof = new Random().Next(int.MaxValue);
var options = new OptionsWithVerbs();
options.CommitVerb.Should().NotBeNull();
options.CommitVerb.CreationProof = proof;
var parser = new CommandLine.Parser();
var result = parser.ParseArguments(new string[] { "commit", "--amend" }, options,
(verb, subOptions) =>
{
invokedVerb = verb;
invokedVerbInstance = subOptions;
});
result.Should().BeTrue();
invokedVerb.Should().Be("commit");
invokedVerbInstance.Should().BeOfType<CommitSubOptions>();
// Check if the instance is the one provider by us (not by the parser)
options.CommitVerb.CreationProof.Should().Be(proof);
options.CommitVerb.Amend.Should().BeTrue();
}
示例6: Main
static void Main(string[] args)
{
Console.WriteLine("MetadataGenerator " + args.ToAggregateString(" "));
var parser = new CommandLine.Parser(ps => { ps.MutuallyExclusive = true; ps.HelpWriter = Console.Out; });
if (!parser.ParseArguments(args, Options))
{
return;
}
var assemblyName = GetAssemblyName(Options.InputFile);
if (!File.Exists(assemblyName))
{
Console.WriteLine("The specified file {0} cannot be found", assemblyName);
return;
}
var dbContextTypes = GetDbContextTypesFromAssembly(assemblyName);
if (dbContextTypes.Length == 1 || Options.TypeName != null)
{
if (Options.TypeName != null)
{
try
{
var type = dbContextTypes.SingleOrDefault(t => t.Name == Options.TypeName || t.FullName == Options.TypeName);
if (type != null)
{
ProcessType(type, Options.OutputFile ?? Options.TypeName + ".json");
}
else
{
Console.WriteLine("The type specified {0} can not be found in the assembly {1}",
Options.TypeName, assemblyName);
}
}
catch (InvalidOperationException)
{
Console.WriteLine("There are several types named {0} in the assembly {1}",
Options.TypeName, assemblyName);
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
else
{
var type = dbContextTypes.First();
ProcessType(type, Options.OutputFile ?? type.FullName + ".json");
}
}
else
{
// Hadle multitype scenario.
//foreach (var type in dbContextTypes) {
//}
}
}
示例7: Passing_no_value_to_a_nullable_integer_option_fails
public void Passing_no_value_to_a_nullable_integer_option_fails()
{
var options = new NullableTypesOptions();
var parser = new CommandLine.Parser();
var result = parser.ParseArguments(new string[] { "-int" }, options);
result.Should().BeFalse();
}
示例8: Parsing_two_mutually_exclusive_options_fails
public void Parsing_two_mutually_exclusive_options_fails()
{
var parser = new CommandLine.Parser(new ParserSettings { MutuallyExclusive = true });
var options = new OptionsWithDefaultSet();
var result = parser.ParseArguments(new string[] { "-i", "1", "--file=mystuff.xml" }, options);
result.Should().BeFalse();
}
示例9: Parsing_mutually_exclusive_options_and_required_option_fails
public void Parsing_mutually_exclusive_options_and_required_option_fails()
{
var options = new OptionsWithMultipleSetAndOneOption();
var parser = new CommandLine.Parser(new ParserSettings { MutuallyExclusive = true });
var result = parser.ParseArguments(new string[] { "-g167", "--hue", "205" }, options);
result.Should().BeFalse();
}
示例10: Parsing_one_mutually_exclusive_option_succeeds
public void Parsing_one_mutually_exclusive_option_succeeds()
{
var options = new OptionsWithDefaultSet();
var parser = new CommandLine.Parser(new ParserSettings {MutuallyExclusive = true});
var result = parser.ParseArguments(new string[] { "--file=mystuff.xml" }, options);
result.Should().BeTrue();
options.FileName.Should().Be("mystuff.xml");
}
示例11: Value_list_with_max_elem_outside_bounds
public void Value_list_with_max_elem_outside_bounds()
{
var options = new OptionsWithValueListMaximumThree();
var parser = new CommandLine.Parser();
var result = parser.ParseArguments(
new string[] { "file.a", "file.b", "file.c", "file.d" }, options);
result.Should().BeFalse();
}
示例12: Allow_single_dash_as_option_input_value
public void Allow_single_dash_as_option_input_value()
{
var options = new SimpleOptions();
var parser = new CommandLine.Parser();
var result = parser.ParseArguments(new string[] { "--string", "-" }, options);
result.Should().BeTrue();
options.StringValue.Should().Be("-");
}
示例13: Parse_string_array_option_using_long_name_with_equal_sign
public void Parse_string_array_option_using_long_name_with_equal_sign()
{
var options = new SimpleOptionsWithArray();
var parser = new CommandLine.Parser();
var result = parser.ParseArguments(new string[] { "--strarr=apple", "kiwi" }, options);
result.Should().BeTrue();
base.ElementsShouldBeEqual(new string[] { "apple", "kiwi" }, options.StringArrayValue);
}
示例14: Parse_string_array_option_using_short_name
public void Parse_string_array_option_using_short_name()
{
var options = new SimpleOptionsWithArray();
var parser = new CommandLine.Parser();
var result = parser.ParseArguments(new string[] { "-z", "alfa", "beta", "gamma" }, options);
result.Should().BeTrue();
base.ElementsShouldBeEqual(new string[] { "alfa", "beta", "gamma" }, options.StringArrayValue);
}
示例15: Between_value_options_order_matters
public void Between_value_options_order_matters()
{
var options = new SimpleOptionsWithValueOptionAndValueList();
var parser = new CommandLine.Parser();
var result = parser.ParseArguments(
new string[] { "4321", "ofvalueoption", "-1234", "forvaluelist1", "forvaluelist2", "forvaluelist3" }, options);
result.Should().BeFalse();
}