command_lion 1.0.2 → 1.0.3geff

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
  SHA1:
3
- metadata.gz: e1a46eb35cac2757a52188adce29bcb41c03a26c
4
- data.tar.gz: f38a9d1c5559252a4232a5ec0d221e6f73708e55
3
+ metadata.gz: d7cda4297c39ea6846426e97a497a5cf04647435
4
+ data.tar.gz: 5b783c285cd06038f9cc99427d13656472ce5f46
5
5
  SHA512:
6
- metadata.gz: 8a2c13b8007fdeff85b9bbeadcc1157deb5008e5087910b3b0c6216d0c993e25d264c2583204f968f843e4c0d03f89dc39c5f3b75c8e357f837977656090753c
7
- data.tar.gz: 1a8513c041c2097d2fce2bb393f654aa76a718860640404af10ef25e0b1bc31ec9b7352076648f699ea008783ef9e3e5451d7349d6386c398bb22e34803cade1
6
+ metadata.gz: 6c4d111fcb3c61e8490832a38293d9fe25ab2591b14b949fd32999a68eea7810a854377b3c05d6b51638d70004263a3d6c94ba7b06093bf0c21236d0e5453497
7
+ data.tar.gz: 47240995ed6c20214dd46da5fb8e35bd91ceee7f720f417052da1bb883dabff2109187607b4c232adf812b1b164128c35a816b231959c911b698c8dab01d4212
data/examples/example.rb CHANGED
@@ -20,7 +20,10 @@ CommandLion::App.run do
20
20
  end
21
21
 
22
22
  option :rainbow do
23
- flag "--rainbow"
23
+ flags do
24
+ short "-r"
25
+ long "--rainbow"
26
+ end
24
27
  action do
25
28
  require 'lolize/auto'
26
29
  end
@@ -24,7 +24,10 @@ CommandLion::App.run do
24
24
 
25
25
  option :ignore do
26
26
  description "Optionally ignore one person."
27
- flag "--ignore"
27
+ flags do
28
+ short "-i"
29
+ long "--ignore"
30
+ end
28
31
  type :string
29
32
  end
30
33
  end
data/examples/read.rb ADDED
@@ -0,0 +1,31 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'command_lion'
3
+ require 'pry'
4
+
5
+ CommandLion::App.run do
6
+ # ...
7
+ command :read_stdin do
8
+ flag "--read"
9
+ type :stdin_stream
10
+ action do
11
+ # Separate into two operations to make it faster.
12
+ if options[:filter].given?
13
+ # Filter lines that contain string.
14
+ inclusive = options[:filter].argument
15
+ arguments do |argument|
16
+ next unless argument.include?(inclusive)
17
+ puts argument
18
+ end
19
+ else
20
+ # Just print lines.
21
+ arguments do |argument|
22
+ puts argument
23
+ end
24
+ end
25
+ end
26
+ option :filter do
27
+ flag "--filter"
28
+ type :string
29
+ end
30
+ end
31
+ end
data/examples/test.rb ADDED
@@ -0,0 +1,32 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'command_lion'
3
+ require 'pry'
4
+
5
+ CommandLion::App.run do
6
+
7
+ name "Printr"
8
+ version "1.0.0"
9
+ remove_default_help_menu
10
+
11
+ command :print do
12
+ type :string
13
+
14
+ action do
15
+ arguments do |argument|
16
+ puts argument
17
+ end
18
+ end
19
+ end
20
+
21
+ #help do
22
+ # flags do
23
+ # short "-h"
24
+ # long "--help"
25
+ # end
26
+ #
27
+ # action do
28
+ # puts "So helpfulp!"
29
+ # end
30
+ #end
31
+
32
+ end
@@ -100,10 +100,11 @@ module CommandLion
100
100
  max_flag = flagz.map(&:length).max + 2
101
101
  max_desc = app.commands.values.map(&:description).select{|d| d unless d.nil? }.map(&:length).max
102
102
  puts app.name
103
+ puts
103
104
  if app.version?
104
- puts
105
105
  puts "VERSION"
106
106
  puts app.version
107
+ puts
107
108
  end
108
109
  if app.description?
109
110
  puts
@@ -141,17 +142,33 @@ module CommandLion
141
142
  end
142
143
  end
143
144
 
145
+ # This run method is a pretty important method when using command lion typically.
146
+ #
147
+ # Under the hood, an application object is initialized. The block of code passed to
148
+ # this method is then used as the code that is ran in the context of a application
149
+ # object. So all of those methods will be available.
150
+ #
144
151
  def self.run(&block)
152
+ # Initialize an instance of an App object.
145
153
  app = new
154
+ # Evaluate the block of code within the context of that App object.
146
155
  app.instance_eval(&block)
156
+ # Parse the application logic out.
157
+ app.parse
158
+ # Sometimes a command-line application is run without being given any arguments.
147
159
  if ARGV.empty?
148
- if app.help?
149
- puts app.help
160
+ # Default to a help menu.
161
+ if cmd = app.commands[:help]
162
+ cmd.before.call if cmd.before?
163
+ cmd.action.call if cmd.action?
164
+ cmd.after.call if cmd.after?
165
+ # maybe exit?
150
166
  else
151
- default_help(app)
167
+ # Use the default help menu for the application unless that's been
168
+ # explictly removed by the author for whatever reason.
169
+ default_help(app) unless app.default_help_menu_removed?
152
170
  end
153
171
  else
154
- app.parse
155
172
  threadz = false
156
173
  app.commands.each do |_, cmd|
157
174
  next unless cmd.given?
@@ -172,6 +189,22 @@ module CommandLion
172
189
  end
173
190
  end
