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); }
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); }