module CommandKit::Help::Man

Allows displaying a man-page instead of the usual `–help` output.

## Examples

class Foo < CommandKit::Command

  include CommandKit::Help::Man

  man_dir "#{__dir__}/../../man"

end

Public Instance Methods

help() click to toggle source

Displays the {ClassMethods#man_page .man_page} in {ClassMethods#man_dir .man_dir} instead of the usual `–help` output.

@raise [NotImplementedError]

{ClassMethods#man_dir .man_dir} does not have a value.

@note

if `TERM` is `dumb` or `$stdout` is not a TTY, will fall back to
printing the usual `--help` output.

@api public

Calls superclass method CommandKit::Help#help
# File lib/command_kit/help/man.rb, line 140
def help
  if stdout.tty?
    if help_man.nil?
      # the `man` command is not installed
      super
    end
  else
    super
  end
end
help_man(man_page=self.class.man_page) click to toggle source

Provides help information by showing one of the man pages within {ClassMethods#man_dir .man_dir}.

@param [String] man_page

The file name of the man page to display.

@return [Boolean, nil]

Specifies whether the `man` command was successful or not.
Returns `nil` when the `man` command is not installed.

@raise [NotImplementedError]

{ClassMethods#man_dir .man_dir} does not have a value.

@api semipublic

# File lib/command_kit/help/man.rb, line 117
def help_man(man_page=self.class.man_page)
  unless self.class.man_dir
    raise(NotImplementedError,"#{self.class}.man_dir not set")
  end

  man_path = File.join(self.class.man_dir,man_page)

  man(man_path)
end