public static void Describe(CommandLineInterpreterConfiguration config, ConsoleAdapter console, string applicationName, CommandLineParserConventions conventions)
        {
            CommandDescriber.Describe(config, console, applicationName, CommandExecutionMode.CommandLine);

            var adorner = MakeAdorner(conventions);
            foreach (var baseCommandConfig in config.Commands)
            {
                console.WriteLine();
                console.WriteLine("Description of {0} command:", baseCommandConfig.Name);
                CommandDescriber.Describe(baseCommandConfig, console, CommandExecutionMode.CommandLine, adorner);
            }
        }
Exemplo n.º 2
0
        public void WriteLine_ShouldCallSystemConsoleWriteLineTest()
        {
            // arrange
            var consoleShim = Shim.Replace(() => System.Console.WriteLine(Is.A <string>()))
                              .With((string s) => shimResult.Add("shimmed: " + s));

            // act
            PoseContext.Isolate(() => sut.WriteLine("monkey"), consoleShim);

            // assert
            shimResult.Should().BeEquivalentTo("shimmed: monkey");
        }
Exemplo n.º 3
0
        internal virtual void Write(Int32 padding)
        {
            ConsoleAdapter.Write($"{String.Empty.PadLeft(padding)}{Name} => ");

            WriteResult();
            WriteDetails();

            ConsoleAdapter.WriteLine();
        }
        public void WriteLine_WriteLineNoParameters_WritesCarriageReturnToOutputStream()
        {
            using (StringWriter sw = new StringWriter())
            {
                //Arrange
                IConsoleAdapter aConsoleAdapter = new ConsoleAdapter();
                Console.SetOut(sw);

                //Act
                aConsoleAdapter.WriteLine();
                var expected = string.Format("{0}", Environment.NewLine);

                var result = sw.ToString();

                //Assert
                Assert.AreEqual <string>(expected, result);
            }
        }
        public void WriteLine_WritesLineToOutputStream_ExpectedOutput()
        {
            using (StringWriter sw = new StringWriter())
            {
                //Arrange
                IConsoleAdapter aConsoleAdapter = new ConsoleAdapter();
                Console.SetOut(sw);

                //Act
                aConsoleAdapter.WriteLine("Press any key to Continue!");
                var expected = string.Format("Press any key to Continue!{0}", Environment.NewLine);

                var result = sw.ToString();

                //Assert
                Assert.AreEqual <string>(expected, result);
            }
        }
        public void SetUp()
        {
            _posix = new CommandLineInterpreterConfiguration(CommandLineParserConventions.PosixConventions);
            _msDos = new CommandLineInterpreterConfiguration(CommandLineParserConventions.MsDosConventions);
            _msStd = new CommandLineInterpreterConfiguration(CommandLineParserConventions.MicrosoftStandard);
            Configure(_posix);
            Configure(_msDos);
            Configure(_msStd);

            _consoleOutInterface = new ConsoleInterfaceForTesting();
            _console = new ConsoleAdapter(_consoleOutInterface);
            _console.WriteLine(RulerFormatter.MakeRuler(40));
        }
        public void SetUp()
        {
            _config = new CommandLineInterpreterConfiguration();
            _config.Command("first", s => new TestCommand())
                .Description("Description of the first commmand.");
            _config
                .Command("second", s => new TestCommand())
                .Description("The second command is a command with a number of parameters.")
                .Positional<string>("dateofthing", (command, s) => { })
                    .Description("The date the thing should have.")
                .Positional<string>("numberofthing", (command, s) => { })
                    .Description("The number of things that should be.");
            _config
                .Command("third", s => new TestCommand())
                .Description("The third command has a number of options but no parameters.")
                .Option("on", (command, b) => { })
                    .Description("A simple option with no argument.")
                .Option<string, int>("fiddly", (command, s, n) => { })
                    .Alias("f")
                    .Description("An option with two arguments. The arguments need to be described in the text.");
            _config
                .Command("fourth", s => new TestCommand())
                .Description("The fourth command is really complicated with a number of parameters and also options. This is the sort of command that needs lots of text.")
                .Positional<string>("date", (command, s) => { })
                    .Description("The date the complicated nonsense should be forgotten.")
                .Positional<string>("crpyticnum", (command, s) => { })
                    .Description("The amount of nonsense the user needs to forget.")
                .Option("ignore", (command, b) => { })
                    .Description("Use this option to consign this command to history, where it belongs.")
                .Option<string, int>("more", (command, s, n) => { })
                    .Description("Even more.");

            _config
                .Command("desc", s => new TestCommand())
                .Description(
                    @"Descriptions can contain embedded line breaks -->
            <-- like that one. These should be respected in the formatting. (This is meant to look a bit odd. Also, you should be aware that the deliberate line break is the only one in this text.)")
                .Positional<string>("pos", (command, s) => { })
                    .Description(@"A parameter with
            a line break.")
                .Option("lb", (command, b) => { })
                    .Description("Another\nbreak.");

            _config
                .Command("exp", s => new TestCommand())
                .Description(@"Command with a positional and options configured using a Linq Expression, not a lambda.")
                .Positional("pos", command => command.StringProp)
                    .Description(@"A positional configured with an expression.")
                .Option("B", command => command.BoolProp)
                    .Description("A boolean option configured with an expression.")
                .Option("I", command => command.IntProp)
                    .Description("A boolean option configured with an expression.");

            _customParser = new CustomParser();

            _consoleOutInterface = new ConsoleInterfaceForTesting();
            _console = new ConsoleAdapter(_consoleOutInterface);

            _console.WriteLine(RulerFormatter.MakeRuler(40));
        }