samovar 2.1.4 → 2.2.0
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
- checksums.yaml.gz.sig +0 -0
- data/lib/samovar/command.rb +13 -21
- data/lib/samovar/error.rb +4 -19
- data/lib/samovar/failure.rb +4 -19
- data/lib/samovar/flags.rb +4 -19
- data/lib/samovar/many.rb +4 -19
- data/lib/samovar/nested.rb +4 -19
- data/lib/samovar/one.rb +4 -19
- data/lib/samovar/option.rb +4 -19
- data/lib/samovar/options.rb +4 -19
- data/lib/samovar/output/columns.rb +4 -19
- data/lib/samovar/output/header.rb +4 -19
- data/lib/samovar/output/row.rb +4 -19
- data/lib/samovar/output/rows.rb +4 -19
- data/lib/samovar/output/usage_formatter.rb +4 -19
- data/lib/samovar/output.rb +4 -19
- data/lib/samovar/split.rb +4 -19
- data/lib/samovar/table.rb +4 -19
- data/lib/samovar/version.rb +6 -20
- data/lib/samovar.rb +4 -19
- data/license.md +22 -0
- data/{README.md → readme.md} +37 -53
- data.tar.gz.sig +0 -0
- metadata +52 -60
- metadata.gz.sig +2 -0
- data/.gitignore +0 -11
- data/.rspec +0 -4
- data/.travis.yml +0 -20
- data/Gemfile +0 -8
- data/Rakefile +0 -9
- data/samovar.gemspec +0 -28
- data/spec/samovar/coerce_spec.rb +0 -45
- data/spec/samovar/command_spec.rb +0 -91
- data/spec/samovar/many_spec.rb +0 -49
- data/spec/samovar/nested_spec.rb +0 -111
- data/spec/samovar/one_spec.rb +0 -49
- data/spec/samovar/options_spec.rb +0 -50
- data/spec/samovar/split_spec.rb +0 -49
- data/spec/samovar/table_spec.rb +0 -39
- data/spec/spec_helper.rb +0 -32
- data/teapot.png +0 -0
data/spec/samovar/nested_spec.rb
DELETED
@@ -1,111 +0,0 @@
|
|
1
|
-
# Copyright, 2019, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
-
#
|
3
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
# of this software and associated documentation files (the "Software"), to deal
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in
|
11
|
-
# all copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
# THE SOFTWARE.
|
20
|
-
|
21
|
-
require 'samovar'
|
22
|
-
|
23
|
-
RSpec.describe Samovar::Nested do
|
24
|
-
let(:commands) do
|
25
|
-
{
|
26
|
-
'inner-a' => Class.new(Samovar::Command),
|
27
|
-
'inner-b' => Class.new(Samovar::Command),
|
28
|
-
}
|
29
|
-
end
|
30
|
-
|
31
|
-
let(:default) {'inner-a'}
|
32
|
-
let(:input) {['inner-a']}
|
33
|
-
subject{described_class.new(:command, commands, default: default)}
|
34
|
-
|
35
|
-
it "has string representation" do
|
36
|
-
expect(subject.to_s).to be == "<command>"
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should have default" do
|
40
|
-
expect(subject.default).to be == default
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should use default" do
|
44
|
-
expect(subject.parse([])).to be_kind_of commands[default]
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should use specified default" do
|
48
|
-
command = commands['inner-b'].new
|
49
|
-
|
50
|
-
expect(subject.parse([], nil, command)).to be command
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should not use default if input specified" do
|
54
|
-
expect(subject.parse(input)).to be_kind_of commands['inner-a']
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
module Samovar::NestedSpec
|
59
|
-
class InnerA < Samovar::Command
|
60
|
-
options
|
61
|
-
end
|
62
|
-
|
63
|
-
class InnerB < InnerA
|
64
|
-
options do
|
65
|
-
option '--help', "Do you need it?"
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
class InnerC < InnerB
|
70
|
-
options do
|
71
|
-
option '--frobulate', "Zork is waiting for you."
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
class Outer < Samovar::Command
|
76
|
-
options do
|
77
|
-
end
|
78
|
-
|
79
|
-
nested :command, {
|
80
|
-
'inner-a' => InnerA,
|
81
|
-
'inner-b' => InnerB,
|
82
|
-
'inner-c' => InnerC,
|
83
|
-
}, default: 'inner-b'
|
84
|
-
end
|
85
|
-
|
86
|
-
RSpec.describe Samovar::Nested do
|
87
|
-
it "should select default nested command" do
|
88
|
-
outer = Outer[]
|
89
|
-
expect(outer.command).to be_kind_of(InnerB)
|
90
|
-
|
91
|
-
outer.print_usage
|
92
|
-
end
|
93
|
-
|
94
|
-
it "should select explicitly named nested command" do
|
95
|
-
outer = Outer['inner-a']
|
96
|
-
expect(outer.command).to be_kind_of(InnerA)
|
97
|
-
end
|
98
|
-
|
99
|
-
it "can parse derived options" do
|
100
|
-
outer = Outer['inner-c', '--help']
|
101
|
-
expect(outer.command).to be_kind_of(InnerC)
|
102
|
-
expect(outer.command.options).to include(help: true)
|
103
|
-
expect(outer.command.parent).to be outer
|
104
|
-
end
|
105
|
-
|
106
|
-
xit "should parse help option at outer level" do
|
107
|
-
outer = Outer['inner-a', '--help']
|
108
|
-
expect(outer.options[:help]).to_be truthy
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
data/spec/samovar/one_spec.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
# Copyright, 2019, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
-
#
|
3
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
# of this software and associated documentation files (the "Software"), to deal
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in
|
11
|
-
# all copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
# THE SOFTWARE.
|
20
|
-
|
21
|
-
require 'samovar/many'
|
22
|
-
|
23
|
-
RSpec.describe Samovar::One do
|
24
|
-
let(:default) {"1"}
|
25
|
-
let(:input) {["2", "3", "4"]}
|
26
|
-
|
27
|
-
subject{described_class.new(:thing, "a thing", default: default)}
|
28
|
-
|
29
|
-
it "has string representation" do
|
30
|
-
expect(subject.to_s).to be == "<thing>"
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should have default" do
|
34
|
-
expect(subject.default).to be == default
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should use default" do
|
38
|
-
expect(subject.parse([])).to be == default
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should use specified default" do
|
42
|
-
expect(subject.parse([], nil, "2")).to be == "2"
|
43
|
-
end
|
44
|
-
|
45
|
-
it "should not use default if input specified" do
|
46
|
-
expect(subject.parse(input)).to be == "2"
|
47
|
-
expect(input).to be == ["3", "4"]
|
48
|
-
end
|
49
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
# Copyright, 2019, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
-
#
|
3
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
# of this software and associated documentation files (the "Software"), to deal
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in
|
11
|
-
# all copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
# THE SOFTWARE.
|
20
|
-
|
21
|
-
RSpec.describe Samovar::Options do
|
22
|
-
subject(:options) do
|
23
|
-
described_class.parse do
|
24
|
-
option '-x <value>', "The x factor", default: 2
|
25
|
-
option '-y <value>', "The y factor"
|
26
|
-
|
27
|
-
option '--symbol <value>', "A symbol", type: Symbol
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should set defaults" do
|
32
|
-
values = options.parse([], nil, nil)
|
33
|
-
expect(values).to be == {x: 2}
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should preserve current values" do
|
37
|
-
values = options.parse([], nil, {x: 1, y: 2, z: 3})
|
38
|
-
expect(values).to be == {x: 1, y: 2, z: 3}
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should update specified values" do
|
42
|
-
values = options.parse(['-x', 10], nil, {x: 1, y: 2, z: 3})
|
43
|
-
expect(values).to be == {x: 10, y: 2, z: 3}
|
44
|
-
end
|
45
|
-
|
46
|
-
it "converts to symbol" do
|
47
|
-
values = options.parse(['--symbol', 'thing'], {})
|
48
|
-
expect(values[:symbol]).to eq :thing
|
49
|
-
end
|
50
|
-
end
|
data/spec/samovar/split_spec.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
# Copyright, 2019, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
-
#
|
3
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
# of this software and associated documentation files (the "Software"), to deal
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in
|
11
|
-
# all copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
# THE SOFTWARE.
|
20
|
-
|
21
|
-
require 'samovar/split'
|
22
|
-
|
23
|
-
RSpec.describe Samovar::Split do
|
24
|
-
let(:default) {["1", "2", "3"]}
|
25
|
-
let(:input) {["2", "--", "3"]}
|
26
|
-
|
27
|
-
subject{described_class.new(:arguments, "arguments", default: default)}
|
28
|
-
|
29
|
-
it "has string representation" do
|
30
|
-
expect(subject.to_s).to be == "-- <arguments...>"
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should have default" do
|
34
|
-
expect(subject.default).to be == default
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should use default" do
|
38
|
-
expect(subject.parse([])).to be == default
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should use specified default" do
|
42
|
-
expect(subject.parse([], nil, ["2"])).to be == ["2"]
|
43
|
-
end
|
44
|
-
|
45
|
-
it "should not use default if input specified" do
|
46
|
-
expect(subject.parse(input)).to be == ["3"]
|
47
|
-
expect(input).to be == ["2"]
|
48
|
-
end
|
49
|
-
end
|
data/spec/samovar/table_spec.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
# Copyright, 2019, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
-
#
|
3
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
# of this software and associated documentation files (the "Software"), to deal
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in
|
11
|
-
# all copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
# THE SOFTWARE.
|
20
|
-
|
21
|
-
require 'samovar/table'
|
22
|
-
require 'samovar/options'
|
23
|
-
|
24
|
-
RSpec.describe Samovar::Table do
|
25
|
-
let(:parent) {described_class.new}
|
26
|
-
subject{described_class.new(parent)}
|
27
|
-
|
28
|
-
it "can merge options" do
|
29
|
-
parent << Samovar::Options.parse
|
30
|
-
subject << Samovar::Options.parse do
|
31
|
-
option "--help", "Print help information."
|
32
|
-
end
|
33
|
-
|
34
|
-
subject.merged
|
35
|
-
parent.merged
|
36
|
-
|
37
|
-
expect(parent[:options]).to be_empty
|
38
|
-
end
|
39
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
# Copyright, 2019, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
-
#
|
3
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
# of this software and associated documentation files (the "Software"), to deal
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in
|
11
|
-
# all copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
# THE SOFTWARE.
|
20
|
-
|
21
|
-
require 'covered/rspec'
|
22
|
-
|
23
|
-
RSpec.configure do |config|
|
24
|
-
config.disable_monkey_patching!
|
25
|
-
|
26
|
-
# Enable flags like --only-failures and --next-failure
|
27
|
-
config.example_status_persistence_file_path = ".rspec_status"
|
28
|
-
|
29
|
-
config.expect_with :rspec do |c|
|
30
|
-
c.syntax = :expect
|
31
|
-
end
|
32
|
-
end
|
data/teapot.png
DELETED
Binary file
|