clactive 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/clactive.rb +15 -10
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1e2612de27766cb143d93663e153632328abe18c
4
- data.tar.gz: 8933cbe5485b68ce28eb39ed62b9ee4853b98fd0
3
+ metadata.gz: 2807221f858d1a13f24c600df346ab12e4364b6f
4
+ data.tar.gz: aa5c10a9e6db92bf2a0ef42e1db8f9a41f862cf5
5
5
  SHA512:
6
- metadata.gz: 7270d11493d2d4967064e63a4fc1bb63e2fb6be2791952ef3c1b73ebfb6a43b3be7dc1e35194731b0868160a929e970fe25030ff4044c21679d419e4e4fa4957
7
- data.tar.gz: 1144a2329cbd9745826ed348cff2ecd2d4873a467d3207494e544b034a1708bb94d4b3d197000c1284251bcfa275ba135e1139e887d645254f1dc7af2368b64b
6
+ metadata.gz: 80671a97c54c39b6634b2c0ee45521a57d95165355277cccc74955cd6c6f13c12906dd908618b634342325292d428cfe02dbbb092c0ec56d47aa65ee44cb73c5
7
+ data.tar.gz: 93913244e093331057cb52e7c16501c063ecfccbc5702594680c61f10f9b8c23ef0b1a12a20d63d8c2f963fb137ed65730a4f388a90b1a69dd21a2713b936013
data/lib/clactive.rb CHANGED
@@ -37,24 +37,27 @@ module CLActive
37
37
 
38
38
  klass_subcmd = Class.new do
39
39
  define_method :initialize do
40
- @options = {}.extend(tos)
41
40
  @subcmds = {}.extend(tos)
42
41
  @usropts = {}.extend(tos)
42
+ @parser = OptionParser.new
43
43
  end
44
44
 
45
45
  def parse(args)
46
- OptionParser.new do |opt|
47
- @options.each do |key, argv|
48
- opt.on(*argv) do |val|
49
- @usropts[key] = val
50
- end
51
- end
52
- end.order!(args)
46
+ @parser.order!(args)
53
47
  @subcmds
54
48
  end
55
49
 
50
+ def help
51
+ puts @parser.help
52
+ end
53
+
56
54
  def run
57
- @action.call(@usropts) if @action
55
+ if @action
56
+ argv = [@usropts]
57
+ argc = @action.arity
58
+ argv << self if argc > 1 || argc < 0
59
+ @action.call(*argv)
60
+ end
58
61
  end
59
62
 
60
63
  def subcmd(name)
@@ -66,7 +69,9 @@ module CLActive
66
69
  end
67
70
 
68
71
  def option(name, *argv)
69
- @options[name] = argv if argv
72
+ @parser.on(*argv) do |val|
73
+ @usropts[name] = val
74
+ end
70
75
  self
71
76
  end
72
77
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clactive
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tang Tianyong
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-11 00:00:00.000000000 Z
11
+ date: 2013-04-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: CLActive help you to build command quickly
14
14
  email: tang3w@gmail.com