samovar 2.1.4 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,45 +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
- module Samovar::CoerceSpec
24
- class Coerce < Samovar::Command
25
- options do
26
- option '--things <array>', "A list of things" do |input|
27
- input.split(/\s*,\s*/)
28
- end
29
-
30
- option '--count <integer>', "A number to count", type: Integer
31
- end
32
- end
33
-
34
- RSpec.describe Samovar::Command do
35
- it "should coerce to array" do
36
- top = Coerce['--things', 'a,b,c']
37
- expect(top.options[:things]).to be == ['a', 'b', 'c']
38
- end
39
-
40
- it "should coerce to integer" do
41
- top = Coerce['--count', '10']
42
- expect(top.options[:count]).to be == 10
43
- end
44
- end
45
- end
@@ -1,91 +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
- module Samovar::CommandSpec
24
- class Bottom < Samovar::Command
25
- self.description = "Create a new teapot package using the specified repository."
26
-
27
- one :project_name, "The name of the new project in title-case, e.g. 'My Project'."
28
- many :packages, "Any additional packages you'd like to include in the project."
29
- split :argv, "Additional arguments to be passed to the sub-process."
30
- end
31
-
32
- class Top < Samovar::Command
33
- self.description = "A decentralised package manager and build tool."
34
-
35
- options do
36
- option '-c/--configuration <name>', "Specify a specific build configuration.", default: 'TEAPOT_CONFIGURATION'
37
- option '-i/--in/--root <path>', "Work in the given root directory."
38
- option '--verbose | --quiet', "Verbosity of output for debugging.", key: :logging
39
- option '-h/--help', "Print out help information."
40
- option '-v/--version', "Print out the application version."
41
- end
42
-
43
- nested :command, {
44
- 'bottom' => Bottom
45
- }
46
- end
47
-
48
- RSpec.describe Samovar::Command do
49
- it "should invoke call" do
50
- expect(Top).to receive(:new).and_wrap_original do |original_method, *arguments, &block|
51
- original_method.call(*arguments, &block).tap do |instance|
52
- expect(instance).to receive(:call)
53
- end
54
- end
55
-
56
- Top.call([])
57
- end
58
-
59
- it "should use default value" do
60
- top = Top[]
61
- expect(top.options[:configuration]).to be == 'TEAPOT_CONFIGURATION'
62
- end
63
-
64
- it "can update options" do
65
- top = Top[]
66
- expect(top.options[:configuration]).to be == 'TEAPOT_CONFIGURATION'
67
-
68
- top = top['--verbose']
69
- expect(top.options[:configuration]).to be == 'TEAPOT_CONFIGURATION'
70
- expect(top.options[:logging]).to be == :verbose
71
- end
72
-
73
- it "should parse a simple command" do
74
- top = Top["-c", "path", "bottom", "foobar", "A", "B", "--", "args", "args"]
75
-
76
- expect(top.options[:configuration]).to be == 'path'
77
- expect(top.command.class).to be == Bottom
78
- expect(top.command.project_name).to be == 'foobar'
79
- expect(top.command.packages).to be == ['A', 'B']
80
- expect(top.command.argv).to be == ["args", "args"]
81
- end
82
-
83
- it "should generate documentation" do
84
- top = Top[]
85
- buffer = StringIO.new
86
- top.print_usage(output: buffer)
87
-
88
- expect(buffer.string).to be_include(Top.description)
89
- end
90
- end
91
- end
@@ -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::Many do
24
- let(:default) {["1", "2", "3"]}
25
- let(:input) {["2", "3", "--else"]}
26
-
27
- subject{described_class.new(:items, "some items", default: default)}
28
-
29
- it "has string representation" do
30
- expect(subject.to_s).to be == "<items...>"
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", "3"]
47
- expect(input).to be == ["--else"]
48
- end
49
- end
@@ -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
@@ -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
@@ -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
@@ -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