HelpGenerator

public protocol HelpGenerator

Protocol that defines the help generation logic. This protocol has an extension that implements all the methods required. You can choose to override helpMessage to completely costumize the help message to print. Alternatively, override one of the sections only to alter that section.

When the help is about to be printed, a CommandHelp is generated from the current Command. a HelpGenerator is created and passed this CommandHelp. the HelpGenerator is used to print the help message string


The help has this format

Usage:
  command [flags]
  command [command]

Aliases:
  alias1, alias2

Examples:
  the command usage example

Available Commands:
  sub_command1  subcommand description
  sub_command2  subcommand description

Flags:
  -f, --flag         flag1 description
      --user string  flag2 description

Use "command [command] --help" for more information about a command.
  • Command Help instance

    Declaration

    Swift

    var commandHelp: CommandHelp
  • Initialize with a command help

    Declaration

    Swift

    init(commandHelp: CommandHelp)
  • init(command:) Default implementation

    Initialize with a command

    Default Implementation

    Declaration

    Swift

    init(command: Command)
  • helpMessage Default implementation

    Return the full help message This help message will be printed when passing -h or --help to the command Override this method when you need to costumize the full message returned to consol If you need to only costumize part of the help, override one or more of the section strings


    Examples:

    var helpMessage: String {
      return "the help"
    }
    

    The help returned

    the help
    

    Default Implementation

    Undocumented

    Declaration

    Swift

    var helpMessage: String
  • errorHelpMessage Default implementation

    Return the message to be printed after printing the error occured This message will be printed after the specific error occured Override this method when you need to costumize the full error message returned to consol If you need to only costumize part of the help, override one or more of the section strings


    Examples:

    var errorHelpMessage: String {
      return "the help"
    }
    

    The help returned

    Some error occured
    the help
    

    Default Implementation

    Undocumented

    Declaration

    Swift

    var errorHelpMessage: String
  • deprecationSection Default implementation

    Returns the deprecation for this command When this is called, the help generator must return a message that uses the command.deprecatedStatus message This method will only be called if Guaka is about to execute this specific command. Returning nil ignores this section from the help message.


    Examples:

    var deprecationSection: String? {
      return "this command is deprecated"
    }
    

    The help returned

    this command is deprecated
    Usage:
      command [flags]
      command [command]
    
    Aliases:
      alias1, alias2
    
    Examples:
      the command usage example
    
    Available Commands:
      sub_command1  subcommand description
      sub_command2  subcommand description
    
    Flags:
      -f, --flag         flag1 description
          --user string  flag2 description
    
    Use "command [command] --help" for more information about a command.
    

    Default Implementation

    Undocumented

    Declaration

    Swift

    var deprecationSection: String?
  • commandDescriptionSection Default implementation

    Return command description section to be printed for when the command help is printed. Returning nil ignores this section from the help message.


    Examples:

    var commandDescriptionSection: String? {
      return "this is the command"
    }
    

    The help returned

    this is the command
    Usage:
      command [flags]
      command [command]
    
    Aliases:
      alias1, alias2
    
    Examples:
      the command usage example
    
    Available Commands:
      sub_command1  subcommand description
      sub_command2  subcommand description
    
    Flags:
      -f, --flag         flag1 description
          --user string  flag2 description
    
    Use "command [command] --help" for more information about a command.
    

    Default Implementation

    Undocumented

    Declaration

    Swift

    var commandDescriptionSection: String?
  • usageSection Default implementation

    Return the usage secion to be printed for when the command help is printed. Returning nil ignores this section from the help message.


    Examples:

    var usageSection: String? {
      return "use as"
    }
    

    The help returned

    use as
    
    Aliases:
      alias1, alias2
    
    Examples:
      the command usage example
    
    Available Commands:
      sub_command1  subcommand description
      sub_command2  subcommand description
    
    Flags:
      -f, --flag         flag1 description
          --user string  flag2 description
    
    Use "command [command] --help" for more information about a command.
    

    Default Implementation

    Undocumented

    Declaration

    Swift

    var usageSection: String?
  • aliasesSection Default implementation

    Return the aliases section to be printed for when the command help is printed. Returning nil ignores this section from the help message.


    Examples:

    var aliasesSection: String? {
      return "my aliases are 1, 2"
    }
    

    The help returned

    Usage:
      command [flags]
      command [command]
    
    my aliases are 1, 2
    
    Examples:
      the command usage example
    
    Available Commands:
      sub_command1  subcommand description
      sub_command2  subcommand description
    
    Flags:
      -f, --flag         flag1 description
          --user string  flag2 description
    
    Use "command [command] --help" for more information about a command.
    

    Default Implementation

    Undocumented

    Declaration

    Swift

    var aliasesSection: String?
  • exampleSection Default implementation

    Return the example section to be printed for when the command help is printed. Returning nil ignores this section from the help message.


    Examples:

    var exampleSection: String? {
      return "some examples"
    }
    

    The help returned

    Usage:
      command [flags]
      command [command]
    
    Aliases:
      alias1, alias2
    
    some examples
    
    Available Commands:
      sub_command1  subcommand description
      sub_command2  subcommand description
    
    Flags:
      -f, --flag         flag1 description
          --user string  flag2 description
    
    Use "command [command] --help" for more information about a command.
    

    Default Implementation

    Undocumented

    Declaration

    Swift

    var exampleSection: String?
  • subCommandsSection Default implementation

    Return the subcommands section to be printed for when the command help is printed. Returning nil ignores this section from the help message.


    Examples:

    var subCommandsSection: String? {
      return "Some sub commands" //should iterate the commands yourself
    }
    

    The help returned

    Usage:
      command [flags]
      command [command]
    
    Aliases:
      alias1, alias2
    
    Examples:
      the command usage example
    
    Some sub commands
    
    Flags:
      -f, --flag         flag1 description
          --user string  flag2 description
    
    Use "command [command] --help" for more information about a command.
    

    Default Implementation

    Undocumented

    Declaration

    Swift

    var subCommandsSection: String?
  • flagsSection Default implementation

    Return the flags description section to be printed for when the command help is printed. Returning nil ignores this section from the help message.


    Examples:

    var flagsSection: String? {
      return "the flags I have" // iterate the flags
    }
    

    The help returned

    Usage:
      command [flags]
      command [command]
    
    Aliases:
      alias1, alias2
    
    Examples:
      the command usage example
    
    Available Commands:
      sub_command1  subcommand description
      sub_command2  subcommand description
    
    the flags I have
    
    Use "command [command] --help" for more information about a command.
    

    Default Implementation

    Undocumented

    Declaration

    Swift

    var flagsSection: String?
  • informationSection Default implementation

    Return command information description section to be printed for when the command help is printed. Returning nil ignores this section from the help message.


    Examples:

    var informationSection: String? {
      return "command info to get help"
    }
    

    The help returned

    Usage:
      command [flags]
      command [command]
    
    Aliases:
      alias1, alias2
    
    Examples:
      the command usage example
    
    Available Commands:
      sub_command1  subcommand description
      sub_command2  subcommand description
    
    Flags:
      -f, --flag         flag1 description
          --user string  flag2 description
    
    command info to get help
    

    Default Implementation

    Undocumented

    Declaration

    Swift

    var informationSection: String?
  • errorString(forError:) Default implementation

    Return the string printed when an error occur. Returning nil ignores this section from the help message.


    Examples:

    func errorString(forError error: CommandError) -> String {
      return "error occured"
    }
    

    The help returned

    error occured
    Usage:
      command [flags]
      command [command]
    
    Aliases:
      alias1, alias2
    
    Examples:
      the command usage example
    
    Available Commands:
      sub_command1  subcommand description
      sub_command2  subcommand description
    
    Flags:
      -f, --flag         flag1 description
          --user string  flag2 description
    
    Use "command [command] --help" for more information about a command.
    

    Default Implementation

    Declaration

    Swift

    func errorString(forError error: CommandError) -> String
  • Return the string printed when a flag is deprecated. Returning nil ignores this section from the help message


    Examples:

    func deprecationMessage(forDeprecatedFlag flag: FlagHelp) -> String? {
      return "this flag is deprecated"
    }
    

    The help returned

    this flag is deprecated
    

    Default Implementation

    Declaration

    Swift

    func deprecationMessage(forDeprecatedFlag flag: FlagHelp) -> String?
  • Returns a suggestion message string when a unrecognized command is passed to the root command. Returning nil does not show the message


    Examples:

    public func suggestionMessage(original: String, suggestion: String) -> String? {
     return [
       "\(commandHelp.name): '\(original)' is not a \(commandHelp.name) command. See '\(commandHelp.name) --help'.",
       "",
       "Did you mean this?",
       "  \(suggestion)"].joined(separator: "\n")
    }
    

    The suggestion message

    git: 'rbase' is not a git command. See 'git --help'.
    
    Did you mean this?
      rebase
    

    Default Implementation

    Declaration

    Swift

    func suggestionMessage(original: String, suggestion: String) -> String?