public void NoCommandTypesDisplayOnlyGeneralInformation()
            {
                var console       = new FakeConsole();
                var parserOptions = new ParserOptions {
                    Logo            = "Logo Unit Test",
                    CommandLineName = "tool.exe"
                };
                var parserOptionsAccessorMock = new Mock <IParserOptionsAccessor>();

                parserOptionsAccessorMock.SetupGet(_ => _.Current).Returns(parserOptions);
                var commandTypeProviderMock = new Mock <ICommandTypeProvider>();

                commandTypeProviderMock.Setup(_ => _.GetAllCommandTypes()).Returns(Enumerable.Empty <ICommandType>);
                var helpWriter = new DefaultHelpWriter(console, new[] { commandTypeProviderMock.Object }, parserOptionsAccessorMock.Object);
                var expected   = @"Logo Unit Test
Usage: tool.exe <command> [options] [args]
Type 'tool.exe help <command>' for help on a specific command.

Available commands:
No commands found.
";

                using (new LangageSwitcher("en-us"))
                {
                    helpWriter.WriteCommandListing();
                }
                var messages = console.Messages;

                Assert.Single(messages);
                Assert.IsType <FakeConsole.InformationMessage>(messages[0]);
                Assert.Equal(expected, messages[0].ToString(), ignoreLineEndingDifferences: true);
            }
Exemple #2
0
        /// <summary>
        /// Base class an Odin command.
        /// </summary>
        protected Command()
        {
            _conventions = new HyphenCaseConvention();
            _helpWriter  = new DefaultHelpWriter();

            _subCommands = new List <Command>();

            InitializeActions();

            this.DisplayHelpWhenArgsAreEmpty = true;
        }
        public void TwoCommandTypesDisplayOnlyGeneralInformationThenHelpForTheCommand()
        {
            var console       = new FakeConsole();
            var parserOptions = new ParserOptions {
                Logo            = "Logo Unit Test",
                CommandLineName = "tool.exe"
            };
            var parserOptionsAccessorMock = new Mock <IParserOptionsAccessor>();

            parserOptionsAccessorMock.SetupGet(_ => _.Current).Returns(parserOptions);
            var commandTypeProviderMock = new Mock <ICommandTypeProvider>();
            var commandMetadata1Mock    = new Mock <ICommandMetadata>();

            commandMetadata1Mock.SetupGet(_ => _.HideFromHelpListing).Returns(false);
            commandMetadata1Mock.SetupGet(_ => _.Name).Returns("build");
            commandMetadata1Mock.SetupGet(_ => _.Description).Returns("description for build command");
            var commandType1Mock = new Mock <ICommandType>();

            commandType1Mock.SetupGet(_ => _.Metadata).Returns(commandMetadata1Mock.Object);
            var commandMetadata2Mock = new Mock <ICommandMetadata>();

            commandMetadata2Mock.SetupGet(_ => _.HideFromHelpListing).Returns(false);
            commandMetadata2Mock.SetupGet(_ => _.Name).Returns("test");
            commandMetadata2Mock.SetupGet(_ => _.Description).Returns("description for test command");
            var commandType2Mock = new Mock <ICommandType>();

            commandType2Mock.SetupGet(_ => _.Metadata).Returns(commandMetadata2Mock.Object);
            commandTypeProviderMock.Setup(_ => _.GetAllCommandTypes()).Returns(new[] { commandType1Mock.Object, commandType2Mock.Object });
            var helpWriter = new DefaultHelpWriter(console, new[] { commandTypeProviderMock.Object }, parserOptionsAccessorMock.Object);
            var expected   = @"Logo Unit Test
Usage: tool.exe <command> [options] [args]
Type 'tool.exe help <command>' for help on a specific command.

Available commands:
 build   description for build command
 test    description for test command
";

            using (new LangageSwitcher("en-us"))
            {
                helpWriter.WriteCommandListing();
            }
            var messages = console.Messages;

            Assert.Single(messages);
            Assert.IsType <FakeConsole.InformationMessage>(messages[0]);
            Assert.Equal(expected, messages[0].ToString(), ignoreLineEndingDifferences: true);
        }
Exemple #4
0
            public void TestDictionaryProperty()
            {
                // Arrange
                var propertyInfo =
                    GetType().GetProperty(TypeHelpers.ExtractPropertyName(() => DictionaryProperty));
                var commandMetadata = new ClassBasedCommandMetadata(typeof(GetMultiValueIndicator));
                var commandOption   = ClassBasedCommandOptionMetadata.Create(propertyInfo, commandMetadata, new List <IConverter> {
                    new StringConverter(), new Int32Converter()
                }, new List <IPropertyOptionAlternateNameGenerator>());
                var expected = DefaultHelpWriter.DictionaryIndicator;

                // Act
                var actual = DefaultHelpWriter.GetMultiValueIndicator(commandOption);

                // Assert
                Assert.Equal(expected, actual);
            }
Exemple #5
0
        private int?Execute(CliContext context)
        {
            // Get input and command schema from context
            CommandInput  input         = context.Input;
            CommandSchema commandSchema = context.CommandSchema;

            // Help option
            if ((commandSchema.IsHelpOptionAvailable && input.IsHelpOptionSpecified) ||
                (commandSchema == StubDefaultCommand.Schema && !input.Parameters.Any() && !input.Options.Any()))
            {
                IHelpWriter helpTextWriter = new DefaultHelpWriter(context);
                helpTextWriter.Write(commandSchema, context.CommandDefaultValues);

                return(ExitCodes.Success);
            }

            return(null);
        }
        private static void PrintHelp(ICliContext context)
        {
            IHelpWriter helpTextWriter = new DefaultHelpWriter(context);

            helpTextWriter.Write();
        }