public void CaseFolding_ParseShortArgWithWrongCaseWhenCaseInsensitive_CorrectlyParsesArgs() { var parser = new CliParser <CaseFoldingOptions>( new CaseFoldingOptions(), ParserOptions.CaseInsensitive); parser.Parse("-N timothy".Split()); }
public CliprConfigurationSource(string[] args) { Config = new T(); var parser = new CliParser <T>(Config); parser.Parse(args); }
public static CoverallsOptions Parse(string[] args) { var res = new CoverallsOptions(); var parser = new CliParser <CoverallsOptions>(res); try { parser.Parse(args); if (!(res.OpenCover.SafeAny() || res.MonoCov.SafeAny() || res.Chutzpah.SafeAny() || res.DynamicCodeCoverage.SafeAny() || res.Lcov.SafeAny() || res.VsCoverage.SafeAny())) { throw new Exception(Usage); } return(res); } catch (ParseException ex) { throw new Exception($"{ex.Message}{Environment.NewLine}{Environment.NewLine}{Usage}"); } }
public void TryParse_WithOutAndInvalidArgs_SetsOutValueToNull() { CaseFoldingOptions obj; CliParser.TryParse("--ame tim".Split(), out obj); Assert.AreEqual(null, obj); }
public void ShowHelp_WithAmericanLocale_ShowsEnglishHelpText() { using (LocalizationExtensions.WithUiCulture(new CultureInfo("en-US"))) { // Arrange var expected = @"Usage: clipr [ -h|--help ] [ --version ] [ --turnonthepower ] [ -s S ] [ -c C ] FILETOADD Positional Arguments: FileToAdd File to add to the thing. Optional Arguments: --turnonthepower Set power level to 9001. -c A cool counter. -h, --help Display this help document. -s Start date. --version Displays the version of the current executable."; var opt = new LocalizationOptions(); var parser = new CliParser <LocalizationOptions>(opt); var help = new AutomaticHelpGenerator <LocalizationOptions>(); // TODO simplify work required to get help info // Act var actual = help.GetHelp(parser.Config); // Assert Assert.AreEqual(expected, actual); } }
public void ParseArguments_WithPositionalBeforeNamed_ParsesBothArguments() { var opt = CliParser.Parse <MixedNamedAndPositional>("pos -n name".Split()); Assert.AreEqual("name", opt.Named); Assert.AreEqual("pos", opt.Positional); }
public void Parse_WithPositionalAgumentFollowingNamedWithNoLimit_LeavesLastArgumentForPositional() { var obj = CliParser.Parse <InfiniteNamedWithPositional>( "-n one two three -- positional".Split()); Assert.AreEqual("positional", obj.Positional); }
static void CustomDateTime(string[] args) { var opt = CliParser.Parse <CustomDateTimeOptions>(args); Console.WriteLine(opt.CurrentDate[1]); // >>> }
public void TryParse_WithOutAndValidArgs_ParsesArgs() { CaseFoldingOptions obj; CliParser.TryParse("--name tim".Split(), out obj); Assert.AreEqual("tim", obj.Name); }
public void ParseExample_WithMultipleArgumentsAndAttributeConfig_ParsesOutputFile() { var opt = CliParser.Parse <Options>( "-vvv output.txt 1 2 -1 7".Split()); Assert.AreEqual("output.txt", opt.OutputFile); }
public void Parse_WithStaticEnumerationSubclassDefinedOnClass_ParsesIntoValue() { var obj = CliParser.Parse <StaticEnumerationOptions>( "-e second".Split()); Assert.AreSame(SomeEnum.Second, obj.Value); }
public void Parse_WithStaticEnumeration_ParsesValue() { var obj = CliParser.Parse <StaticEnumerationOptions>( "-e first".Split()); Assert.AreSame(SomeEnum.First, obj.Value); }
public void ParseExample_WithMultipleArgumentsAndAttributeConfig_ParsesVerbosity() { var opt = CliParser.Parse <Options>( "-vvv output.txt 1 2 -1 7".Split()); Assert.AreEqual(3, opt.Verbosity); }
public void Parse_WithStaticEnumerationDefinedOnProperty_ParsesIntoValue() { var obj = CliParser.Parse <StaticEnumerationOptionsExplicit>( "-e first".Split()); Assert.AreSame(SomeEnumNonStatic.First, obj.Value); }
public void Help_WithNestedHelpOfVerbCalled_GeneratedHelpOutputForVerb() { const string expected = @"Usage: clipr verb1 verb2 [ -a|--age A ] [ -h|--help ] Optional Arguments: -a, --age -h, --help Display this help document. "; var sw = new StringWriter(); var opt = new OptionsWithNestedVerbs(); var parser = new CliParser <OptionsWithNestedVerbs>(opt, new ParserOptions { OutputWriter = sw }); try { parser.Parse("verb1 verb2 --help".Split()); } catch (ParserExit e) { } var actual = sw.ToString(); Assert.AreEqual(expected, actual); }
public void Help_WithNestedHelpOfVerbCalledOnBaseVerb_GeneratedHelpOutputForVerbWithCommands() { const string expected = @"Usage: clipr verb1 [ -n|--name N ] [ -h|--help ] <command> Optional Arguments: -h, --help Display this help document. -n, --name Commands: verb2 A verb for ages "; var sw = new StringWriter(); var opt = new OptionsWithNestedVerbs(); var parser = new CliParser <OptionsWithNestedVerbs>(opt, new ParserOptions { OutputWriter = sw }); try { parser.Parse("verb1 --help".Split()); } catch (ParserExit e) { } var actual = sw.ToString(); Assert.AreEqual(expected, actual); }
static void Main(string[] args) { try { Options opt = CliParser.Parse <Options>(args); FileMode fileMode = (opt.NoCreate) ? FileMode.Open : FileMode.OpenOrCreate; LibTruncate.Truncate.TruncateFiles(new TruncateOptions { FileMode = fileMode, Quiet = opt.Quiet, Size = opt.Size }, opt.FileNames); } catch (ParseException ex) { Console.WriteLine(ex.Message); } catch (ParserExit) { // This is thrown when the --help or --version parameters are passed // to the parser so we can safely ignore. return; } }
public void Parse_WithStaticEnumerationSubclassCovariantDefinedOnClass_ParsesIntoValue() { var obj = CliParser.Parse <StaticEnumerationOptions>( "-e first".Split()); Assert.AreSame(SomeEnum.First, obj.Value); }
public void CaseFolding_ParseLongArgPrefixWithWrongCaseWhenCaseInsensitiveAndPartialMatch_CorrectlyParsesArgs() { var parser = new CliParser <CaseFoldingOptions>( new CaseFoldingOptions(), ParserOptions.CaseInsensitive | ParserOptions.NamedPartialMatch); parser.Parse("--Na timothy".Split()); }
public void Parse_WithIEnumerableNamedArgument_ParsesIntoIEnumerable() { var obj = CliParser.Parse <EnumerableArguments>( "-n 1 4 6 8".Split()); Assert.AreEqual(4, obj.Numbers.Count()); }
static void ParseRequiredNamedArgument(string[] args) { var opt = CliParser.Parse <RequiredNamedArgument>(args); Console.WriteLine(opt.CurrentDate); // >>> }
public void Parse_WithShortNamedAgumentFollowingNamedWithNoLimit_StopsParsingAtFirstDash() { var obj = CliParser.Parse <InfiniteNamedWithOtherNamedFollowing>( "-n one two three -o final".Split()); Assert.AreEqual("final", obj.Other); }
public void TryParse_WithInstanceAndValidArgs_ParsesArgs() { var obj = new CaseFoldingOptions(); CliParser.TryParse("--name tim".Split(), obj); Assert.AreEqual("tim", obj.Name); }
public void ShowHelp_WithMexicanLocale_ShowsSpanishHelpText() { using (LocalizationExtensions.WithUiCulture(new CultureInfo("es-MX"))) { // Arrange var expected = @"Forma de uso: clipr [ -h|--help ] [ --version ] [ --turnonthepower ] [ -s S ] [ -c C ] FILETOADD Argumentos dependientes de la posición: FileToAdd Archivo para añadir a la cosa. Argumentos opcionales: --turnonthepower Establecer el nivel de potencia de 9001. -c Un contador fresco. -h, --help Muestra esta ayuda -s Fecha de inicio. --version Muestra la versión del ejecutable"; var opt = new LocalizationOptions(); var parser = new CliParser <LocalizationOptions>(opt); var help = new AutomaticHelpGenerator <LocalizationOptions>(); // Act var actual = help.GetHelp(parser.Config); // Assert Assert.AreEqual(expected, actual); } }
public void ParseArgument_WithDuplicateArguments_ThrowsException() { var parser = new CliParser <DuplicateArguments>(new DuplicateArguments()); AssertEx.Throws <DuplicateArgumentException>( () => parser.Parse("-n orange".Split())); }
public void Argument_WithLongOptionAndPromptNoMasking_GetsValueFromStdin() { // TODO inject pw into stdin //const string password = "******"; var opt = CliParser.Parse<NamedArgumentWithOption>("--password".Split()); Assert.AreEqual("tim", opt.Name); }
private static void ParseArgs(string[] args) { var opt = new Verbs(); var helpGen = new HelpGenerator <Verbs>(); helpGen.DescriptionDistance = 25; var parser = new CliParser <Verbs>(opt, ParserOptions.CaseInsensitive, helpGen); parser.StrictParse(args); if (opt.Start != null) { StartService(opt.Start.ReadOnly); } else if (opt.Stop != null) { StopService(); } else if (opt.Set != null) { SetFanSpeed(opt.Set); } else if (opt.Config != null) { ConfigureService(opt.Config); } else if (opt.Status != null) { PrintStatus(opt.Status); } else { Console.WriteLine(helpGen.GetHelp(parser.Config)); } }
private static void ParseArgs(string[] args) { var opt = new Verbs(); var parser = new CliParser <Verbs>(opt, ParserOptions.CaseInsensitive, new VerbsHelpGenerator()); parser.StrictParse(args); if (opt.Start != null) { StartService(); } else if (opt.Stop != null) { StopService(); } else if (opt.Set != null) { SetFanSpeed(opt.Set); } else if (opt.Config != null) { ConfigureService(opt.Config); } else if (opt.Status != null) { PrintStatus(opt.Status); } }
private static void ParseArgs(string[] args) { var opt = new Verbs(); var parser = new CliParser<Verbs>(opt, ParserOptions.CaseInsensitive, new VerbsHelpGenerator()); parser.StrictParse(args); if (opt.Start != null) { StartService(); } else if (opt.Stop != null) { StopService(); } else if (opt.Set != null) { SetFanSpeed(opt.Set); } else if (opt.Config != null) { ConfigureService(opt.Config); } else if (opt.Status != null) { PrintStatus(opt.Status); } }
static void Main(string[] args) { //dynamic load: //load config file from args=>LoadConfig //Loader.LoadLog(LoadConfig.Log); //Loader.LoadCommunication(LoadConfig.Communication,host); //Loader.LoadThing(LoadConfig.Things,host); //very first thing to do is congfig logger //初始化 LogManager NlogProvider.Config(); Cfet2LogManager.SetLogProvider(new NlogProvider()); //inject and init the host app module var host = new Cfet2Program(); HubMaster.InjectHubToModule(host); //add communication module //var comm= new NancyCM("http://localhost:13345"); //var comm = new AspNetCoreCommunicatonModule(); //host.MyHub.TryAddCommunicationModule(comm); //todo lock comminication so no more communication can be added //add things host.AddThings(); //this is defined in a partial file of this class f12 to modify //start communication modules host.MyHub.StartCommunication(); //start all thins host.MyHub.StartThings(); //start cli loop var cli = new CliParser(host); cli.Host = host; Console.WriteLine("Cfet2 host Cli started"); while (true) { Console.Write("Cfet2> "); var command = Console.ReadLine(); try { cli.Execute(command); } catch (Exception e) { Console.WriteLine(e.Message); } if (cli.MySesstion.ShouldExit) { //quit the app break; } } }
public void Parse_WithNestedPostParseMethods_ExecutesMethodsFromInnerToOuterClass() { PostParseBuilder = new StringBuilder(); CliParser.Parse <PostParseOuter>("-u frank counter -c 5".Split()); Assert.AreEqual("5frank", PostParseBuilder.ToString()); }
public void Parse_WithFactoryAndGitVerbsCommitAndNoMessage_ParsesCommitVerb() { const string expected = "My default message"; var opt = new OptionsWithGitVerbs(); var factory = new SimpleVerbfactory { { () => new GitAdd() }, { typeof(GitCommit), () => new GitCommit("My default message") } }; var parser = new CliParser<OptionsWithGitVerbs>( opt, ParserOptions.None, new AutomaticHelpGenerator<OptionsWithGitVerbs>(), factory); parser.Parse("commit".Split()); var actual = opt.Commit.CommitMessage; Assert.AreEqual(expected, actual); }
public void Parse_WithFactoryAndGitVerbsAdd_ParsesAddVerb() { string[] expected = { "myfile.txt", "otherfile.txt" }; var opt = new OptionsWithGitVerbs(); var factory = new SimpleVerbfactory { { () => new GitAdd() }, { typeof(GitCommit), () => new GitCommit("My default message") } }; var parser = new CliParser<OptionsWithGitVerbs>( opt, ParserOptions.None, new AutomaticHelpGenerator<OptionsWithGitVerbs>(), factory); parser.Parse("add myfile.txt otherfile.txt".Split()); var actual = opt.Add.Files.ToList(); CollectionAssert.AreEqual(expected, actual); }
public void ParseDate_WithSpanishLocaleAndSpanishDateFormat_ParsesDateCorrectly() { using (LocalizationExtensions.WithUiCulture(new CultureInfo("es-ES"))) { // Arrange var expected = new DateTime(2016, 3, 12); var opt = new LocalizationOptions(); var parser = new CliParser<LocalizationOptions>(opt); var help = new AutomaticHelpGenerator<LocalizationOptions>(); // Act parser.Parse("-s 12/3/2016 file.txt".Split()); // Assert Assert.AreEqual(expected, opt.StartDate); } }
private static void ParseArgs(string[] args) { var opt = new Verbs(); var parser = new CliParser<Verbs>(opt, ParserOptions.CaseInsensitive, new CustomHelpGenerator()); parser.StrictParse(args); if (opt.ECDump != null) { ECDump(); } else if (opt.ECRead != null) { ECRead(opt.ECRead.Register); } else if (opt.ECWrite != null) { ECWrite(opt.ECWrite.Register, opt.ECWrite.Value, opt.ECWrite.Verbose); } else { Console.WriteLine((new CustomHelpGenerator()).GetHelp(null)); } }
public void PositionalArgument_WithLowerBoundCountEqualsZero_ParsesNoArguments() { var opts = new PositionalArgumentUnitTest.PositionalArgumentLowerBoundCountEqualsZero(); var arguments = new string[0]; var parser = new CliParser<PositionalArgumentUnitTest.PositionalArgumentLowerBoundCountEqualsZero>(opts); parser.Parse(arguments); Assert.AreEqual(0, opts.Args.Count); }
public void CaseFolding_ParseLongArgPrefixWithWrongCaseWhenCaseInsensitiveAndPartialMatch_CorrectlyParsesArgs() { var parser = new CliParser<CaseFoldingOptions>( new CaseFoldingOptions(), ParserOptions.CaseInsensitive | ParserOptions.NamedPartialMatch); parser.Parse("--Na timothy".Split()); }
public void CaseFolding_ParseShortArgWithWrongCaseWhenCaseInsensitive_CorrectlyParsesArgs() { var parser = new CliParser<CaseFoldingOptions>( new CaseFoldingOptions(), ParserOptions.CaseInsensitive); parser.Parse("-N timothy".Split()); }
public void ShowHelp_WithAmericanLocale_ShowsEnglishHelpText() { using (LocalizationExtensions.WithUiCulture(new CultureInfo("en-US"))) { // Arrange var expected = @"Usage: clipr [ -h|--help ] [ --version ] [ --turnonthepower ] [ -s S ] [ -c C ] FILETOADD Positional Arguments: FileToAdd File to add to the thing. Optional Arguments: --turnonthepower Set power level to 9001. -c A cool counter. -h, --help Display this help document. -s Start date. --version Displays the version of the current executable."; var opt = new LocalizationOptions(); var parser = new CliParser<LocalizationOptions>(opt); var help = new AutomaticHelpGenerator<LocalizationOptions>(); // TODO simplify work required to get help info // Act var actual = help.GetHelp(parser.Config); // Assert Assert.AreEqual(expected, actual); } }
public void ShowHelp_WithMexicanLocale_ShowsSpanishHelpText() { using (LocalizationExtensions.WithUiCulture(new CultureInfo("es-MX"))) { // Arrange var expected = @"Uso: clipr [ -h|--help ] [ --version ] [ --turnonthepower ] [ -s S ] [ -c C ] FILETOADD Los Argumentos Posicionales: FileToAdd Archivo para añadir a la cosa. Los Argumentos Opcionales: --turnonthepower Establecer el nivel de potencia de 9001. -c Un contador fresco. -h, --help Mostrar este documento de ayuda. -s Fecha de inicio. --version Muestra la versión del ejecutable actual."; var opt = new LocalizationOptions(); var parser = new CliParser<LocalizationOptions>(opt); var help = new AutomaticHelpGenerator<LocalizationOptions>(); // Act var actual = help.GetHelp(parser.Config); // Assert Assert.AreEqual(expected, actual); } }
public void Parse_WithVerbHavingDefaultConstructor_ParsesVerb() { const string expected = "myfile.txt"; var opt = new OptionsWithVerbDefaultConstructor(); var parser = new CliParser<OptionsWithVerbDefaultConstructor>(opt); parser.Parse("add myfile.txt".Split()); Assert.AreEqual(expected, opt.AddInfo.Filename); }
public void ParseNumber_WithMexicanLocaleAndMexicanNumberFormat_ParsesNumberCorrectly() { using (LocalizationExtensions.WithUiCulture(new CultureInfo("es-MX"))) { // Arrange var expected = 2.3; var opt = new LocalizationOptions(); var parser = new CliParser<LocalizationOptions>(opt); var help = new AutomaticHelpGenerator<LocalizationOptions>(); // Act parser.Parse("-c 2.3 file.txt".Split()); // Assert Assert.AreEqual(expected, opt.MyCounter); } }
public void PositionalArgument_WithLowerBoundCountEqualsZero_ParsesAllArguments() { var opts = new PositionalArgumentUnitTest.PositionalArgumentLowerBoundCountEqualsZero(); var arguments = new[] { "first", "second" }; var parser = new CliParser<PositionalArgumentUnitTest.PositionalArgumentLowerBoundCountEqualsZero>(opts); parser.Parse(arguments); Assert.AreEqual(2, opts.Args.Count); }
public void PositionalArgument_WithMultiplePositionalArgumentsAndLowerBoundCountEqualsZero_ParsesOtherArguments() { var opts = new PositionalArgumentUnitTest.MultiplePositionalArgumentLowerBoundCountEqualsZero(); var arguments = new[] { "fixed" }; var parser = new CliParser<PositionalArgumentUnitTest.MultiplePositionalArgumentLowerBoundCountEqualsZero>(opts); parser.Parse(arguments); Assert.AreEqual(0, opts.Args.Count); }
public void Parse_WithFactoryAndVerbHavingNoDefaultConstructor_ParsesVerb() { const string expected = "myfile.txt"; var opt = new OptionsWithNoDefaultConstructor(); var factory = new SimpleVerbfactory { { typeof(VerbWithNoDefaultConstructor), () => new VerbWithNoDefaultConstructor("default.txt") } }; var parser = new CliParser<OptionsWithNoDefaultConstructor>( opt, ParserOptions.None, new AutomaticHelpGenerator<OptionsWithNoDefaultConstructor>(), factory); parser.Parse("add myfile.txt".Split()); Assert.AreEqual(expected, opt.AddInfo.Filename); }
public void NamedArgument_WithLowerBoundCountEqualsZero_ParsesAllArguments() { var opts = new NamedArgumentLowerBoundCountEqualsZero(); var arguments = new[] { "-s", "first", "second" }; var parser = new CliParser<NamedArgumentLowerBoundCountEqualsZero>(opts); parser.Parse(arguments); Assert.AreEqual(2, opts.Args.Count); }
public void NamedArgument_WithLowerBoundCountEqualsZero_ParsesNoArguments() { var opts = new NamedArgumentLowerBoundCountEqualsZero(); var arguments = new string[0]; var parser = new CliParser<NamedArgumentLowerBoundCountEqualsZero>(opts); parser.Parse(arguments); Assert.AreEqual(0, opts.Args.Count); }