public void Option() { String[] args = new String[] { "-p" }; ICommandLine cl = parser.Parse(options, args); Assert.IsTrue(cl.HasOption("p"), "Confirm -p is set"); Assert.IsFalse(cl.HasOption("attr"), "Confirm -attr is not set"); Assert.IsTrue(!cl.Arguments.Any(), "Confirm all arguments recognized"); }
public void OptionWithArgument() { String[] args = new String[] { "-attr", "p" }; ICommandLine cl = parser.Parse(options, args); Assert.IsFalse(cl.HasOption("p"), "Confirm -p is set"); Assert.IsTrue(cl.HasOption("attr"), "Confirm -attr is set"); Assert.IsTrue(cl.GetOptionValue("attr").Value.Equals("p"), "Confirm arg of -attr"); Assert.IsTrue(!cl.Arguments.Any(), "Confirm all arguments recognized"); }
public void StopAtNonOptionLong() { String[] args = new String[] { "--zop==1", "-abtoast", "--b=bar" }; ICommandLine cl = parser.Parse(options, args, true); Assert.IsFalse(cl.HasOption("a"), "Confirm -a is not set"); Assert.IsFalse(cl.HasOption("b"), "Confirm -b is not set"); Assert.IsTrue(cl.Arguments.Count() == 3, "Confirm 3 extra args: " + cl.Arguments.Count()); }
public void DoubleDash() { String[] args = new String[] { "--copt", "--", "-b", "toast" }; ICommandLine cl = parser.Parse(options, args); Assert.IsTrue(cl.HasOption("c"), "Confirm -c is set"); Assert.IsTrue(!cl.HasOption("b"), "Confirm -b is not set"); Assert.IsTrue(cl.Arguments.Count() == 2, "Confirm 2 extra args: " + cl.Arguments.Count()); }
public void SimpleShort() { String[] args = new String[] { "-a", "-b", "toast", "foo", "bar" }; ICommandLine cl = parser.Parse(options, args); Assert.IsTrue(cl.HasOption("a"), "Confirm -a is set"); Assert.IsTrue(cl.HasOption("b"), "Confirm -b is set"); Assert.IsTrue(cl.GetOptionValue("b").Value.Equals("toast"), "Confirm arg of -b"); Assert.IsTrue(cl.Arguments.Count() == 2, "Confirm size of extra args"); }
public void SingleDash() { String[] args = new String[] { "--copt", "-b", "-", "-a", "-" }; ICommandLine cl = parser.Parse(options, args); Assert.IsTrue(cl.HasOption("a"), "Confirm -a is set"); Assert.IsTrue(cl.HasOption("b"), "Confirm -b is set"); Assert.IsTrue(cl.GetOptionValue("b").Value.Equals("-"), "Confirm arg of -b"); Assert.IsTrue(cl.Arguments.Count() == 1, "Confirm 1 extra arg: " + cl.Arguments.Count()); Assert.IsTrue(cl.Arguments.First().Equals("-"), "Confirm value of extra arg: " + cl.Arguments.First()); }
public void Ls() { Options options = new Options(); options.AddOption("a", "all", false, "do not hide entries starting with ."); options.AddOption("A", "almost-all", false, "do not list implied . and .."); options.AddOption("b", "escape", false, "print octal escapes for nongraphic characters"); options.AddOption(OptionBuilder.New().WithLongName("block-size") .WithDescription("use SIZE-byte blocks") .HasArgument() .WithArgumentName("SIZE") .Create()); options.AddOption("B", "ignore-backups", false, "do not list implied entried ending with ~"); options.AddOption("c", false, "with -lt: sort by, and show, ctime (time of last modification of file status information) with -l:show ctime and sort by name otherwise: sort by ctime"); options.AddOption("C", false, "list entries by columns"); String[] args = new String[] { "--block-size=10" }; // create the command line parser ICommandLineParser parser = new PosixParser(); ICommandLine line = parser.Parse(options, args); Assert.IsTrue(line.HasOption("block-size")); Assert.AreEqual("10", line.GetOptionValue("block-size").Value); }
private static void SetOptionsToMember(MemberInfo member, Options options, ICommandLine cmdLine) { var optionName = member.Name; var attrs = member.GetCustomAttributes(typeof(OptionAttribute), false); if (attrs.Length > 0) { var attr = (OptionAttribute)attrs[0]; optionName = attr.Name; if (String.IsNullOrEmpty(optionName)) { optionName = attr.LongName; } if (String.IsNullOrEmpty(optionName)) { optionName = member.Name; } } if (cmdLine.HasOption(optionName)) { var value = cmdLine.GetOptionValue(optionName); } }
public void MultipleWithLong() { String[] args = new String[] { "--copt", "foobar", "--bfile", "toast" }; ICommandLine cl = parser.Parse(options, args, true); Assert.IsTrue(cl.HasOption("c"), "Confirm -c is set"); Assert.IsTrue(cl.Arguments.Count() == 3, "Confirm 3 extra args: " + cl.Arguments.Count()); cl = parser.Parse(options, cl.Arguments.ToArray()); Assert.IsTrue(!cl.HasOption("c"), "Confirm -c is not set"); Assert.IsTrue(cl.HasOption("b"), "Confirm -b is set"); Assert.IsTrue(cl.GetOptionValue("b").Value.Equals("toast"), "Confirm arg of -b"); Assert.IsTrue(cl.Arguments.Count() == 1, "Confirm 1 extra arg: " + cl.Arguments.Count()); Assert.IsTrue(cl.Arguments.First().Equals("foobar"), "Confirm value of extra arg: " + cl.Arguments.First()); }
public void StopAtExpectedArg() { String[] args = new String[] { "-b", "foo" }; ICommandLine cl = parser.Parse(options, args, true); Assert.IsTrue(cl.HasOption('b'), "Confirm -b is set"); Assert.AreEqual("foo", cl.GetOptionValue('b').Value, "Confirm -b is set"); Assert.IsTrue(!cl.Arguments.Any(), "Confirm no extra args: " + cl.Arguments.Count()); }
public void StopAtUnexpectedArg() { String[] args = new String[] { "-c", "foober", "-b", "toast" }; ICommandLine cl = parser.Parse(options, args, true); Assert.IsTrue(cl.HasOption("c"), "Confirm -c is set"); Assert.IsTrue(cl.Arguments.Count() == 3, "Confirm 3 extra args: " + cl.Arguments.Count()); }
public void Ant() { Options options = new Options(); options.AddOption("help", false, "print this message"); options.AddOption("projecthelp", false, "print project help information"); options.AddOption("version", false, "print the version information and exit"); options.AddOption("quiet", false, "be extra quiet"); options.AddOption("verbose", false, "be extra verbose"); options.AddOption("debug", false, "print debug information"); options.AddOption("logfile", true, "use given file for log"); options.AddOption("logger", true, "the class which is to perform the logging"); options.AddOption("listener", true, "add an instance of a class as a project listener"); options.AddOption("buildfile", true, "use given buildfile"); options.AddOption(OptionBuilder.New().WithDescription("use value for given property") .HasArguments() .WithValueSeparator() .Create('D')); //, null, true, , false, true ); options.AddOption("find", true, "search for buildfile towards the root of the filesystem and use it"); String[] args = new String[] { "-buildfile", "mybuild.xml", "-Dproperty=value", "-Dproperty1=value1", "-projecthelp" }; // use the GNU parser ICommandLineParser parser = new GnuParser(); ICommandLine line = parser.Parse(options, args); // check multiple values String[] opts = line.GetOptionValues("D"); Assert.AreEqual("property", opts[0]); Assert.AreEqual("value", opts[1]); Assert.AreEqual("property1", opts[2]); Assert.AreEqual("value1", opts[3]); // check single value Assert.AreEqual("mybuild.xml", line.GetOptionValue("buildfile").Value); // check option Assert.IsTrue(line.HasOption("projecthelp")); }
public void Groovy() { Options options = new Options(); options.AddOption( OptionBuilder.New().WithLongName("define"). WithDescription("define a system property"). HasArgument(true). WithArgumentName("name=value"). Create('D')); options.AddOption( OptionBuilder.New().HasArgument(false) .WithDescription("usage information") .WithLongName("help") .Create('h')); options.AddOption( OptionBuilder.New().HasArgument(false) .WithDescription("debug mode will print out full stack traces") .WithLongName("debug") .Create('d')); options.AddOption( OptionBuilder.New().HasArgument(false) .WithDescription("display the Groovy and JVM versions") .WithLongName("version") .Create('v')); options.AddOption( OptionBuilder.New().WithArgumentName("charset") .HasArgument() .WithDescription("specify the encoding of the files") .WithLongName("encoding") .Create('c')); options.AddOption( OptionBuilder.New().WithArgumentName("script") .HasArgument() .WithDescription("specify a command line script") .Create('e')); options.AddOption( OptionBuilder.New().WithArgumentName("extension") .HasOptionalArg() .WithDescription("modify files in place; create backup if extension is given (e.g. \'.bak\')") .Create('i')); options.AddOption( OptionBuilder.New().HasArgument(false) .WithDescription("process files line by line using implicit 'line' variable") .Create('n')); options.AddOption( OptionBuilder.New().HasArgument(false) .WithDescription("process files line by line and print result (see also -n)") .Create('p')); options.AddOption( OptionBuilder.New().WithArgumentName("port") .HasOptionalArg() .WithDescription("listen on a port and process inbound lines") .Create('l')); options.AddOption( OptionBuilder.New().WithArgumentName("splitPattern") .HasOptionalArg() .WithDescription("split lines using splitPattern (default '\\s') using implicit 'split' variable") .WithLongName("autosplit") .Create('a')); Parser parser = new PosixParser(); ICommandLine line = parser.Parse(options, new String[] { "-e", "println 'hello'" }, true); Assert.IsTrue(line.HasOption('e')); Assert.AreEqual("println 'hello'", line.GetOptionValue('e').Value); }
void Parse() { AllowDuplicateResources = cmd.Modifier("allowduplicateresources"); foreach (string dupType in cmd.Options("allowdup")) { AllowDuplicateType(dupType); } AllowMultipleAssemblyLevelAttributes = cmd.Modifier("allowmultiple"); AllowWildCards = cmd.Modifier("wildcards"); AllowZeroPeKind = cmd.Modifier("zeropekind"); Parallel = cmd.Modifier("parallel"); PauseBeforeExit = cmd.Modifier("pause"); AttributeFile = cmd.Option("attr"); Closed = cmd.Modifier("closed"); CopyAttributes = cmd.Modifier("copyattrs"); DebugInfo = !cmd.Modifier("ndebug"); DelaySign = cmd.Modifier("delaysign"); UsePrimaryAssemblyName = cmd.Modifier("useprimaryassemblyname"); cmd.Option("align"); // not supported, just prevent interpreting this as file... Internalize = cmd.HasOption("internalize"); if (Internalize) { // this file shall contain one regex per line to compare agains FullName of types NOT to internalize ExcludeFile = cmd.Option("internalize"); } RenameInternalized = cmd.Modifier("renameinternalized"); KeyFile = cmd.Option("keyfile"); KeyContainer = cmd.Option("keycontainer"); Log = cmd.HasOption("log"); if (Log) { LogFile = cmd.Option("log"); } OutputFile = cmd.Option("out"); PublicKeyTokens = cmd.Modifier("usefullpublickeyforreferences"); var targetKind = cmd.Option("target"); if (string.IsNullOrEmpty(targetKind)) { targetKind = cmd.Option("t"); } if (!string.IsNullOrEmpty(targetKind)) { switch (targetKind) { case ("library"): TargetKind = ILRepack.Kind.Dll; break; case ("exe"): TargetKind = ILRepack.Kind.Exe; break; case ("winexe"): TargetKind = ILRepack.Kind.WinExe; break; default: throw new InvalidTargetKindException("Invalid target: \"" + targetKind + "\"."); } } // TargetPlatformDirectory -> how does cecil handle that? var targetPlatform = cmd.Option("targetplatform"); if (targetPlatform != null) { int dirIndex = targetPlatform.IndexOf(','); if (dirIndex != -1) { TargetPlatformDirectory = targetPlatform.Substring(dirIndex + 1); TargetPlatformVersion = targetPlatform.Substring(0, dirIndex); } else { TargetPlatformVersion = targetPlatform; } } if (cmd.Modifier("v2")) { TargetPlatformVersion = "v2"; } if (cmd.Modifier("v4")) { TargetPlatformVersion = "v4"; } UnionMerge = cmd.Modifier("union"); var version = cmd.Option("ver"); if (!string.IsNullOrEmpty(version)) { Version = new Version(version); } XmlDocumentation = cmd.Modifier("xmldocs"); NoRepackRes = cmd.Modifier("norepackres"); KeepOtherVersionReferences = cmd.Modifier("keepotherversionreferences"); SearchDirectories = cmd.Options("lib"); // private cmdline-Options: LogVerbose = cmd.Modifier("verbose"); LineIndexation = cmd.Modifier("index"); if (cmd.HasOption("repackdrop")) { RepackDropAttribute = cmd.Option("repackdrop"); if (String.IsNullOrWhiteSpace(RepackDropAttribute)) { RepackDropAttribute = "RepackDropAttribute"; } } // everything that doesn't start with a '/' must be a file to merge (verify when loading the files) InputAssemblies = cmd.OtherAguments; }
private static void SetOptionsToMember(MemberInfo member, Options options, ICommandLine cmdLine) { var optionName = member.Name; var attrs = member.GetCustomAttributes(typeof (OptionAttribute), false); if (attrs.Length > 0) { var attr = (OptionAttribute) attrs[0]; optionName = attr.Name; if (String.IsNullOrEmpty(optionName)) optionName = attr.LongName; if (String.IsNullOrEmpty(optionName)) optionName = member.Name; } if (cmdLine.HasOption(optionName)) { var value = cmdLine.GetOptionValue(optionName); } }
public static bool HasOption(this ICommandLine commandLine, char opt) { return(commandLine.HasOption(opt.ToString(CultureInfo.InvariantCulture))); }