Class: Commands
- Inherits:
-
Object
- Object
- Commands
- Defined in:
- lib/ezgit/commands.rb
Instance Attribute Summary collapse
-
#all ⇒ Object
Returns the value of attribute all.
-
#help_list ⇒ Object
Returns the value of attribute help_list.
-
#names ⇒ Object
Returns the value of attribute names.
-
#options ⇒ Object
Returns the value of attribute options.
-
#symbols ⇒ Object
Returns the value of attribute symbols.
Instance Method Summary collapse
-
#initialize ⇒ Commands
constructor
A new instance of Commands.
- #process ⇒ Object
- #read ⇒ Object
Constructor Details
#initialize ⇒ Commands
Returns a new instance of Commands.
6 7 8 9 10 11 12 |
# File 'lib/ezgit/commands.rb', line 6 def initialize @all = [] @symbols = [] @names = [] @help_list = '' @options = {} end |
Instance Attribute Details
#all ⇒ Object
Returns the value of attribute all.
3 4 5 |
# File 'lib/ezgit/commands.rb', line 3 def all @all end |
#help_list ⇒ Object
Returns the value of attribute help_list.
3 4 5 |
# File 'lib/ezgit/commands.rb', line 3 def help_list @help_list end |
#names ⇒ Object
Returns the value of attribute names.
3 4 5 |
# File 'lib/ezgit/commands.rb', line 3 def names @names end |
#options ⇒ Object
Returns the value of attribute options.
3 4 5 |
# File 'lib/ezgit/commands.rb', line 3 def @options end |
#symbols ⇒ Object
Returns the value of attribute symbols.
3 4 5 |
# File 'lib/ezgit/commands.rb', line 3 def symbols @symbols end |
Instance Method Details
#process ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/ezgit/commands.rb', line 28 def process @cmd = ARGV.shift matched = false @all.each do |current| if current[:name].to_s.eql? @cmd matched = true @cmd_opts = Trollop:: do usage = current[:usage] usage ||= "ezgit #{current[:name].to_s} [<options>]" <<-HELP_DESCRIPTION command: ezgit #{current[:name].to_s}\n #{current[:help].to_s} Usage: #{usage} options are: HELP_DESCRIPTION current[:options].each do |cmd_opt| sym = cmd_opt[0] info = cmd_opt[1] flags = cmd_opt[2] opt sym, info, flags end end current[:action].call(@cmd_opts, ARGV) break end end Trollop::die "unknown subcommand #{@cmd.inspect}" if not matched if $commands.[:debug] puts "Global options: #{$commands..inspect}" puts "Subcommand: #{@cmd.inspect}" puts "Subcommand options: #{@cmd_opts.inspect}" puts "Remaining arguments: #{ARGV.inspect}" end end |
#read ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ezgit/commands.rb', line 15 def read commands_dir = File. "commands", File.dirname(__FILE__) files = Dir["#{commands_dir}/*.rb"] files.each do |command_file| require command_file current_symbol = @all.last[:name] @symbols << current_symbol @names << current_symbol.to_s @help_list << "\t#{@names.last.cyan.bold}\t#{@all.last[:help].to_s.bold}\n" end end |