public void PrintHelp_ShouldPrintBasicInfoWithParamSeries() { var outputAggregator = new OutputAggregator(); Cli.Configure(configurator => configurator .SetDialect(_dialect) .SetOutput(outputAggregator) ) .Root(configurator => configurator .RegisterParameterSeries <string>("paramSeries", "Param series Description") ) .Run(new[] { "" + _longPrefix + "help" }); NFAssert.HelpEquals( outputAggregator, "Usage:", "\ttesthost [OPTIONS]... [PARAMETERS]...", "", "\tParameters:", "\t<paramSeries...>\tParam series Description", "", "\tOptions:", "\t" + _longPrefix + "help, " + _shortPrefix + "h\tPrints this help", "" ); }
public void NFlags_ShouldPrintHelpForPersistentFlagsAtNthLevelSubCommand() { var outputAggregator = new OutputAggregator(); Cli.Configure(c => c.SetOutput(outputAggregator)) .Root(c => c. RegisterPersistentFlag("flag1", "f1", "dFlag1", false). RegisterCommand("sub", "desc", sc => sc. RegisterCommand("sub1", "desc1", sc1 => sc1. RegisterCommand("sub2", "desc2", sc2 => sc2. RegisterCommand("sub3", "desc3", sc3 => { }) ) ) ). RegisterPersistentFlag("flag2", "dFlag2", false) ) .Run(new[] { "sub", "sub1", "sub2", "sub3", "/h" }); NFAssert.HelpEquals( outputAggregator, "Usage:", "\ttesthost sub sub1 sub2 sub3 [OPTIONS]...", "", "\tOptions:", "\t/flag1, /f1\tdFlag1", "\t/flag2\tdFlag2", "\t/help, /h\tPrints this help", "" ); }
public void PrintHelp_ShouldPrintBasicInfoWithFlags() { var outputAggregator = new OutputAggregator(); Cli.Configure(configurator => configurator .SetDialect(_dialect) .SetOutput(outputAggregator) ) .Root(configurator => configurator .RegisterFlag("flag1", "Flag 1 Description", false) .RegisterFlag("flag2", "f2", "Flag 2 Description", false) ) .Run(new[] { "" + _longPrefix + "help" }); NFAssert.HelpEquals( outputAggregator, "Usage:", "\ttesthost [OPTIONS]...", "", "\tOptions:", "\t" + _longPrefix + "flag1\tFlag 1 Description", "\t" + _longPrefix + "flag2, " + _shortPrefix + "f2\tFlag 2 Description", "\t" + _longPrefix + "help, " + _shortPrefix + "h\tPrints this help", "" ); }
public void PrintHelp_ShouldPrintBasicInfoWithOptions() { var outputAggregator = new OutputAggregator(); Cli.Configure(configurator => configurator .SetDialect(_dialect) .SetOutput(outputAggregator) ) .Root(configurator => configurator .RegisterOption("option1", "Option 1 Description", "") .RegisterOption("option2", "o2", "Option 2 Description", "") ) .Run(new[] { "" + _longPrefix + "help" }); NFAssert.HelpEquals( outputAggregator, "Usage:", "\ttesthost [OPTIONS]...", "", "\tOptions:", "\t" + _longPrefix + "option1" + _optionValueSeparator + "<option1>\tOption 1 Description (Default: '')", "\t" + _longPrefix + "option2" + _optionValueSeparator + "<option2>, " + _shortPrefix + "o2" + _optionValueSeparator + "<option2>\tOption 2 Description (Default: '')", "\t" + _longPrefix + "help, " + _shortPrefix + "h\tPrints this help", "" ); }
public void RegisterCommandT_ShouldPrintParametersOptionsFlagsAndParameterSeriesInHelp() { var outputAggregator = new OutputAggregator(); Cli .Configure(c => c .SetDialect(Dialect.Gnu) .SetOutput(outputAggregator) ) .Root <ArgumentsType>(c => c .RegisterCommand <ArgumentsType>("sub", "sub command ", rc => rc .SetExecute((args, output) => { })) .SetExecute((type, output) => { }) ) .Run(new[] { "sub", "--help" }); NFAssert.HelpEquals( outputAggregator, "Usage:", "\ttesthost sub [OPTIONS]... [PARAMETERS]...", "", "\tParameters:", "\t<parameter1>\tparameter desc (Default: " + 1.1 + ")", "\t<parameter2>\tparameter2 desc (Default: " + 1 + ", Environment variable: 'NFLAG_TEST_PARAMETER2', Config path: 'Config:Path:Parameter2')", "\t<parameterSeries...>\tparameter series desc", "", "\tOptions:", "\t--option1 <option1>\toption desc (Default: " + 1 + ", Environment variable: 'NFLAG_TEST_OPTION1', Config path: 'Config:Path:Option1')", "\t--option2 <option2>, -o2 <option2>\toption2 desc (Default: 'asd')", "\t--flag1\tflag desc (Environment variable: 'NFLAG_TEST_FLAG1', Config path: 'Config:Path:Flag1')", "\t--flag2, -f2\tflag2 desc", "\t--help, -h\tPrints this help", "" ); }
public void TestRun_ShouldPrintGenericRootCommandHelp_IfDefaultCommandIsSetAndHelpFlagIsPassed() { var outputAggregator = new OutputAggregator(); Cli .Configure(c => c .SetOutput(outputAggregator) .SetDialect(Dialect.Gnu) ) .Root <EmptyArgumentsType>(c => c .RegisterDefaultCommand <EmptyArgumentsType>( "command", "description", configurator => configurator .PrintHelpOnExecute() ) ) .Run(new [] { "-h" }); NFAssert.HelpEquals(outputAggregator, "Usage:", "\ttesthost [COMMAND] [OPTIONS]...", "", "\tCommands:", "\tcommand\tdescription", "", "\tOptions:", "\t--help, -h\tPrints this help", "" ); }
public void PrintHelp_ShouldPrintCustomVersionDescription() { var outputAggregator = new OutputAggregator(); Cli.Configure(configurator => configurator .SetDialect(_dialect) .SetOutput(outputAggregator) .SetName("groups") .SetDescription("some description") .ConfigureVersion(vc => vc.Enable().SetOptionDescription("custom version description")) ) .Root(configurator => configurator.PrintHelpOnExecute()) .Run(new string[0]); NFAssert.HelpEquals( outputAggregator, "Usage:", "\tgroups [OPTIONS]...", "", "some description", "", "\tOptions:", "\t" + _longPrefix + "help, " + _shortPrefix + "h\tPrints this help", "\t" + _longPrefix + "version, " + _shortPrefix + "v\tcustom version description", "" ); }
public void PrintHelp_ShouldPrintCustomHelpFlagAbbreviation() { var outputAggregator = new OutputAggregator(); Cli.Configure(configurator => configurator .SetDialect(_dialect) .SetOutput(outputAggregator) .SetName("groups") .SetDescription("some description") .ConfigureHelp(hc => hc.SetOptionAbr("x")) ) .Root(configurator => configurator.PrintHelpOnExecute()) .Run(new string[0]); NFAssert.HelpEquals( outputAggregator, "Usage:", "\tgroups [OPTIONS]...", "", "some description", "", "\tOptions:", "\t" + _longPrefix + "help, " + _shortPrefix + "x\tPrints this help", "" ); }
public void PrintHelp_ShouldPrintInfoOfVersionOption_WhenEnabled() { var outputAggregator = new OutputAggregator(); Cli.Configure(configurator => { configurator .SetDialect(_dialect) .SetOutput(outputAggregator) .ConfigureVersion(vc => vc.Enable()); }) .Root(c => { }) .Run(new[] { "" + _longPrefix + "help" }); NFAssert.HelpEquals( outputAggregator, "Usage:", "\ttesthost [OPTIONS]...", "", "\tOptions:", "\t" + _longPrefix + "help, " + _shortPrefix + "h\tPrints this help", "\t" + _longPrefix + "version, " + _shortPrefix + "v\tPrints application version", "" ); }
public void TestParams_ShouldPrintMessageWithHelp_IfCannotConvertValue() { var outputAggregator = new OutputAggregator(); Cli.Configure(configurator => configurator .SetDialect(Dialect.Win) .SetOutput(outputAggregator) ) .Root(configurator => configurator .RegisterOption("option", "", 1) .SetExecute((args, output) => 0) ) .Run(new[] { "/option=asd" }); NFAssert.HelpEquals( outputAggregator, "Cannot convert value 'asd' to type 'System.Int32'", "", "Usage:", "\ttesthost [OPTIONS]...", "", "\tOptions:", "\t/option=<option>\t(Default: 1)", "\t/help, /h\tPrints this help", "" ); }
public void NFlags_ShouldPrintHelpForPersistentOptionsAtNthLevelSubCommand() { var outputAggregator = new OutputAggregator(); Cli.Configure(c => c.SetOutput(outputAggregator)) .Root(c => c. RegisterPersistentOption("option1", "o1", "dOption1", ""). RegisterCommand("sub", "desc", sc => sc. RegisterCommand("sub1", "desc1", sc1 => sc1. RegisterCommand("sub2", "desc2", sc2 => sc2. RegisterCommand("sub3", "desc3", sc3 => { }) ) ) ). RegisterPersistentOption("option2", "dOption2", "") ) .Run(new[] { "sub", "sub1", "sub2", "sub3", "/h" }); NFAssert.HelpEquals( outputAggregator, "Usage:", "\ttesthost sub sub1 sub2 sub3 [OPTIONS]...", "", "\tOptions:", "\t/option1=<option1>, /o1=<option1>\tdOption1 (Default: '')", "\t/option2=<option2>\tdOption2 (Default: '')", "\t/help, /h\tPrints this help", "" ); }
public static void HelpEquals(OutputAggregator output, params string[] lines) { var expectedResultBuilder = new StringBuilder(); foreach (var line in lines) { expectedResultBuilder.AppendLine(line); } Xunit.Assert.Equal(expectedResultBuilder.ToString(), output.ToString()); }
public void PrintHelp_ShouldPrintFlagAndOptionsInGroups() { var outputAggregator = new OutputAggregator(); Cli.Configure(configurator => configurator .SetDialect(Dialect.Gnu) .SetOutput(outputAggregator) .SetName("groups") .SetDescription("some description") ) .Root <GroupedArgumentsType>(configurator => { }) .Run(new[] { "--help" }); NFAssert.HelpEquals( outputAggregator, "Usage:", "\tgroups [OPTIONS]... [PARAMETERS]...", "", "some description", "", "\tParameters:", "\t<param1>", "\t<param2>", "\t<param3>", "", "\tOptions:", "\t--flag2", "\t--flag4", "\t--flag7", "\t--option2 <option2>\t(Default: 0)", "\t--option4 <option4>\t(Default: 0)", "\t--option7 <option7>\t(Default: 0)", "\t--help, -h\tPrints this help", "", "\tgroup1:", "\t\t--flag1", "\t\t--flag5", "\t\t--option1 <option1>\t(Default: 0)", "\t\t--option3 <option3>\t(Default: 0)", "", "\tgroup2:", "\t\t--flag3", "\t\t--option5 <option5>\t(Default: 0)", "", "\tgroup3:", "\t\t--flag6", "\t\t--option6 <option6>\t(Default: 0)", "" ); }
public void NFlags_WithoutCommandConfigured_ShouldPrintNothing() { const string expectedOutput = ""; var outputAggregator = new OutputAggregator(); Cli.Configure(configurator => configurator .SetOutput(outputAggregator) ) .Root(c => c .SetExecute((args, output) => { }) ) .Run(Array.Empty <string>()); Assert.Equal(expectedOutput, outputAggregator.ToString()); }
public void TestRun_ShouldPrintHelpWhenGenericCommandExecuted() { var outputAggregator = new OutputAggregator(); Cli .Configure(c => c.SetOutput(outputAggregator)) .Root <EmptyArgumentsType>(c => c.PrintHelpOnExecute()) .Run(new string[0]); NFAssert.HelpEquals(outputAggregator, "Usage:", "\ttesthost [OPTIONS]...", "", "\tOptions:", "\t/help, /h\tPrints this help", "" ); }
public void PrintHelp_ShouldPrintVersion_WhenCustomFlagAbrPassed() { var outputAggregator = new OutputAggregator(); Cli.Configure(configurator => { configurator .SetDialect(Dialect.Gnu) .ConfigureVersion(vc => vc.Enable().SetOptionAbr("x")) .SetOutput(outputAggregator); }) .Root(c => { }) .Run(new[] { "-x" }); NFAssert.HelpEquals( outputAggregator, "testhost Version: " + Assembly.GetEntryAssembly()?.GetName().Version ); }
public void RegisterCommand_ShouldPrintParametersOptionsFlagsAndParameterSeriesInHelp() { var outputAggregator = new OutputAggregator(); Cli .Configure(c => c .SetDialect(Dialect.Gnu) .SetOutput(outputAggregator) ) .Root(c => c .RegisterCommand("sub", "sub command ", rc => rc .RegisterOption <int>(b => b.Name("option1").Description("option desc").DefaultValue(1)) .RegisterOption <string>(b => b.Name("option2").Abr("o2").Description("option2 desc").DefaultValue("asd")) .RegisterFlag(b => b.Name("flag1").Description("flag desc").DefaultValue(true)) .RegisterFlag(b => b.Name("flag2").Abr("f2").Description("flag2 desc")) .RegisterParameter <double>(b => b.Name("parameter1").Description("parameter desc").DefaultValue(1.1)) .RegisterParameter <int>(b => b.Name("parameter2").Description("parameter2 desc").DefaultValue(1)) .RegisterParameterSeries <int>(b => b.Name("parameterSeries").Description("parameter series desc")) .SetExecute((args, output) => { })) .SetExecute((type, output) => { }) ) .Run(new[] { "sub", "--help" }); NFAssert.HelpEquals( outputAggregator, "Usage:", "\ttesthost sub [OPTIONS]... [PARAMETERS]...", "", "\tParameters:", "\t<parameter1>\tparameter desc (Default: " + 1.1 + ")", "\t<parameter2>\tparameter2 desc (Default: " + 1 + ")", "\t<parameterSeries...>\tparameter series desc", "", "\tOptions:", "\t--option1 <option1>\toption desc (Default: " + 1 + ")", "\t--option2 <option2>, -o2 <option2>\toption2 desc (Default: 'asd')", "\t--flag1\tflag desc", "\t--flag2, -f2\tflag2 desc", "\t--help, -h\tPrints this help", "" ); }
public void PrintHelp_ShouldPrintDefaultValueAfterOptionAndParametersDescriptions() { var outputAggregator = new OutputAggregator(); Cli.Configure(configurator => configurator .SetDialect(_dialect) .SetOutput(outputAggregator) .SetName("custName") .SetDescription("some description") ) .Root(configurator => configurator .RegisterFlag("flag1", "Flag 1 Description", false) .RegisterFlag("flag2", "f2", "Flag 2 Description", false) .RegisterOption("option1", "Option 1 Description", 1) .RegisterOption("option2", "o2", "Option 2 Description", 2.1) .RegisterParameter("param1", "Param 1 Description", 8.5m) .RegisterParameter("param2", "Param 2 Description", "default") .RegisterParameter("param3", "", "default") ) .Run(new[] { "" + _longPrefix + "help" }); NFAssert.HelpEquals( outputAggregator, "Usage:", "\tcustName [OPTIONS]... [PARAMETERS]...", "", "some description", "", "\tParameters:", "\t<param1>\tParam 1 Description (Default: " + 8.5 + ")", "\t<param2>\tParam 2 Description (Default: 'default')", "\t<param3>\t(Default: 'default')", "", "\tOptions:", "\t" + _longPrefix + "flag1\tFlag 1 Description", "\t" + _longPrefix + "flag2, " + _shortPrefix + "f2\tFlag 2 Description", "\t" + _longPrefix + "option1" + _optionValueSeparator + "<option1>\tOption 1 Description (Default: 1)", "\t" + _longPrefix + "option2" + _optionValueSeparator + "<option2>, " + _shortPrefix + "o2" + _optionValueSeparator + "<option2>\tOption 2 Description (Default: " + 2.1 + ")", "\t" + _longPrefix + "help, " + _shortPrefix + "h\tPrints this help", "" ); }
public void PrintHelp_ShouldPrintSubCommandBasicInfoWithDefaultName() { var outputAggregator = new OutputAggregator(); Cli.Configure(configurator => configurator .SetDialect(_dialect) .SetOutput(outputAggregator) ) .Root(c => { }) .Run(new[] { "" + _longPrefix + "help" }); NFAssert.HelpEquals( outputAggregator, "Usage:", "\ttesthost [OPTIONS]...", "", "\tOptions:", "\t" + _longPrefix + "help, " + _shortPrefix + "h\tPrints this help", "" ); }
public void TestParams_ShouldPrintSubCommandHelp_IfSubCommandCalled() { var outputAggregator = new OutputAggregator(); Cli.Configure(configurator => configurator .SetDialect(Dialect.Win) .SetOutput(outputAggregator) ) .Root(configurator => configurator .RegisterFlag("flag1", "f1", "", false) .RegisterFlag("flag2", "", false) .RegisterCommand("sub", "sub command description", c => c .RegisterOption("option1", "", "") .RegisterOption("option2", "o2", "", "") .RegisterParameter("param1", "", "") .RegisterParameter("param2", "", "") ) ) .Run(new[] { "sub", "/h" }); NFAssert.HelpEquals( outputAggregator, "Usage:", "\ttesthost sub [OPTIONS]... [PARAMETERS]...", "", "\tParameters:", "\t<param1>\t(Default: '')", "\t<param2>\t(Default: '')", "", "\tOptions:", "\t/option1=<option1>\t(Default: '')", "\t/option2=<option2>, /o2=<option2>\t(Default: '')", "\t/help, /h\tPrints this help", "" ); }
public void NFlags_ShouldPrintHelpForPersistentFlags() { var outputAggregator = new OutputAggregator(); Cli.Configure(c => c.SetOutput(outputAggregator)) .Root(c => c. RegisterPersistentFlag("flag1", "f1", "dFlag1", false). RegisterPersistentFlag("flag2", "dFlag2", false) ) .Run(new[] { "/h" }); NFAssert.HelpEquals( outputAggregator, "Usage:", "\ttesthost [OPTIONS]...", "", "\tOptions:", "\t/flag1, /f1\tdFlag1", "\t/flag2\tdFlag2", "\t/help, /h\tPrints this help", "" ); }
public void NFlags_ShouldPrintHelpForPersistentOptions() { var outputAggregator = new OutputAggregator(); Cli.Configure(c => c.SetOutput(outputAggregator)) .Root(c => c. RegisterPersistentOption("option1", "o1", "dOption1", ""). RegisterPersistentOption("option2", "dOption2", "") ) .Run(new[] { "/h" }); NFAssert.HelpEquals( outputAggregator, "Usage:", "\ttesthost [OPTIONS]...", "", "\tOptions:", "\t/option1=<option1>, /o1=<option1>\tdOption1 (Default: '')", "\t/option2=<option2>\tdOption2 (Default: '')", "\t/help, /h\tPrints this help", "" ); }
public void TestRun_ShouldPrintSubCommandHelp_IfPrintHelpOnExecuteIsSetForSubCommand() { var outputAggregator = new OutputAggregator(); Cli .Configure(c => c.SetOutput(outputAggregator)) .Root <EmptyArgumentsType>(c => c .PrintHelpOnExecute() .RegisterCommand <EmptyArgumentsType>("command", "description", configurator => configurator .PrintHelpOnExecute() ) ) .Run(new [] { "command" }); NFAssert.HelpEquals(outputAggregator, "Usage:", "\ttesthost command [OPTIONS]...", "", "\tOptions:", "\t/help, /h\tPrints this help", "" ); }
public void TestParams_ShouldPrintMessageWithHelp_IfCannotConvertValue() { var outputAggregator = new OutputAggregator(); Cli.Configure(c => c .SetOutput(outputAggregator) ) .Root(c => { }) .Run(new[] { "s" }); var expectedResultBuilder = new StringBuilder(); expectedResultBuilder.AppendLine("Two many parameters. Can't handle s value."); expectedResultBuilder.AppendLine(); expectedResultBuilder.AppendLine("Usage:"); expectedResultBuilder.AppendLine("\ttesthost [OPTIONS]..."); expectedResultBuilder.AppendLine(); expectedResultBuilder.AppendLine("\tOptions:"); expectedResultBuilder.AppendLine("\t/help, /h Prints this help"); expectedResultBuilder.AppendLine(); Assert.Equal(expectedResultBuilder.ToString(), outputAggregator.ToString()); }
public void PrintHelp_ShouldPrintFlagAndOptionsInGroups() { var outputAggregator = new OutputAggregator(); Cli.Configure(configurator => configurator .SetDialect(_dialect) .SetOutput(outputAggregator) .SetName("groups") .SetDescription("some description") ) .Root(configurator => configurator .RegisterFlag(b => b.Name("flag1").Group("group1")) .RegisterFlag(b => b.Name("flag2")) .RegisterFlag(b => b.Name("flag3").Group("group2")) .RegisterFlag(b => b.Name("flag4")) .RegisterFlag(b => b.Name("flag5").Group("group1")) .RegisterFlag(b => b.Name("flag6").Group("group3")) .RegisterFlag(b => b.Name("flag7")) .RegisterOption <int>(b => b.Name("option1").Group("group1")) .RegisterOption <int>(b => b.Name("option2")) .RegisterOption <int>(b => b.Name("option3").Group("group1")) .RegisterOption <int>(b => b.Name("option4")) .RegisterOption <int>(b => b.Name("option5").Group("group2")) .RegisterOption <int>(b => b.Name("option6").Group("group3")) .RegisterOption <int>(b => b.Name("option7")) .RegisterParameter <string>(b => b.Name("param1")) .RegisterParameter <string>(b => b.Name("param2")) .RegisterParameter <string>(b => b.Name("param3")) ) .Run(new[] { "" + _longPrefix + "help" }); NFAssert.HelpEquals( outputAggregator, "Usage:", "\tgroups [OPTIONS]... [PARAMETERS]...", "", "some description", "", "\tParameters:", "\t<param1>", "\t<param2>", "\t<param3>", "", "\tOptions:", "\t" + _longPrefix + "flag2", "\t" + _longPrefix + "flag4", "\t" + _longPrefix + "flag7", "\t" + _longPrefix + "option2" + _optionValueSeparator + "<option2>\t(Default: 0)", "\t" + _longPrefix + "option4" + _optionValueSeparator + "<option4>\t(Default: 0)", "\t" + _longPrefix + "option7" + _optionValueSeparator + "<option7>\t(Default: 0)", "\t" + _longPrefix + "help, " + _shortPrefix + "h\tPrints this help", "", "\tgroup1:", "\t\t" + _longPrefix + "flag1", "\t\t" + _longPrefix + "flag5", "\t\t" + _longPrefix + "option1" + _optionValueSeparator + "<option1>\t(Default: 0)", "\t\t" + _longPrefix + "option3" + _optionValueSeparator + "<option3>\t(Default: 0)", "", "\tgroup2:", "\t\t" + _longPrefix + "flag3", "\t\t" + _longPrefix + "option5" + _optionValueSeparator + "<option5>\t(Default: 0)", "", "\tgroup3:", "\t\t" + _longPrefix + "flag6", "\t\t" + _longPrefix + "option6" + _optionValueSeparator + "<option6>\t(Default: 0)", "" ); }