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 +4 -4
- data/NOTES.md +2 -0
- data/lib/cl/args.rb +2 -2
- data/lib/cl/cmd.rb +3 -3
- data/lib/cl/help/cmd.rb +1 -1
- data/lib/cl/help/table.rb +10 -1
- data/lib/cl/helper.rb +10 -1
- data/lib/cl/opts.rb +2 -1
- data/lib/cl/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f989a757e92bffbfc45652517bbec98cc8cdd09b9aa6809e4822c807de4c3cd
|
4
|
+
data.tar.gz: e315d830caf5e61f236d962d83d25c4a3e45c04e6672189a8358ad04c7007e2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9ad4c4d902a66dbe56581053ca7babeca533a65af31d22ff815f17f9f2a386fa238fe9686af776a0df510d7cd1a6696fd32b3fc3061d9cda00f22130bcb520a
|
7
|
+
data.tar.gz: 4554e81d0a53997506257670514195e1df150c8d8fe51e35bb956e40e7216d211139ae98403d9c25d05fbc66feff35eaec31471252e78a5555ff88aa2644f947
|
data/NOTES.md
CHANGED
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
|
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 =
|
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
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
|
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
|
-
|
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
data/lib/cl/version.rb
CHANGED