NuDeploy.CommandLine.Commands.HelpProvider.ShowHelp C# (CSharp) Method

ShowHelp() public method

public ShowHelp ( ICommand command ) : void
command ICommand
return void
        public void ShowHelp(ICommand command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            // command name
            string commandNameText = this.applicationInformation.NameOfExecutable + " " + command.Attributes.CommandName;
            this.userInterface.WriteLine(commandNameText);

            this.userInterface.WriteLine(string.Empty);

            // command description
            this.userInterface.WriteLine(command.Attributes.Description);

            this.userInterface.WriteLine(string.Empty);

            // command usage
            string usageLabel = Resources.HelpCommand.UsageLabel + ":";
            string usageText = this.applicationInformation.NameOfExecutable + " " + command.Attributes.Usage;
            this.userInterface.ShowLabelValuePair(usageLabel, usageText, distanceBetweenLabelAndValue: 2);

            this.userInterface.WriteLine(string.Empty);

            // examples
            string examplesLabel = Resources.HelpCommand.ExamplesLabel + ":";
            this.userInterface.WriteLine(examplesLabel);

            foreach (KeyValuePair<string, string> pair in command.Attributes.Examples)
            {
                this.userInterface.WriteLine(string.Empty);

                string commandText = string.Format("> {0} {1}", this.applicationInformation.NameOfExecutable, pair.Key);
                string description = pair.Value;

                this.userInterface.ShowIndented(description, 3);

                this.userInterface.WriteLine(string.Empty);
                this.userInterface.ShowIndented(commandText, 6);
            }

            this.userInterface.WriteLine(string.Empty);

            // options
            if (command.Attributes.ArgumentDescriptions.Count > 0)
            {
                string optionsLabel = Resources.HelpCommand.OptionsLabel + ":";
                this.userInterface.WriteLine(optionsLabel);
                this.userInterface.WriteLine(string.Empty);

                var formattedOptions =
                    command.Attributes.ArgumentDescriptions.Select(pair => new KeyValuePair<string, string>("-" + pair.Key, pair.Value)).ToDictionary(
                        pair => pair.Key, pair => pair.Value);

                this.userInterface.ShowKeyValueStore(formattedOptions, 4, 3);

                this.userInterface.WriteLine(string.Empty);
            }
        }

Usage Example

        public void ShowHelp_Examples_AreWrittenToTheUserInterface()
        {
            // Arrange
            ICommand command = CommandTestUtilities.GetCommand("SomeCommand");

            var applicationInformation = new ApplicationInformation();

            var helpProvider = new HelpProvider(applicationInformation, this.loggingUserInterface.UserInterface);

            // Act
            helpProvider.ShowHelp(command);

            // Assert
            foreach (var example in command.Attributes.Examples)
            {
                Assert.IsTrue(this.loggingUserInterface.UserInterfaceOutput.Contains(example.Key));
                Assert.IsTrue(this.loggingUserInterface.UserInterfaceOutput.Contains(example.Value));
            }
        }
All Usage Examples Of NuDeploy.CommandLine.Commands.HelpProvider::ShowHelp