command_lion 1.0.2 → 1.0.3geff
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/examples/example.rb +4 -1
- data/examples/hello_multi.rb +4 -1
- data/examples/read.rb +31 -0
- data/examples/test.rb +32 -0
- data/lib/command_lion/app.rb +59 -14
- data/lib/command_lion/version.rb +1 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7cda4297c39ea6846426e97a497a5cf04647435
|
4
|
+
data.tar.gz: 5b783c285cd06038f9cc99427d13656472ce5f46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c4d111fcb3c61e8490832a38293d9fe25ab2591b14b949fd32999a68eea7810a854377b3c05d6b51638d70004263a3d6c94ba7b06093bf0c21236d0e5453497
|
7
|
+
data.tar.gz: 47240995ed6c20214dd46da5fb8e35bd91ceee7f720f417052da1bb883dabff2109187607b4c232adf812b1b164128c35a816b231959c911b698c8dab01d4212
|
data/examples/example.rb
CHANGED
data/examples/hello_multi.rb
CHANGED
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
|
data/lib/command_lion/app.rb
CHANGED
@@ -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
|
-
|
149
|
-
|
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
|
-
|
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
|
236
|
-
@flags << option.flags.long if
|
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
|
-
|
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 =
|
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
|
data/lib/command_lion/version.rb
CHANGED
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.
|
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-
|
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:
|
124
|
+
version: 1.3.1
|
123
125
|
requirements: []
|
124
126
|
rubyforge_project:
|
125
127
|
rubygems_version: 2.6.12
|