NuDeploy.CommandLine.Commands.Console.HelpCommand.Execute C# (CSharp) Method

Execute() public method

public Execute ( ) : bool
return bool
        public bool Execute()
        {
            string commandName = this.Arguments.Values.FirstOrDefault();
            if (string.IsNullOrWhiteSpace(commandName) == false)
            {
                ICommand matchedCommand =
                    this.AvailableCommands.FirstOrDefault(
                        c =>
                        c.Attributes.CommandName.Equals(commandName, StringComparison.OrdinalIgnoreCase)
                        || c.Attributes.AlternativeCommandNames.Any(a => a.Equals(commandName, StringComparison.OrdinalIgnoreCase)));

                if (matchedCommand != null)
                {
                    this.helpProvider.ShowHelp(matchedCommand);
                    return true;
                }
            }

            this.helpProvider.ShowHelpOverview(this.AvailableCommands);
            return true;
        }

Usage Example

Example #1
0
        public void Execute_NoCommandNameArgumentSupplied_GeneralHelpIsCalled()
        {
            // Arrange
            var helpProvider = new Mock<IHelpProvider>();

            var helpCommand = new HelpCommand(helpProvider.Object);

            // Act
            helpCommand.Execute();

            // Assert
            helpProvider.Verify(h => h.ShowHelpOverview(It.IsAny<IEnumerable<ICommand>>()), Times.Once());
        }