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);
}
}