public void ParseOption(string prefix, string name, int argCount) { var opt = new StubOption(1, prefix, name); OptTable optTable = new OptTableBuilder() .Add(opt) .CreateTable(); var args = Enumerable.Repeat(prefix + name, argCount).ToList(); IArgumentList al = optTable.ParseArgs(args, out var missing); Assert.Equal(new MissingArgs(), missing); Assert.Equal(args.Count, al.Count); Assert.Equal(opt.CreatedArgs, al); }
public void ParseRemainingArgs(string prefix, string name) { OptTable optTable = new OptTableBuilder() .AddRemainingArgs(1, prefix, name) .CreateTable(); var args = new[] { prefix + name, prefix + name, "value", "-flag" }; IArgumentList al = optTable.ParseArgs(args, out var missing); Assert.Equal(0, missing.ArgIndex); Assert.Equal(0, missing.ArgCount); Assert.Equal(1, al.Count); Assert.Equal(optTable.MakeArg(1, prefix + name, 0, prefix + name, "value", "-flag"), al[0], argComparer); }
public void ParseMultiArg(string prefix, string name, string[] extraArgs) { OptTable optTable = new OptTableBuilder() .AddMultiArg(1, prefix, name, extraArgs.Length) .CreateTable(); var args = new[] { prefix + name }.Concat(extraArgs).ToArray(); IArgumentList al = optTable.ParseArgs(args, out var missing); Assert.Equal(0, missing.ArgIndex); Assert.Equal(0, missing.ArgCount); Assert.Equal(1, al.Count); Assert.Equal(optTable.MakeArg(1, prefix + name, 0, extraArgs), al[0], argComparer); }
public void ParseSeparate(string prefix, string name, string arg) { OptTable optTable = new OptTableBuilder() .AddSeparate(1, prefix, name) .CreateTable(); var args = new[] { prefix + name, arg }; IArgumentList al = optTable.ParseArgs(args, out var missing); Assert.Equal(0, missing.ArgIndex); Assert.Equal(0, missing.ArgCount); Assert.Equal(1, al.Count); Assert.Equal(optTable.MakeArg(1, prefix + name, 0, arg), al[0], argComparer); }
public void ParseSeparateMissingArg() { OptTable optTable = new OptTableBuilder() .AddSeparate(1, "-", "opt") .CreateTable(); var args = new[] { "-opt", "v1", "-opt" }; IArgumentList al = optTable.ParseArgs(args, out var missing); Assert.Equal(2, missing.ArgIndex); Assert.Equal(1, missing.ArgCount); Assert.Equal(1, al.Count); Assert.Equal(optTable.MakeArg(1, "-opt", 0, "v1"), al[0], argComparer); }
public void ParseMixed() { OptTable optTable = new OptTableBuilder() .AddFlag(1, "-", "a") .AddJoined(2, "-", "a=") .CreateTable(); var args = new[] { "-a=123", "-a" }; IArgumentList al = optTable.ParseArgs(args, out var missing); Assert.Equal(0, missing.ArgIndex); Assert.Equal(0, missing.ArgCount); Assert.Equal(2, al.Count); Assert.Equal(optTable.MakeArg(2, "-a=", 0, "123"), al[0], argComparer); Assert.Equal(optTable.MakeArg(1, "-a", 1), al[1], argComparer); }
public void ParseMultiArgMissingArgs( string prefix, string name, int argCount, string[] preArgs, string[] postArgs) { OptTable optTable = new OptTableBuilder() .AddUnknown(1) .AddMultiArg(2, prefix, name, argCount) .CreateTable(); var args = preArgs.Concat(new[] { prefix + name }).Concat(postArgs).ToArray(); IArgumentList al = optTable.ParseArgs(args, out var missing); Assert.Equal(preArgs.Length, missing.ArgIndex); Assert.Equal(argCount - postArgs.Length, missing.ArgCount); Assert.Equal(preArgs.Length, al.Count); Assert.True(al.All(a => a.Option.Id == 1)); }
public void ParseJoinedMultiplePrefixes() { OptTable optTable = new OptTableBuilder() .AddJoined(1, new[] { "-", "--", "/" }, "opt=") .CreateTable(); var args = new[] { "--opt=value1", "/opt=value2", "-opt=value3" }; IArgumentList al = optTable.ParseArgs(args, out var missing); Assert.Equal(0, missing.ArgIndex); Assert.Equal(0, missing.ArgCount); Assert.Equal(3, al.Count); Assert.Equal(optTable.MakeArg(1, "--opt=", 0, "value1"), al[0], argComparer); Assert.Equal(optTable.MakeArg(1, "/opt=", 1, "value2"), al[1], argComparer); Assert.Equal(optTable.MakeArg(1, "-opt=", 2, "value3"), al[2], argComparer); }
public void ParseFlagMultiplePrefixes() { OptTable optTable = new OptTableBuilder() .AddFlag(1, new[] { "-", "--", "/" }, "opt") .CreateTable(); var args = new[] { "--opt", "/opt", "-opt" }; IArgumentList al = optTable.ParseArgs(args, out var missing); Assert.Equal(0, missing.ArgIndex); Assert.Equal(0, missing.ArgCount); Assert.Equal(3, al.Count); Assert.Equal(optTable.MakeArg(1, "--opt", 0), al[0], argComparer); Assert.Equal(optTable.MakeArg(1, "/opt", 1), al[1], argComparer); Assert.Equal(optTable.MakeArg(1, "-opt", 2), al[2], argComparer); }
public void Verb() { var table = new OptTableBuilder() .Add(new VerbOption(1, "action", helpText: "Action", metaVar: "<action>")) .Add(new SeparateOption(2, "-", "name", helpText: "Name", metaVar: "foo")) .Add(new SeparateOption(3, "-", "foo", helpText: "Bar", metaVar: "foo")) .Add(new InputOption(4, metaVar: "foo")) .CreateTable(); var al = table.ParseArgs(new[] { "bar", "-name", "n" }, out var _); output.WriteLine("Help: {0}", table.GetHelp()); output.WriteLine("{0}", al.Count); output.WriteLine("{0}", al[0]); output.WriteLine("{0}", al[1]); }
public void ParseJoinedMultiple() { OptTable optTable = new OptTableBuilder() .AddJoined(1, "-", "aaaa") .AddJoined(2, new[] { "-", "--" }, "aaa") .AddJoined(3, "-", "a") .AddJoined(4, "--", "aa") .CreateTable(); var args = new[] { "--aaa1", "--aa2", "-aaaaa", "-a4", "-aaa5" }; IArgumentList al = optTable.ParseArgs(args, out var missing); Assert.Equal(0, missing.ArgIndex); Assert.Equal(0, missing.ArgCount); Assert.Equal(5, al.Count); Assert.Equal(optTable.MakeArg(2, "--aaa", 0, "1"), al[0], argComparer); Assert.Equal(optTable.MakeArg(4, "--aa", 1, "2"), al[1], argComparer); Assert.Equal(optTable.MakeArg(1, "-aaaa", 2, "a"), al[2], argComparer); Assert.Equal(optTable.MakeArg(3, "-a", 3, "4"), al[3], argComparer); Assert.Equal(optTable.MakeArg(2, "-aaa", 4, "5"), al[4], argComparer); }
public void ParseFlagMultiple() { OptTable optTable = new OptTableBuilder() .AddFlag(1, "-", "aaaa") .AddFlag(2, new[] { "-", "--" }, "aaa") .AddFlag(3, "-", "a") .AddFlag(4, "--", "aa") .CreateTable(); var args = new[] { "--aaa", "--aa", "-aaaa", "-a", "-aaa" }; IArgumentList al = optTable.ParseArgs(args, out MissingArgs missing); Assert.Equal(0, missing.ArgIndex); Assert.Equal(0, missing.ArgCount); Assert.Equal(5, al.Count); Assert.Equal(optTable.MakeArg(2, "--aaa", 0), al[0], argComparer); Assert.Equal(optTable.MakeArg(4, "--aa", 1), al[1], argComparer); Assert.Equal(optTable.MakeArg(1, "-aaaa", 2), al[2], argComparer); Assert.Equal(optTable.MakeArg(3, "-a", 3), al[3], argComparer); Assert.Equal(optTable.MakeArg(2, "-aaa", 4), al[4], argComparer); }