public void ACustomConverterCanBeSpecifiedAndUsed()
        {
            CommandLineInterpreterConfiguration.AddCustomConverter(s => s.Length > 1 ? new CustomParamType(s.First(), s.Substring(1)) : null);
            var config = new CommandLineInterpreterConfiguration();
            config
                .Parameters(() => new CustomParamCommand())
                .Description("Description of the whole program.")
                .Positional<CustomParamType>("pos", (command, s) => { })
                    .Description("A positional parameter.");

            CommandDescriber.Describe(config, _console, _applicationName, CommandExecutionMode.CommandLine);
            var description = _consoleOutInterface.GetBuffer();
            Console.WriteLine(description);
            Approvals.Verify(description);
        }
        public void DefaultCommandHelpIsFormatted()
        {
            var config = new CommandLineInterpreterConfiguration();
            config
                .Parameters(() => new TestCommand())
                .Description("Description of the whole program.")
                .Positional<string>("pos", (command, s) => { })
                .Description("A positional parameter.");

            config.DefaultCommand.Name = "shouldnotbedisplayed";

            _console.WriteLine(RulerFormatter.MakeRuler(_console.WindowWidth));
            CommandDescriber.Describe(config, _console, "Test", CommandExecutionMode.CommandLine);
            var buffer = _consoleOutInterface.GetBuffer();
            Console.WriteLine(buffer);
            Approvals.Verify(buffer);
        }
        private static CommandLineInterpreterConfiguration ConfigureCommandLine()
        {
            var config = new CommandLineInterpreterConfiguration(CommandLineParserConventions.MsDosConventions);
            config.Parameters<Options>("SetCsprojVer")
                .Description(@"SetCsprojVer is a simple tool to update the version number in AssemblyInfo.cs files in a project tree.

            A project folder should be supplied, and this will scanned for AssemblyInfo.cs files. Each file found will be edited to select the appropriate version number.")
                .Positional("projectfolder")
                    .Description("The base folder for the scan.")
                .Option("AV", o => o.AssemblyVersion)
                    .Description("Set the AssemblyVersion to the specified value. This must be a 4 part version number, " +
                                 "if specified. e.g. /AV:1.0.0.0")
                .Option("FV", o => o.AssemblyFileVersion)
                    .Description("Set the AssemblyFileVersion to the specified value. This must be a 4 part version number, " +
                                 "if specified. e.g. /FV:1.0.0.0")
                .Option("IV", o => o.AssemblyInformationalVersion)
                    .Description("Set the AssemblyInformationalVersion to the specified value. e.g. \"/IV:1.0 beta\"")
                .Option<string, string>("inc", (o, s, p) => o.SetIncTarget(s, p))
                    .Description("Increment a component of either the AssemblyVersion (AV) or the AssemblyFileVersion (FV). " +
                                 "The component incremented is either the build (b) or revision (r). " + Environment.NewLine +
                                 "Specify [AV|FV],[B|R], e.g. /inc:av,b")
                    .Alias("I")
                .Option("env", o => o.EnvironmentVariableName)
                    .Description("Set an environment variable to the version number set. " +
                                 "This may not be specified if more than one of the /AV, /FV, or /IV options are specified. " +
                                 "If the /inc option is specified, the environment variable will receive the result of the increment. " +
                                 "In a dry run, the environment variable will still be set. e.g. /env:variable")
                    .Alias("e")
                .Option("Report")
                    .Description("Report the version numbers defined in the AssemblyInfo.cs files found in the project tree. " +
                                 "This option may not be combined with any others.")
                    .Alias("R")
                .Option("Get")
                    .Description("Retrieve a the first version number defined in the AssemblyInfo.cs files for either the " +
                                 "AssemblyVersion (AV), the AssemblyFileVersion (FV) or the AssemblyInformationalVersion (IV). " +
                                 "This option may not be combined with options that change a version number, or the report option. " +
                                 "If the Env option is also used, the discovered version number will be placed in an environment variable. " +
                                 "e.g. /get:av")
                    .Alias("G")
                .Option("dryrun")
                    .Alias("D")
                    .Description("Perform a dry run. No updates will be made. e.g. /dryrun or /D")
                .Validator(Options.Validator);
            return config;
        }
Exemplo n.º 4
0
 public void SetUp()
 {
     _config = new CommandLineInterpreterConfiguration();
     _command = _config.Parameters(() => new CommandParams())
         .Positional<string>("pos1", (c, s) => c.Pos1 = s)
         .Positional<int>("pos2", (c, i) => c.Pos2 = i)
         .Option<string, int>("opt1", (c, s, i) =>
         {
             c.Opt1String = s;
             c.Opt1Int = i;
         })
             .Alias("1")
             .Alias("one")
         .Option("opt2", (c, b) => c.Opt2 = b)
             .Alias("2")
             .Alias("two")
         .Option<string>("opt3", (c, s) => c.Opt3 = s)
             .Alias("3")
             .Alias("three");
     _parserResult = new ParserResult(_command, "commandName");
 }
 private void Configure(CommandLineInterpreterConfiguration config)
 {
     config.Parameters<Data>()
         .Description("Do something to a file.")
         .Positional("filename")
         .Description("The name of the file.")
         .Option("delete")
         .Alias("D")
         .Description("Delete the file after processing.")
         .Option("archive")
         .Alias("A")
         .Description("Archive after processing");
 }
 public void ShortCircuitOptionOnAPositionalThrows()
 {
     var config = new CommandLineInterpreterConfiguration();
     config
         .Parameters(() => new TestCommand())
         .Description("Description of the whole program.")
         .Positional<string>("pos", (command, s) => { })
             .Description("A positional parameter.")
             .ShortCircuitOption();
 }
 public void PositionalWithDefaultValueIsOptional()
 {
     var config = new CommandLineInterpreterConfiguration();
     config.Parameters(() => new MultiCaseCommand())
         .Positional("AOne").DefaultValue("X");
     Assert.That(config.DefaultCommand.Positionals[0].IsOptional, Is.True);
 }
 public void PositionalDefinedOnlyByNameMatchesPropertyAutomatically()
 {
     var config = new CommandLineInterpreterConfiguration();
     config.Parameters(() => new TestCommand())
         .Positional("IntProp");
     var thePositional = config.DefaultCommand.Positionals[0];
     var thePositionalParameterType = thePositional.GetType().GetGenericArguments()[1];
     Assert.That(thePositionalParameterType, Is.EqualTo(typeof(int)));
 }
 public void PositionalDefinedByNamePrefersCorrectCaseProperty()
 {
     var config = new CommandLineInterpreterConfiguration();
     config.Parameters(() => new MultiCaseCommand())
         .Positional("AOne");
     var thePositional = config.DefaultCommand.Positionals[0];
     var thePositionalParameterType = thePositional.GetType().GetGenericArguments()[1];
     Assert.That(thePositionalParameterType, Is.EqualTo(typeof(string)));
 }
 public void DefaultValueIsStoredOnOptionalParameter()
 {
     var config = new CommandLineInterpreterConfiguration();
     config.Parameters(() => new MultiCaseCommand())
         .Positional("AOne").DefaultValue("X");
     Assert.That(config.DefaultCommand.Positionals[0].DefaultValue, Is.EqualTo("X"));
 }
 public void DefaultValueIsInvalidOnAnOption()
 {
     var config = new CommandLineInterpreterConfiguration();
     config.Parameters(() => new MultiCaseCommand())
         .Option("AOne").DefaultValue("true");
 }
        public void DefaultCommandHelpIsFormatted()
        {
            var config = new CommandLineInterpreterConfiguration();
            config
                .Parameters(() => new TestCommand())
                .Description("Description of the whole program.")
                .Positional<string>("pos", (command, s) => { })
                    .Description("A positional parameter.");

            CommandDescriber.Describe(config, _console, _applicationName, CommandExecutionMode.CommandLine);
            var description = _consoleOutInterface.GetBuffer();
            Console.WriteLine(description);
            Approvals.Verify(description);
        }
 public void ConfiguringDefaultCommandTwiceThrows()
 {
     var config = new CommandLineInterpreterConfiguration();
     config
         .Parameters(() => "test")
         .Positional<string>("opt", (s, x) => { });
     config
         .Parameters(() => "test again")
         .Positional<int>("opt2", (s, x) => { });
 }
 public void ARepeatingPositionalCanBeSpecified()
 {
     var config = new CommandLineInterpreterConfiguration();
     config
         .Parameters(() => new TestCommand())
         .Description("Description of the whole program.")
         .Positional<string>("pos", (command, s) => { })
             .Description("A positional parameter.")
             .AllowMultiple();
 }