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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b51686dc165e8a0fa5dad00dea71e56a4007be3ad050de0e7a73b3f7587baefa
4
- data.tar.gz: 97ce2e6f4bb16974e8b1375133fbcbf8be7b1d4f15491935ebcda55557b3784f
3
+ metadata.gz: 71cb3a66fe8101078796ec7dfb0c793d315416020c76e11f2b312c32f6d3c1b2
4
+ data.tar.gz: 1675ca2b4f22fc083948bec274aa75c067e41622dc3d65059a9b200a86d21e0e
5
5
  SHA512:
6
- metadata.gz: 5a98c654de4a78a1dc07c41a8cd2dffcba9d34b57c03b80784b8d652f155d5a53f54370906ec51404c0b6df45a4e387fb8027b5938539780a50e680b9dfbd123
7
- data.tar.gz: 3a0e657604254c35e65ae6c501af0c79fd6887b7cb45b8a4ea1693c6fd666eddf04d5e3b060841bf6b0619c35bfdd6af61e98d9598090c9101f4631d993d84ee
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 {|*args, full:|
20
+ cli.cmd( :help, "An example for help", aliases: [nil, '-h', '--help'], &lambda {|*commands, full:|
21
21
  if full
22
- cli.help_full *args, output: STDERR
22
+ cli.help_full *commands, output: STDERR
23
23
  else
24
- cli.help *args, output: STDERR
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 {|*args| sub2.help( *args, output: STDERR) })
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
- required.each {|s| output << " <#{s}>" }
80
- output << " [#{additional.map{|s|"<#{s}>"}.join " "}]" unless additional.empty?
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 += "=#{v}" if v
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
- "#{full_cmd.join ' '} ..."
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
- def self._help_commands output, subs
50
- m = subs.map {|_name,c| x = c.usage.length; 25 < x ? 0 : x }.max
51
- subs.each do |_name, c|
52
- if 25 < c.usage.length
53
- output << "% -#{m}s\n#{' ' * m} " % [c.usage]
54
- else
55
- output << "% -#{m}s " % [c.usage]
56
- end
57
- n = m+2
58
- prefix = nil
59
- c.description.split /\n/ do |l|
60
- c = 0
61
- l.split %r< > do |w|
62
- if prefix
63
- output << prefix
64
- prefix = nil
65
- end
66
- wl = w.length
67
- if 75 < c+wl
68
- output << "\n#{' ' * n}#{w}"
69
- c = n+2+wl
70
- else
71
- output << " #{w}"
72
- c += 1 + wl
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
- prefix = "\n#{' ' * n}"
89
+ output << "\n"
76
90
  end
77
- output << "\n"
91
+ output
78
92
  end
79
- output
80
93
  end
81
94
 
82
95
  def goto *a
@@ -1,3 +1,3 @@
1
1
  class DenCli
2
- VERSION = '0.5.3'
2
+ VERSION = '0.5.4'
3
3
  end
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.3
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-07 00:00:00.000000000 Z
11
+ date: 2021-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec