Module: Shebang::Command::ClassMethods

Defined in:
lib/shebang/command.rb

Overview

Several methods that become available as class methods once Shebang::Command is extended by another class.

Since:

Instance Method Summary (collapse)

Instance Method Details

Sets the banner for the command, trailing or leading newlines will be removed.

Parameters:

  • text (String)

    The content of the banner.

Author:

  • Yorick Peterse

Since:

  • 0.1



72
73
74
# File 'lib/shebang/command.rb', line 72

def banner(text)
  @__banner = text.strip
end

- (Object) command(name, options = {})

Binds a class to the specified command name.

Parameters:

  • name (#to_sym)

    The name of the command.

  • options (Hash) (defaults to: {})

    Hash containing various options for the command.

Options Hash (options):

  • :parent (Object)

    The name of the parent command.

Author:

  • Yorick Peterse

Since:

  • 0.1



54
55
56
57
58
59
60
61
62
# File 'lib/shebang/command.rb', line 54

def command(name, options = {})
  name = name.to_sym

  if Shebang::Commands.key?(name)
    Shebang.error("The command #{name} has already been registered")
  end

  Shebang::Commands[name] = self
end

- (Object) help(title, text)

Sets a general "help topic" with a custom title and content.

Examples:

help('License', 'MIT License')

Parameters:

  • title (String)

    The title of the topic.

  • text (String)

    The content of the topic.

Author:

  • Yorick Peterse

Since:

  • 0.1



101
102
103
104
# File 'lib/shebang/command.rb', line 101

def help(title, text)
  @__help_topics      ||= {}
  @__help_topics[title] = text.strip
end

- (Object) option(short, long, desc = nil, options = {}) Also known as: o

Creates a new option for a command.

Examples:

o :h, :help, 'Shows this help message', :method => :help
o :l, :list, 'A list of numbers'      , :type   => Array

See Also:

Author:

  • Yorick Peterse

Since:

  • 0.1



117
118
119
120
121
122
# File 'lib/shebang/command.rb', line 117

def option(short, long, desc = nil, options = {})
  @__options ||= []
  option       = Shebang::Option.new(short, long, desc, options)

  @__options.push(option)
end

- (Object) usage(text)

A small shortcut for defining the syntax of a command. This method is just a shortcut for the following:

help('Usage', 'foobar [OPTIONS]'

Parameters:

  • text (String)

    The content of the usage block.

Author:

  • Yorick Peterse

Since:

  • 0.1



86
87
88
# File 'lib/shebang/command.rb', line 86

def usage(text)
  help('Usage', text)
end