public void AutomaticUsage() { var hf = new HelpFormatter(); String expected = "usage: app [-a]"; var output = new MemoryStream(); var pw = new StreamWriter(output); Options options = new Options().AddOption("a", false, "aaaa aaaa aaaa aaaa aaaa"); hf.PrintUsage(options, new HelpSettings { Width = 60, CommandLineSyntax = "app" }, pw); pw.Flush(); Assert.AreEqual(expected, Encoding.UTF8.GetString(output.ToArray()).Trim(), "simple auto usage"); output = new MemoryStream(); pw = new StreamWriter(output); expected = "usage: app [-a] [-b]"; options = new Options().AddOption("a", false, "aaaa aaaa aaaa aaaa aaaa").AddOption("b", false, "bbb"); hf.PrintUsage(options, new HelpSettings { CommandLineSyntax = "app", Width = 60 }, pw); pw.Flush(); Assert.AreEqual(expected, Encoding.UTF8.GetString(output.ToArray()).Trim(), "simple auto usage"); }
public void PrintSortedUsageWithNullComparer() { Options opts = new Options(); opts.AddOption(new Option("a", "first")); opts.AddOption(new Option("b", "second")); opts.AddOption(new Option("c", "third")); HelpFormatter helpFormatter = new HelpFormatter(); StringWriter output = new StringWriter(); helpFormatter.PrintUsage(opts, new HelpSettings { Width = 80, CommandLineSyntax = "app", OptionComparer = null }, output); Assert.AreEqual("usage: app [-a] [-b] [-c]" + Eol, output.ToString()); }
public void PrintUsage() { var optionA = new Option("a", "first"); var optionB = new Option("b", "second"); var optionC = new Option("c", "third"); var opts = new Options(); opts.AddOption(optionA); opts.AddOption(optionB); opts.AddOption(optionC); var helpFormatter = new HelpFormatter(); var bytesOut = new MemoryStream(); var printWriter = new StreamWriter(bytesOut); helpFormatter.PrintUsage(opts, new HelpSettings { Width = 80, CommandLineSyntax = "app" }, printWriter); printWriter.Close(); Assert.AreEqual("usage: app [-a] [-b] [-c]" + Eol, Encoding.UTF8.GetString(bytesOut.ToArray())); }
public void PrintOptionWithEmptyArgNameUsage() { Option option = new Option("f", true, null); option.ArgumentName = ""; option.IsRequired = true; Options options = new Options(); options.AddOption(option); StringWriter output = new StringWriter(); HelpFormatter formatter = new HelpFormatter(); formatter.PrintUsage(options, new HelpSettings { ArgumentName = null, CommandLineSyntax = "app", Width = 80 }, output); Assert.AreEqual("usage: app -f" + Eol, output.ToString()); }
public void PrintOptionGroupUsage() { OptionGroup group = new OptionGroup(); group.AddOption(OptionBuilder.New().Create("a")); group.AddOption(OptionBuilder.New().Create("b")); group.AddOption(OptionBuilder.New().Create("c")); Options options = new Options(); options.AddOptionGroup(group); StringWriter output = new StringWriter(); HelpFormatter formatter = new HelpFormatter(); formatter.PrintUsage(options, new HelpSettings { Width = 80, CommandLineSyntax = "app" }, output); Assert.AreEqual("usage: app [-a | -b | -c]" + Eol, output.ToString()); }