Module: CommandKit::Help::Man

Extended by:
ModuleMethods
Includes:
CommandName, CommandKit::Help, 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 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, fallsback to printing the usual --help output.

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

Raises:

  • (NotImplementedError)

    .man_dir does not have a value.



161
162
163
164
165
166
167
168
169
170
# File 'lib/command_kit/help/man.rb', line 161

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) ⇒ 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 does not have a value.



138
139
140
141
142
143
144
145
146
# File 'lib/command_kit/help/man.rb', line 138

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

#man(page, section: nil) ⇒ Boolean?

Displays the given man page.

Parameters:

  • page (String)

    The man page file name.

  • section (Integer, String, nil) (defaults to: nil)

    The optional section number to specify.

Returns:

  • (Boolean, nil)

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



114
115
116
117
118
119
120
# File 'lib/command_kit/help/man.rb', line 114

def man(page, section: nil)
  if section
    system('man',section.to_s,page.to_s)
  else
    system('man',page.to_s)
  end
end