dencli 0.5.3 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/example.rb +4 -4
- data/lib/dencli/cmd.rb +11 -3
- data/lib/dencli/sub.rb +42 -29
- data/lib/dencli/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71cb3a66fe8101078796ec7dfb0c793d315416020c76e11f2b312c32f6d3c1b2
|
4
|
+
data.tar.gz: 1675ca2b4f22fc083948bec274aa75c067e41622dc3d65059a9b200a86d21e0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 938480ac26fa9cbac07118edfa407b1a59d2e9534b43fdd308bf4e81a96e78a20fc2b3d3143029d6a8b1f516ebbd14af7507ae703e395d46ad4abfdbd3b42844
|
7
|
+
data.tar.gz: af52e24ace634da494e17b5efa06bdc475fa64d9250218d38b1c60ee7d4b9897cfdce6cf6cf54f141acca8ec836140a2ad368ac27ceb0bbd2b1cdf1c3b43598a
|
data/bin/example.rb
CHANGED
@@ -17,11 +17,11 @@ cli.cmd( :args, "Expects and prints given arguments",
|
|
17
17
|
opt( :h, '-hsth', "No long option, only short option", default: "nothing")
|
18
18
|
|
19
19
|
cli.cmd( :example, "I have an example command") { STDERR.puts "This is an example" }
|
20
|
-
cli.cmd( :help, "", aliases: [nil, '-h', '--help'], &lambda {|*
|
20
|
+
cli.cmd( :help, "An example for help", aliases: [nil, '-h', '--help'], &lambda {|*commands, full:|
|
21
21
|
if full
|
22
|
-
cli.help_full *
|
22
|
+
cli.help_full *commands, output: STDERR
|
23
23
|
else
|
24
|
-
cli.help *
|
24
|
+
cli.help *commands, output: STDERR
|
25
25
|
end
|
26
26
|
}).
|
27
27
|
opt( :full, '-f', '--[no-]full', "Print all commands and sub-commands.", default: false)
|
@@ -40,7 +40,7 @@ cli.sub( :more, "Sub-Commands are also possible with a new cli") do |sub|
|
|
40
40
|
opt( :e, '-e', "Toggle e")
|
41
41
|
|
42
42
|
sub.sub( :deeper, "You want to have Sub-Sub-Commands?") do |sub2|
|
43
|
-
sub2.cmd( :help, "", aliases: [nil, '-h', '--help'], &lambda {|*
|
43
|
+
sub2.cmd( :help, "", aliases: [nil, '-h', '--help'], &lambda {|*commands| sub2.help( *commands, output: STDERR) })
|
44
44
|
sub2.cmd( :last, "The last example", &lambda { STDERR.puts "The last example" })
|
45
45
|
|
46
46
|
sub2.sub( :'sub-commands', "Endless Sub-Sub- ...") do |sub3|
|
data/lib/dencli/cmd.rb
CHANGED
@@ -76,8 +76,16 @@ class DenCli::CMD
|
|
76
76
|
output << (o.required? ? " #{s}" : " [#{s}]")
|
77
77
|
end
|
78
78
|
if @exe.lambda?
|
79
|
-
|
80
|
-
|
79
|
+
parameters.each do |(type, name)|
|
80
|
+
case type
|
81
|
+
when :req
|
82
|
+
output << " <#{name}>"
|
83
|
+
when :opt
|
84
|
+
output << " [<#{name}>]"
|
85
|
+
when :rest
|
86
|
+
output << " [<#{name}> ...]"
|
87
|
+
end
|
88
|
+
end
|
81
89
|
else
|
82
90
|
output << ' ...'
|
83
91
|
end
|
@@ -130,7 +138,7 @@ class DenCli::CMD
|
|
130
138
|
@options.map do |_, o|
|
131
139
|
s, l, v, y = o.short, o.long, o.val, ','
|
132
140
|
if l.nil?
|
133
|
-
s += "
|
141
|
+
s += "#{v}" if v
|
134
142
|
y = ' '
|
135
143
|
elsif s.nil?
|
136
144
|
l += "=#{v}" if v
|
data/lib/dencli/sub.rb
CHANGED
@@ -14,8 +14,19 @@ class DenCli::Sub
|
|
14
14
|
def full_cmd() _full_cmd [] end
|
15
15
|
def []( k) @aliases[k] end
|
16
16
|
|
17
|
-
def usage
|
18
|
-
|
17
|
+
def usage output: nil
|
18
|
+
output ||= ''
|
19
|
+
_usage output
|
20
|
+
output
|
21
|
+
end
|
22
|
+
|
23
|
+
def _usage output
|
24
|
+
output << full_cmd.join( ' ')
|
25
|
+
if @aliases.has_key? nil
|
26
|
+
output << " [<command> ...]"
|
27
|
+
else
|
28
|
+
output << " <command> [...]"
|
29
|
+
end
|
19
30
|
end
|
20
31
|
|
21
32
|
def help n = nil, *a, output: nil
|
@@ -46,37 +57,39 @@ class DenCli::Sub
|
|
46
57
|
output
|
47
58
|
end
|
48
59
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
c
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
60
|
+
class <<self
|
61
|
+
def _help_commands output, subs
|
62
|
+
m = subs.map {|_name,c| x = c.usage.length; 25 < x ? 0 : x }.max
|
63
|
+
subs.each do |_name, c|
|
64
|
+
if 25 < c.usage.length
|
65
|
+
output << "% -#{m}s\n#{' ' * m} " % [c.usage]
|
66
|
+
else
|
67
|
+
output << "% -#{m}s " % [c.usage]
|
68
|
+
end
|
69
|
+
n = m+2
|
70
|
+
prefix = nil
|
71
|
+
c.description.split( /\n/).each do |l|
|
72
|
+
c = 0
|
73
|
+
l.split( %r< >).each do |w|
|
74
|
+
if prefix
|
75
|
+
output << prefix
|
76
|
+
prefix = nil
|
77
|
+
end
|
78
|
+
wl = w.length
|
79
|
+
if 75 < c+wl
|
80
|
+
output << "\n#{' ' * n}#{w}"
|
81
|
+
c = n+2+wl
|
82
|
+
else
|
83
|
+
output << " #{w}"
|
84
|
+
c += 1 + wl
|
85
|
+
end
|
73
86
|
end
|
87
|
+
prefix = "\n#{' ' * n}"
|
74
88
|
end
|
75
|
-
|
89
|
+
output << "\n"
|
76
90
|
end
|
77
|
-
output
|
91
|
+
output
|
78
92
|
end
|
79
|
-
output
|
80
93
|
end
|
81
94
|
|
82
95
|
def goto *a
|
data/lib/dencli/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dencli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Denis Knauf
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-12-
|
11
|
+
date: 2021-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|