Пример #1
0
        public string FormatSummary(ICommandHelp commandHelp)
        {
            var result = new StringBuilder();

            AddLines(result, commandHelp.Description);
            return(string.Format("* [`crane {0}`]({0}.md)  {2}{1}{2}", commandHelp.CommandName, result, Environment.NewLine));
        }
Пример #2
0
        private string FormatDescription(ICommandHelp commandHelp)
        {
            var result = new StringBuilder();

            AddLines(result, commandHelp.Description);

            return(result.ToString());
        }
Пример #3
0
        public void object_instantiation(ICommandHelp commandHelp)
        {
            "When I create an instance of command help"
            ._(() => commandHelp = new CommandHelp("init", "Crane.Core.Commands.Init", string.Empty, new List <CommandExample>()));

            "Then it should create the command type based on the supplied full name"
            ._(() => commandHelp.CommandType.FullName.Should().Be(typeof(Init).FullName));
        }
Пример #4
0
        private string FormatUsage(ICommandHelp commandHelp)
        {
            var requiredArgs = new StringBuilder();

            _typeInfoParser.GetArguments(commandHelp.CommandType)
            .Where(item => item.Required)
            .ForEach(item => requiredArgs.AppendFormat("<{0}>", item.Name.PascalCaseToWords().ToLower()));

            return(string.Format("`usage: crane {0} {1}`", commandHelp.CommandName, requiredArgs));
        }
Пример #5
0
        public string Format(ICommandHelp commandHelp)
        {
            var result = new StringBuilder();

            result.AppendLine(FormatUsage(commandHelp));

            result.AppendLine();
            result.AppendLine(FormatDescription(commandHelp));

            if (commandHelp.Examples.Any())
            {
                result.Append(FormatExamples(commandHelp.Examples));
                result.AppendLine();
            }

            return(result.ToString());
        }
        public void formatting_help_command_with_console_formatter(IHelpFormatter formatter, ICommandHelp commandHelp, string result)
        {
            "Given I have a console formatter"
            ._(() => formatter = ServiceLocator.Resolve <ConsoleHelpFormatter>());

            "And I have a help command"
            ._(() => commandHelp = new CommandHelp("init", "Crane.Core.Commands.Init", "Initializes a new project with foo and bar.", new[] { new CommandExample {
                                                                                                                                                  Value = "Example 1"
                                                                                                                                              } }));

            "When I format the command"
            ._(() => result = formatter.Format(commandHelp));

            "It should display the usage statement on the first line"
            ._(() => result.Line(0).Should().Be("usage: crane init <project name>"));

            "It should display the description statement on the 3rd line"
            ._(() => result.Line(2).Should().Be("Initializes a new project with foo and bar."));

            "It should display the example"
            ._(() => result.Line(4).Should().Be("Example 1"));

            "It should display for information url"
            ._(() => result.Line(6).Should().Contain("For more information, visit"));
        }
Пример #7
0
 public string FormatSummary(ICommandHelp commandHelp)
 {
     return(string.Empty);
 }
Пример #8
0
        public void formatting_help_command_with_console_formatter(IHelpFormatter formatter, ICommandHelp commandHelp, string result)
        {
            "Given I have a markdown formatter"
            ._(() => formatter = ServiceLocator.Resolve <MarkdownHelpFormatter>());

            "And I have a help command"
            ._(() => commandHelp = new CommandHelp("init", "Crane.Core.Commands.Init",
                                                   "Initializes a new project with foo and bar.",
                                                   new[] { new CommandExample {
                                                               Value = "Example 1\n<code>usage</code>\n<code>\nvar x = 1;\nvar y=2;\n</code>"
                                                           } }));

            "When I format the command"
            ._(() => result = formatter.Format(commandHelp));

            "Then it should display the usage statement on the first line"
            ._(() => result.Line(0).Should().Be("`usage: crane init <project name>`"));

            "And it should display the description statement on the 3rd line"
            ._(() => result.Line(2).Should().Be("Initializes a new project with foo and bar."));

            "And it should display the first line of an example as a title"
            ._(() => result.Lines().First(item => item.Contains("Example"))
               .Should().StartWith("**")
               .And.EndWith("**  "));

            "And it should display any code element values that start and begin on the same line as markdown code blocks using single back ticks"
            ._(() => result.Should().Contain("`usage`"));

            "And it should display any multiline code blocks as markdown code blocks"
            ._(
                () =>
                result.Should().Contain(string.Format("```{0}var x = 1;{0}var y=2;{0}```", Environment.NewLine)));
        }
        public void can_retrieve_command_help_specifying_a_commands_short_name(CommandHelpCollection help, ICraneCommand command, ICommandHelp result)
        {
            "Given I have a help collection"
            ._(() => help = new CommandHelpCollection(new Dictionary <string, ICommandHelp>
            {
                { "init", new CommandHelp("init", "Crane.Core.Commands.Init", "Initializes things", null) },
                { "help", new CommandHelp("help", "Crane.Core.Commands.Help", "Helps things", null) },
            }));

            "When I retrieve the command help using a short name"
            ._(() => result = help.Get("help"));

            "Then it should retrieve the command help associated with that type"
            ._(() => result.CommandName.Should().Be("help"));
        }