Module: GitHub
- Extended by:
- GitHub
- Included in:
- GitHub
- Defined in:
- lib/github.rb,
lib/github/helper.rb,
lib/github/command.rb
Overview
Starting simple.
$ github <command> <args>
GitHub.register <command> do |*args|
whatever
end
We’ll probably want to use the ‘choice` gem for concise, tasty DSL arg parsing action.
Defined Under Namespace
Constant Summary collapse
- BasePath =
File.(File.dirname(__FILE__) + '/..')
Instance Method Summary collapse
- #activate(args) ⇒ Object
- #commands ⇒ Object
- #debug(*messages) ⇒ Object
- #debug? ⇒ Boolean
- #describe(hash) ⇒ Object
- #descriptions ⇒ Object
- #flag_descriptions ⇒ Object
- #flags(command, hash) ⇒ Object
- #helper(command, &block) ⇒ Object
- #invoke(command, *args) ⇒ Object
- #load(file) ⇒ Object
- #options ⇒ Object
- #parse_options(args) ⇒ Object
- #register(command, &block) ⇒ Object
Instance Method Details
#activate(args) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/github.rb', line 44 def activate(args) @options = (args) load 'helpers.rb' load 'commands.rb' invoke(args.shift, *args) end |
#commands ⇒ Object
57 58 59 |
# File 'lib/github.rb', line 57 def commands @commands ||= {} end |
#debug(*messages) ⇒ Object
97 98 99 |
# File 'lib/github.rb', line 97 def debug(*) puts *.map { |m| "== #{m}" } if debug? end |
#debug? ⇒ Boolean
101 102 103 |
# File 'lib/github.rb', line 101 def debug? !!@debug end |
#describe(hash) ⇒ Object
31 32 33 |
# File 'lib/github.rb', line 31 def describe(hash) descriptions.update hash end |
#descriptions ⇒ Object
61 62 63 |
# File 'lib/github.rb', line 61 def descriptions @descriptions ||= {} end |
#flag_descriptions ⇒ Object
65 66 67 |
# File 'lib/github.rb', line 65 def flag_descriptions @flagdescs ||= Hash.new { |h, k| h[k] = {} } end |
#flags(command, hash) ⇒ Object
35 36 37 |
# File 'lib/github.rb', line 35 def flags(command, hash) flag_descriptions[command].update hash end |
#helper(command, &block) ⇒ Object
39 40 41 42 |
# File 'lib/github.rb', line 39 def helper(command, &block) debug "Helper'd `#{command}`" Helper.send :define_method, command, &block end |
#invoke(command, *args) ⇒ Object
51 52 53 54 55 |
# File 'lib/github.rb', line 51 def invoke(command, *args) block = commands[command.to_s] || commands['default'] debug "Invoking `#{command}`" block.call(*args) end |
#load(file) ⇒ Object
93 94 95 |
# File 'lib/github.rb', line 93 def load(file) file[0] == ?/ ? super : super(BasePath + "/commands/#{file}") end |
#options ⇒ Object
69 70 71 |
# File 'lib/github.rb', line 69 def @options end |
#parse_options(args) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/github.rb', line 73 def (args) idx = 0 args.clone.inject({}) do |memo, arg| case arg when /^--(.+?)=(.*)/ args.delete_at(idx) memo.merge($1.to_sym => $2) when /^--(.+)/ args.delete_at(idx) memo.merge($1.to_sym => true) when "--" args.delete_at(idx) return memo else idx += 1 memo end end end |