Module: CommandKit::Help::Man

Extended by:
ModuleMethods
Includes:
CommandName, CommandKit::Help, Man, Stdio
Defined in:
lib/command_kit/help/man.rb

Overview

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

Defined Under Namespace

Modules: ClassMethods, ModuleMethods

Instance Attribute Summary

Attributes included from CommandName

#command_name

Instance Method Summary collapse

Methods included from ModuleMethods

included

Methods included from Man

#man

Methods included from Stdio

#abort, #gets, #initialize, #print, #printf, #putc, #puts, #readline, #readlines, #stderr, #stdin, #stdout

Methods included from ModuleMethods

#included

Methods included from CommandName

#initialize

Methods included from CommandName::ModuleMethods

#included

Instance Method Details

#helpObject

Note:

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

Displays the .man_page in .man_dir instead of the usual --help output.



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/command_kit/help/man.rb', line 137

def help
  if stdout.tty?
    if self.class.man_dir
      status = help_man

      if status.nil?
        # the `man` command is not installed
        super
      end
    else
      # man_dir was not set
      super
    end
  else
    # stdout is not a TTY
    super
  end
end

#help_man(man_page = self.class.man_page) ⇒ Boolean?

Provides help information by showing one of the man pages within .man_dir.

Parameters:

  • man_page (String) (defaults to: self.class.man_page)

    The file name of the man page to display.

Returns:

  • (Boolean, nil)

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

Raises:

  • (NotImplementedError)

    .man_dir was not set in the class.



117
118
119
120
121
122
123
124
125
# 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,"man_dir was not set in #{self.class}")
  end

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

  man(man_path)
end