cl 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8887728de74e5c76602f7aacb96b7681f89186b8f9688c9a2fe5dc239a921dbe
4
- data.tar.gz: a7105d685d6965d82179c9f7b329d185016dd808b4468a0aa17d7f6f61fbfb25
3
+ metadata.gz: 7f989a757e92bffbfc45652517bbec98cc8cdd09b9aa6809e4822c807de4c3cd
4
+ data.tar.gz: e315d830caf5e61f236d962d83d25c4a3e45c04e6672189a8358ad04c7007e2c
5
5
  SHA512:
6
- metadata.gz: 774ddb21196dd996ed6a627e24eb67a01f0f9a4b44dbf1c04326ff1840c5c999dd4b738bdfd3e1d9d6a874cdb7f6edad8df21c2d0431755b724e47ef74e38ff8
7
- data.tar.gz: baa6e4fc6ca95b7d34763422a1d25efbffad810173f8c79cc981c375a45c75c0542e9db1104cb5caa1d966aa2d7c3b3dba63f6073ed2dd8daec86466275e2a88
6
+ metadata.gz: d9ad4c4d902a66dbe56581053ca7babeca533a65af31d22ff815f17f9f2a386fa238fe9686af776a0df510d7cd1a6696fd32b3fc3061d9cda00f22130bcb520a
7
+ data.tar.gz: 4554e81d0a53997506257670514195e1df150c8d8fe51e35bb956e40e7216d211139ae98403d9c25d05fbc66feff35eaec31471252e78a5555ff88aa2644f947
data/NOTES.md CHANGED
@@ -2,4 +2,6 @@
2
2
  - add conditional required: ->(opts) { opts[:key].nil? }
3
3
 
4
4
 
5
+ - refactor Help::Cmd and Table so that everything goes into one big table
6
+
5
7
  - wrap long lines in help output
data/lib/cl/args.rb CHANGED
@@ -13,8 +13,8 @@ class Cl
13
13
  self.args << arg
14
14
  end
15
15
 
16
- def apply(cmd, args)
17
- return args unless self.args.any?
16
+ def apply(cmd, args, opts)
17
+ return args if self.args.empty? || opts[:help]
18
18
  args = grouped(args)
19
19
  validate(args)
20
20
  args.map { |(arg, value)| arg.set(cmd, value) }.flatten(1)
data/lib/cl/cmd.rb CHANGED
@@ -25,7 +25,7 @@ class Cl
25
25
  def parse(ctx, args)
26
26
  opts = Parser.new(self.opts, args).opts unless self == Help
27
27
  opts = merge(ctx.config[registry_key], opts) if ctx.config[registry_key]
28
- [args, opts]
28
+ [args, opts || {}]
29
29
  end
30
30
 
31
31
  def abstract
@@ -81,8 +81,8 @@ class Cl
81
81
  def initialize(ctx, args)
82
82
  args, opts = self.class.parse(ctx, args)
83
83
  @ctx = ctx
84
- @opts = self.class.opts.apply(self, self.opts.merge(opts || {}))
85
- @args = @opts[:help] ? args : self.class.args.apply(self, args)
84
+ @opts = self.class.opts.apply(self, self.opts.merge(opts))
85
+ @args = self.class.args.apply(self, args, opts)
86
86
  end
87
87
 
88
88
  def opts
data/lib/cl/help/cmd.rb CHANGED
@@ -92,7 +92,7 @@ class Cl
92
92
  opts = opts.join(', ')
93
93
  opts = "(#{opts})" if obj.description && !opts.empty?
94
94
  opts = [obj.description, opts]
95
- opts.compact.join(' ')
95
+ opts.compact.map(&:strip).join(' ')
96
96
  end
97
97
 
98
98
  def format_opt(opt)
data/lib/cl/help/table.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  class Cl
2
2
  class Help
3
3
  class Table
4
+ include Wrap
5
+
4
6
  attr_reader :data, :padding
5
7
 
6
8
  def initialize(data)
@@ -22,7 +24,14 @@ class Cl
22
24
  end
23
25
 
24
26
  def cells(row)
25
- row.map.with_index { |cell, ix| cell.to_s.ljust(widths[ix]) }
27
+ row.map.with_index do |cell, ix|
28
+ indent(wrap(cell.to_s), widths[ix - 1]).ljust(widths[ix])
29
+ end
30
+ end
31
+
32
+ def indent(str, width)
33
+ return str if str.empty? || !width
34
+ [str.lines[0], *str.lines[1..-1].map { |str| ' ' * (width + 1) + str }].join.rstrip
26
35
  end
27
36
 
28
37
  def width
data/lib/cl/helper.rb CHANGED
@@ -16,5 +16,14 @@ class Cl
16
16
  end
17
17
  end
18
18
 
19
- extend Merge, Regex
19
+ module Wrap
20
+ def wrap(str, opts = {})
21
+ width = opts[:width] || 80
22
+ str.lines.map do |line|
23
+ line.size > width ? line.gsub(/(.{1,#{width}})(\s+|$)/, "\\1\n").strip : line
24
+ end.join("\n")
25
+ end
26
+ end
27
+
28
+ extend Merge, Regex, Wrap
20
29
  end
data/lib/cl/opts.rb CHANGED
@@ -15,10 +15,11 @@ class Cl
15
15
  end
16
16
 
17
17
  def apply(cmd, opts)
18
+ return opts if opts[:help]
18
19
  opts = with_defaults(cmd, opts)
19
20
  opts = downcase(opts)
20
21
  opts = cast(opts)
21
- validate(cmd, opts) unless opts[:help]
22
+ validate(cmd, opts)
22
23
  opts
23
24
  end
24
25
 
data/lib/cl/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Cl
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sven Fuchs