Module: CommandKit::Usage

Extended by:
ModuleMethods
Includes:
CommandName, Help
Included in:
Arguments, Command, Commands, Options::Parser
Defined in:
lib/command_kit/usage.rb

Overview

Defines the usage string for a command class.

Examples

include CommandKit::Usage

usage "[options] ARG1 ARG2 [ARG3 ...]"

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 Help::ModuleMethods

#included

Methods included from CommandName

#initialize

Methods included from CommandName::ModuleMethods

#included

Instance Method Details

#helpObject

Prints the usage.

See Also:



114
115
116
# File 'lib/command_kit/usage.rb', line 114

def help
  help_usage
end

#help_usageObject

Prints the usage: ... output.



94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/command_kit/usage.rb', line 94

def help_usage
  case (usage = self.usage)
  when Array
    puts "usage: #{usage[0]}"

    usage[1..].each do |command|
      puts "       #{command}"
    end
  when String
    puts "usage: #{usage}"
  end
end

#usageArray<String>, ...

Similar to .usage, but prepends command_name.

Returns:

  • (Array<String>, String, nil)


80
81
82
83
84
85
86
87
# File 'lib/command_kit/usage.rb', line 80

def usage
  case (usage = self.class.usage)
  when Array
    usage.map { |command| "#{command_name} #{command}" }
  when String
    "#{command_name} #{usage}"
  end
end