Example #1
0
 public override string Description()
 {
     return(command.Description());
 }
Example #2
0
    private HelpDetails CreateHelpForCommand(ICommand command)
    {
      var type = command.GetType();

      var details = new HelpDetails
      {
        Description = command.Description(),
      };

      var usage = new StringBuilder();

      var commandAttr = CommandInspector.GetCommandAttribute(type);
      if (commandAttr != null)
        usage.Append(commandAttr.Binding);

      var properties = type.GetProperties();

      foreach (var prop in properties)
      {
        usage.Append(" ");

        var isOptionalProperty = CommandInspector.GetOptionalParameter(prop) != null;
        var descriptionAttribute = CommandInspector.GetDescriptionAttribute(prop);

        var flagParameterAttribute = CommandInspector.GetFlagParameter(prop);
        if (flagParameterAttribute != null)
        {
          FormatParameterForUsage(usage, "-" + flagParameterAttribute.Name, isOptionalProperty);
          AddParameterToHelp(details, "-" + flagParameterAttribute.Name, descriptionAttribute, isOptionalProperty);
        }

        var namedParameterAttribute = CommandInspector.GetNamedParameter(prop);
        if (namedParameterAttribute != null)
        {
          FormatParameterForUsage(usage, "-" + namedParameterAttribute.Name + " " + namedParameterAttribute.HelpValuePlaceholder, isOptionalProperty);
          AddParameterToHelp(details, "-" + namedParameterAttribute.Name, descriptionAttribute, isOptionalProperty);
        }

        var numberedParameterAttribute = CommandInspector.GetNumberedParameter(prop);
        if (numberedParameterAttribute != null)
        {
          FormatParameterForUsage(usage, numberedParameterAttribute.HelpValuePlaceholder, isOptionalProperty);
          AddParameterToHelp(details, numberedParameterAttribute.HelpValuePlaceholder, descriptionAttribute, isOptionalProperty);
        }

        var listParameterAttribute = CommandInspector.GetListParameter(prop);
        if (listParameterAttribute != null)
        {
          FormatParameterForUsage(usage, listParameterAttribute.HelpValuePlaceholder, isOptionalProperty);
          AddParameterToHelp(details, listParameterAttribute.HelpValuePlaceholder, descriptionAttribute, isOptionalProperty);
        }
      }

      details.Usage = usage.ToString();

      return details;
    }