174
191
 
192
+ # Check if there has been an indexed help command.
193
+ def help?
194
+ return true if @commands[:help]
195
+ false
196
+ end
197
+
198
+ # Explicitly remove the default help menu from the application.
199
+ def remove_default_help_menu
200
+ @remove_default_help_menu = true
201
+ end
202
+
203
+ # Check if the default help menu for the application has been explicitly removed.
204
+ def default_help_menu_removed?
205
+ @remove_default_help_menu || false
206
+ end
207
+
175
208
  # A tiny bit of rainbow magic is included. You can simple include
176
209
  # this option within your application and, if you have the `lolize` gem
177
210
  # installed, then rainbows will automagically be hooked to STDOUT to make your
@@ -232,8 +265,8 @@ module CommandLion
232
265
  if cmd.options?
233
266
  cmd.options.each do |_, option|
234
267
  if option.flags?
235
- @flags << option.flags.short if cmd.flags.short?
236
- @flags << option.flags.long if cmd.flags.long?
268
+ @flags << option.flags.short if option.flags.short?
269
+ @flags << option.flags.long if option.flags.long?
237
270
  else # just use index
238
271
  @flags << option.index.to_s
239
272
  end
@@ -245,6 +278,11 @@ module CommandLion
245
278
  cmd
246
279
  end
247
280
 
281
+ def help(&block)
282
+ command :help, &block
283
+ end
284
+
285
+
248
286
  # Plugin a command that's probably been built outside of the application's run or build block.
249
287
  # This is helpful for sharing or reusing commands in applications.
250
288
  # @param command [Command]
@@ -268,7 +306,8 @@ module CommandLion
268
306
  def parse
269
307
  @commands.each do |_, cmd|
270
308
  if cmd.flags?
271
- next unless argv_index = ARGV.index(cmd.flags.short) or ARGV.index(cmd.flags.long)
309
+ # or for the || seems to not do what I want it to do...
310
+ next unless argv_index = ARGV.index(cmd.flags.short) || ARGV.index(cmd.flags.long)
272
311
  else
273
312
  next unless argv_index = ARGV.index(cmd.index.to_s)
274
313
  end
@@ -292,7 +331,7 @@ module CommandLion
292
331
  def parse_cmd(cmd, flags)
293
332
  if cmd.flags?
294
333
  args = Raw.arguments_to(cmd.flags.short, flags)
295
- if args.empty?
334
+ if args.nil? || args.empty?
296
335
  args = Raw.arguments_to(cmd.flags.long, flags)
297
336
  end
298
337
  else
@@ -307,7 +346,13 @@ module CommandLion
307
346
  when :stdin_string
308
347
  args = STDIN.gets.strip
309
348
  when :stdin_strings
310
- args = STDIN.gets.strip
349
+ args = []
350
+ while arg = STDIN.gets
351
+ next if arg.nil?
352
+ arg = arg.strip
353
+ args << arg
354
+ end
355
+ args
311
356
  when :stdin_integer
312
357
  args = STDIN.gets.strip.to_i
313
358
  when :stdin_integers
@@ -324,7 +369,7 @@ module CommandLion
324
369
  when :stdin_bool
325
370
  args = STDIN.gets.strip.downcase == "true"
326
371
  when :single, :string
327
- args.first
372
+ args = args.first
328
373
  when :strings, :multi
329
374
  if cmd.delimiter?
330
375
  if args.count > 1
@@ -338,7 +383,7 @@ module CommandLion
338
383
  end
339
384
  args
340
385
  when :integer
341
- args.first.to_i
386
+ args = args.first.to_i
342
387
  when :integers
343
388
  if cmd.delimiter?
344
389
  if args.count > 1
@@ -349,7 +394,7 @@ module CommandLion
349
394
  args = args.map { |arg| arg.split(cmd.delimiter) }.flatten
350
395
  end
351
396
  end
352
- args.map(&:to_i)
397
+ args = args.map(&:to_i)
353
398
  when :bool, :bools
354
399
  if cmd.delimiter?
355
400
  if args.count > 1
@@ -360,7 +405,7 @@ module CommandLion
360
405
  args = args.map { |arg| arg.split(cmd.delimiter) }.flatten
361
406
  end
362
407
  end
363
- args.map { |arg| arg == "true" }
408
+ args = args.map { |arg| arg == "true" }
364
409
  end
365
410
  rescue => e# this is dangerous
366
411
  puts e
@@ -1,3 +1,3 @@
1
1
  module CommandLion
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3geff"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: command_lion
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3geff
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kent 'picat' Gruber
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-04 00:00:00.000000000 Z
11
+ date: 2017-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -87,12 +87,14 @@ files:
87
87
  - examples/packet_head.rb
88
88
  - examples/pcapr.rb
89
89
  - examples/plugin.rb
90
+ - examples/read.rb
90
91
  - examples/read_file.rb
91
92
  - examples/read_stdin.rb
92
93
  - examples/readme.rb
93
94
  - examples/sample.rb
94
95
  - examples/simple_attr_example.rb
95
96
  - examples/simple_attrs_example.rb
97
+ - examples/test.rb
96
98
  - examples/words.txt
97
99
  - lib/command_lion.rb
98
100
  - lib/command_lion/app.rb
@@ -117,9 +119,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
117
119
  version: '0'
118
120
  required_rubygems_version: !ruby/object:Gem::Requirement
119
121
  requirements:
120
- - - ">="
122
+ - - ">"
121
123
  - !ruby/object:Gem::Version
122
- version: '0'
124
+ version: 1.3.1
123
125
  requirements: []
124
126
  rubyforge_project:
125
127
  rubygems_version: 2.6.12