Class: Chid::Command
- Inherits:
-
Object
- Object
- Chid::Command
- Defined in:
- lib/chid/command.rb
Direct Known Subclasses
Chid::Commands::Config, Chid::Commands::Currency::Convert, Chid::Commands::Currency::Current, Chid::Commands::Currency::List, Chid::Commands::Gitflow::Commit, Chid::Commands::Github, Chid::Commands::Init, Chid::Commands::Installs::Dotfile, Chid::Commands::Installs::Node, Chid::Commands::Installs::Postgres, Chid::Commands::Installs::Rvm, Chid::Commands::Installs::Vim, Chid::Commands::News, Chid::Commands::StackOverflow, Chid::Commands::Tmux::List, Chid::Commands::Tmux::Open, Chid::Commands::Workstation::Create, Chid::Commands::Workstation::Destroy, Chid::Commands::Workstation::List, Chid::Commands::Workstation::Open
Constant Summary collapse
- COMMANDS =
{}
Class Attribute Summary collapse
-
.arguments ⇒ Object
Returns the value of attribute arguments.
-
.description ⇒ Object
Returns the value of attribute description.
-
.summary ⇒ Object
Returns the value of attribute summary.
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
- .command(cmd) ⇒ Object
- .help ⇒ Object
-
.map_options_with_values(argv) ⇒ Hash<String, Array>
Returns a mapped options with your values from @argv.
- .run(argv) ⇒ Object
Instance Method Summary collapse
-
#initialize(options) ⇒ Command
constructor
A new instance of Command.
Constructor Details
#initialize(options) ⇒ Command
145 146 147 |
# File 'lib/chid/command.rb', line 145 def initialize() @options = end |
Class Attribute Details
.arguments ⇒ Object
Returns the value of attribute arguments.
6 7 8 |
# File 'lib/chid/command.rb', line 6 def arguments @arguments end |
.description ⇒ Object
Returns the value of attribute description.
6 7 8 |
# File 'lib/chid/command.rb', line 6 def description @description end |
.summary ⇒ Object
Returns the value of attribute summary.
6 7 8 |
# File 'lib/chid/command.rb', line 6 def summary @summary end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
143 144 145 |
# File 'lib/chid/command.rb', line 143 def @options end |
Class Method Details
.command(cmd) ⇒ Object
10 11 12 |
# File 'lib/chid/command.rb', line 10 def command(cmd) COMMANDS[cmd] = self.to_s end |
.help ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/chid/command.rb', line 14 def help if self.description.nil? commands = String.new COMMANDS.keys.each {|k| commands << " #{k.to_s}\n" } self.description = <<-DESC Usage: $ chid [COMMAND] To see what the Command do: $ chid [COMMAND] -h Commands: #{commands} DESC end puts summary print description end |
.map_options_with_values(argv) ⇒ Hash<String, Array>
Returns a mapped options with your values from @argv
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/chid/command.rb', line 57 def (argv) return argv.reduce({}) do |, arg| = if arg_is_an_option?(arg) [arg] = [] next() end (, arg) end end |
.run(argv) ⇒ Object
37 38 39 40 41 |
# File 'lib/chid/command.rb', line 37 def run(argv) command_key = command_key(argv) return self.help unless command_key_is_included?(command_key) invoke(argv) end |