public void WriteGlobalCommands() { // Arrange var application = new KingpinApplication(console); application.Command("cmd1", "command1 help"); application.Command("cmd2", "command2 help"); // Act var subject = new HelpGenerator(application, console); var appText = subject.ReadResourceInExecutingAssembly("KingpinNet.Help.ApplicationHelp.liquid"); subject.Generate(writer, appText); // Assert var result = writer.ToString(); output.WriteLine(result); Assert.Contains($"usage: <command>", result); Assert.Contains($"Commands:", result); Assert.Contains($" cmd1", result); Assert.Contains($" command1 help", result); Assert.Contains($" cmd2", result); Assert.Contains($" command2 help", result); }
public void ParseSimpleCommand() { // Arrange string[] args = new[] { "run" }; var application = new KingpinApplication(consoleMock.Object); application.Command("run", "This is a command"); // Act var subject = new Parser(application); var result = subject.Parse(args); // Assert Assert.Equal("run", result.Result["Command"]); }
public void ParseHelpFlagOnCommand() { // Arrange string[] args = new[] { "run", "--help" }; var application = new KingpinApplication(console); application.Initialize(); application.Command("run", "This is a command"); // Act var result = application.Parse(args); // Assert Assert.Equal("true", result.Result["run:help"]); }
public void ParseNestedCommand() { // Arrange string[] args = new[] { "cmd1", "cmd2" }; var application = new KingpinApplication(consoleMock.Object); var command = application.Command("cmd1", "command1 help"); command.Command("cmd2", "command2 help"); // Act var subject = new Parser(application); var result = subject.Parse(args); // Assert Assert.Equal("cmd1:cmd2", result.Result["Command"]); }
public void ParseSimpleCommandWithFlag() { // Arrange string[] args = new[] { "run", "--myflag=danish" }; var application = new KingpinApplication(consoleMock.Object); var command = application.Command("run", "This is a command"); command.Flag("myflag", "This is the flag of the person"); // Act var subject = new Parser(application); var result = subject.Parse(args); // Assert Assert.Equal("run", result.Result["Command"]); Assert.Equal("danish", result.Result["run:myflag"]); }
public void ParseNestedDefaultFlag() { // Arrange string[] args = { "cmd1", "cmd2" }; var application = new KingpinApplication(consoleMock.Object); var command = application.Command("cmd1", "command1 help"); var cmd2 = command.Command("cmd2", "command2 help"); cmd2.Flag("flg", "").Default("1234"); // Act var subject = new Parser(application); var result = subject.Parse(args); // Assert Assert.Equal("1234", result.Result["cmd1:cmd2:flg"]); }
public void ParseSimpleCommandWithArgument() { // Arrange string[] args = new[] { "run", "an_argument" }; var application = new KingpinApplication(consoleMock.Object); var command = application.Command("run", "This is a command"); command.Argument("argument", "This is an argument"); // Act var subject = new Parser(application); var result = subject.Parse(args); // Assert Assert.Equal("run", result.Result["Command"]); Assert.Equal("an_argument", result.Result["run:argument"]); }
public void SuggestCommandSubstring() { // Arrange string[] args = new[] { "suggest", "cmd1", "cm" }; var application = new KingpinApplication(consoleMock.Object); var command = application.Command("cmd1", "command1 help"); command.Command("cmd2", "command2 help"); // Act var subject = new Parser(application); var result = subject.Parse(args); // Assert Assert.True(result.IsSuggestion); Assert.Equal("cmd2", result.Suggestions.First()); }
public void SuggestDoubleMinusShowFlags() { // Arrange string[] args = new[] { "suggest", "cmd1", "--" }; var application = new KingpinApplication(consoleMock.Object); var command = application.Command("cmd1"); command.Command("cmd2"); command.Flag("myflag"); // Act var subject = new Parser(application); var result = subject.Parse(args); // Assert Assert.True(result.IsSuggestion); Assert.Equal("--myflag", result.Suggestions[0]); }
public void SuggestCommandShowShortNamedFlag() { // Arrange string[] args = new[] { "suggest", "m" }; var application = new KingpinApplication(consoleMock.Object); var command = application.Command("cmd1"); application.Flag("myflag").Short('m'); // Act var subject = new Parser(application); var result = subject.Parse(args); // Assert Assert.True(result.IsSuggestion); Assert.Equal("cmd1", result.Suggestions[0]); Assert.Equal("--myflag", result.Suggestions[1]); Assert.Equal("-m", result.Suggestions[2]); }
public void WriteGlobalCommandWithFlagAndDefaultValue() { // Arrange var application = new KingpinApplication(console); var command = application.Command("cmd", "command help"); command.Flag("flag", "flag help").Default("1234.5678"); // Act var subject = new HelpGenerator(application, console); var appText = subject.ReadResourceInExecutingAssembly("KingpinNet.Help.ApplicationHelp.liquid"); subject.Generate(writer, appText); // Assert var result = writer.ToString(); output.WriteLine(result); Assert.Contains($"usage: <command>", result); Assert.Contains($"Commands:", result); Assert.Contains($" cmd --flag=<1234.5678> flag help command help", result); }
public void WriteGlobalCommandWithFlagAndExamples() { // Arrange var application = new KingpinApplication(console); var command = application.Command("cmd", "command help"); command.Flag("flag", "flag help").SetExamples("1", "2"); // Act var subject = new HelpGenerator(application, console); var appText = subject.ReadResourceInExecutingAssembly("KingpinNet.Help.CommandHelp.liquid"); subject.Generate(command, writer, appText); // Assert var result = writer.ToString(); output.WriteLine(result); Assert.Contains($"usage: cmd [<flags>]", result); Assert.Contains($" command help", result); Assert.Contains($"Flags:", result); Assert.Contains($" --flag=<value> flag help (e.g. 1, 2)", result); }
public void WriteFlagWithValueName() { // Arrange var application = new KingpinApplication(console); application.ApplicationName("x"); var command = application.Command("cmd", "command help"); command.Flag("flag", "flag help").ValueName("!name!"); // Act var subject = new HelpGenerator(application, console); var appText = subject.ReadResourceInExecutingAssembly("KingpinNet.Help.ApplicationHelp.liquid"); subject.Generate(writer, appText); // Assert var result = writer.ToString(); output.WriteLine(result); Assert.Contains($"usage: x <command>", result); Assert.Contains($"Commands:", result); Assert.Contains($" cmd --flag=!name!", result); Assert.Contains($" command help", result); }
public void ShowDetailedError() { // Arrange string[] args = new[] { "--integer=x1x" }; var application = new KingpinApplication(console); application.Initialize(); application.ShowHelpOnParsingErrors(); application.Command("integer", "This is an int").IsInt(); // Act try { application.Parse(args); } catch { } // Assert var result = writer.ToString(); output.WriteLine(result); Assert.Contains("Illegal flag", result); }