consoler 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 49ca5e9011acc8b6817962ab10c90bae3b91b8f2e0fe351001bdd55b84d0338d
4
- data.tar.gz: f8ced34f84e72074986fad4b16fcfd1ae0725ffaaade46b69d876b028f327ffd
3
+ metadata.gz: 0010d4720e7d43dfb1f4d565b75907891be9d249722835f31ef7db564c952b86
4
+ data.tar.gz: 5f5ea095545606670b4d20b33c3210fa892e91427a4f7cdf273e15fe941cf4e8
5
5
  SHA512:
6
- metadata.gz: 3ab6c3d9629accdc064f3b74cb0458f65a14615e89a81e892e07e9498a7fd28607efcd439fc53278ad4e8be86c54b5031b891b0b9d67c5e6496c456e2f049b74
7
- data.tar.gz: 14c391a50764df0359e0483fd5e59fcd2d765c982e69ea3d15e4b0ff6c5a00270b5f31df397cc2b5275f20d7d9c4e6e56e3000479f78d5e416f5c6287445bc5c
6
+ metadata.gz: 2e7135eb513b261165986c85f724960991429fae68aa8a86b357209e804a6293189094dc987b91c64f03f1c29535865a81726147e9a4173d6f5ae9cbd87ef76a
7
+ data.tar.gz: 49647acd0e61309181a6f0f38098b21ccfaf155549a737ebc2335dacd28d087f5562ad79577d54f18921ff42b55a1edb10e41577d92508cab4b975a48cadc816
data/README.md CHANGED
@@ -55,20 +55,20 @@ gem install consoler
55
55
  or add to your `Gemfile` for applications
56
56
 
57
57
  ```ruby
58
- gem 'consoler', '~> 1.1.0'
58
+ gem 'consoler', '~> 1.2.0'
59
59
  ```
60
60
 
61
61
  or to your `.gemspec` file for gems
62
62
 
63
63
  ```ruby
64
64
  Gem::Specification.new do |spec|
65
- spec.add_dependency 'consoler', '~> 1.1.0'
65
+ spec.add_dependency 'consoler', '~> 1.2.0'
66
66
  end
67
67
  ```
68
68
 
69
69
  ## Docs
70
70
 
71
- Full API documentation can the found here: https://www.rubydoc.info/github/justim/consoler-rb/
71
+ Full API documentation can the found here: https://www.rubydoc.info/gems/consoler/1.2.0
72
72
 
73
73
  ### API
74
74
 
@@ -142,6 +142,12 @@ ruby app.rb build --env production dist
142
142
 
143
143
  # deploy
144
144
  ruby app.rb deploy --verbose
145
+
146
+ # or, you can use command shortcuts. this works by prefix matching and only if
147
+ # there is one match, exact matches always have priority
148
+ ruby app.rb b --env production dist
149
+ ruby app.rb d --verbose
150
+
145
151
  ```
146
152
 
147
153
  #### Options definition
@@ -112,10 +112,31 @@ module Consoler
112
112
  # @return [(mixed, Boolean)] Result of the command, and, did the args match a command at all
113
113
  def _run(args)
114
114
  arg = args.shift
115
+
116
+ return [nil, false] if arg.nil?
117
+
115
118
  arguments = Consoler::Arguments.new args
119
+ exact_matches = []
120
+ partial_matches = []
116
121
 
117
122
  @commands.each do |command|
118
123
  if command.command == arg
124
+ exact_matches.push command
125
+ elsif command.command.start_with? arg
126
+ partial_matches.push command
127
+ end
128
+ end
129
+
130
+ # we only allow a single partial match to prevent ambiguity
131
+ partial_match = if partial_matches.size == 1
132
+ partial_matches[0]
133
+ end
134
+
135
+ unless exact_matches.empty? && partial_match.nil?
136
+ matches = exact_matches
137
+ matches.push partial_match unless partial_match.nil?
138
+
139
+ matches.each do |command|
119
140
  # the matched command contains a subapp, run subapp with the same
120
141
  # arguments (excluding the arg that matched this command)
121
142
  if command.action.instance_of?(Consoler::Application)
@@ -202,7 +223,7 @@ module Consoler
202
223
  normalized_name = _normalize name
203
224
 
204
225
  if parameter_name == normalized_name
205
- return value
226
+ break value
206
227
  end
207
228
  end
208
229
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Consoler
4
4
  # Current version number
5
- VERSION = '1.1.0'.freeze
5
+ VERSION = '1.2.0'.freeze
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: consoler
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-08 00:00:00.000000000 Z
11
+ date: 2019-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler