clactive 0.0.11 → 0.0.12

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 +23 -3
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ec004dbe7968f7644cd600fc83a3dd6e3b9a4194
4
- data.tar.gz: c804b6da4821034579f62c5633eada3d50b79821
3
+ metadata.gz: c7e4c4ba93357a7c358eadf5cbbe467a0763d50c
4
+ data.tar.gz: e516a1c1bf8f1de50a02137849a5882a4bc61831
5
5
  SHA512:
6
- metadata.gz: d2b455692aa0c2bd07ddec723f1bed2717a6251707b4468f4912439910fdf0b4c96c1e3ffd2ce20b0f1695219ad321c0909d3ee48332bed11e00260d0a629209
7
- data.tar.gz: 87666e0acc3f7fc60c88e7c1ce7457582fcdac7598407bd1480759cb208d76756cc92ac4ef3860e7e72d0aa7ef50a3171b3b2a904ab988881f299c9cd5ab947d
6
+ metadata.gz: 2e78465a5aeb0b5065f6292110bcd4853f3c9557f13c1632d99dcfccc9051c8976faf7751611ec3cc8b62450fb056cd90433caef8d0b9cb27f889c4106e4e8e1
7
+ data.tar.gz: 81c3b49f88fdbfe22ddd15f7b64ecea4e60684709999abccef0b1d336a05ef01ed98fd1c2e6967c722d34d612ee523ca0f99e32f959a117a1eca98bdaa0463cb
@@ -77,13 +77,24 @@ module CLActive
77
77
  end
78
78
 
79
79
  def [](key)
80
- subcmds[key]
80
+ cmd = subcmds[key]
81
+ unless cmd
82
+ key = key.to_s
83
+ subcmds.reverse_each do |_, val|
84
+ return val if val.aka.include?(key)
85
+ end
86
+ end
87
+ cmd
81
88
  end
82
89
 
83
- def subcmd(key = nil, &block)
90
+ def subcmd(*keys, &block)
84
91
  if block
85
92
  cmd = self.class.new
86
- cmd.name(key) if key
93
+ unless keys.empty?
94
+ keys.map!(&:to_s)
95
+ cmd.name(keys.shift)
96
+ cmd.aka.concat(keys) unless keys.empty?
97
+ end
87
98
  cmd.instance_exec(&block)
88
99
  subcmds[cmd.name] = cmd if cmd.name
89
100
  else
@@ -111,6 +122,15 @@ module CLActive
111
122
  def action(&block)
112
123
  @action = block if block
113
124
  end
125
+
126
+ def aka(key = nil)
127
+ if key
128
+ key = key.to_s
129
+ aka << key unless aka.include?(key)
130
+ else
131
+ @aka ||= []
132
+ end
133
+ end
114
134
  end
115
135
 
116
136
  apis = %w(name subcmd option action)
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.11
4
+ version: 0.0.12
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-16 00:00:00.000000000 Z
11
+ date: 2013-04-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: CLActive help you to build command quickly
14
14
  email: tang3w@gmail.com