bovem 2.4.1 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/Gemfile +1 -1
- data/README.md +98 -2
- data/bovem.gemspec +3 -3
- data/doc/Bovem.html +25 -6
- data/doc/Bovem/Application.html +3057 -0
- data/doc/Bovem/Command.html +7031 -0
- data/doc/Bovem/CommandMethods.html +125 -0
- data/doc/Bovem/CommandMethods/Children.html +1285 -0
- data/doc/Bovem/CommandMethods/Help.html +209 -0
- data/doc/Bovem/Configuration.html +3 -3
- data/doc/Bovem/Console.html +8 -8
- data/doc/Bovem/ConsoleMethods.html +3 -3
- data/doc/Bovem/ConsoleMethods/Interactions.html +3 -3
- data/doc/Bovem/ConsoleMethods/Interactions/ClassMethods.html +3 -3
- data/doc/Bovem/ConsoleMethods/Logging.html +4 -4
- data/doc/Bovem/ConsoleMethods/Logging/ClassMethods.html +3 -3
- data/doc/Bovem/ConsoleMethods/Output.html +3 -3
- data/doc/Bovem/ConsoleMethods/StyleHandling.html +4 -4
- data/doc/Bovem/ConsoleMethods/StyleHandling/ClassMethods.html +8 -8
- data/doc/Bovem/Errors.html +4 -4
- data/doc/Bovem/Errors/Error.html +631 -0
- data/doc/Bovem/Errors/InvalidConfiguration.html +3 -3
- data/doc/Bovem/Errors/InvalidLogger.html +3 -3
- data/doc/Bovem/Localizer.html +376 -0
- data/doc/Bovem/Logger.html +64 -160
- data/doc/Bovem/Option.html +7009 -0
- data/doc/Bovem/Parser.html +276 -0
- data/doc/Bovem/ParserMethods.html +125 -0
- data/doc/Bovem/ParserMethods/General.html +134 -0
- data/doc/Bovem/ParserMethods/General/ClassMethods.html +574 -0
- data/doc/Bovem/Shell.html +8 -8
- data/doc/Bovem/ShellMethods.html +3 -3
- data/doc/Bovem/ShellMethods/Directories.html +3 -3
- data/doc/Bovem/ShellMethods/Execute.html +3 -3
- data/doc/Bovem/ShellMethods/General.html +3 -3
- data/doc/Bovem/ShellMethods/Read.html +3 -3
- data/doc/Bovem/ShellMethods/Write.html +3 -3
- data/doc/Bovem/Version.html +6 -6
- data/doc/_index.html +119 -11
- data/doc/class_list.html +1 -1
- data/doc/file.README.html +98 -5
- data/doc/frames.html +1 -1
- data/doc/index.html +98 -5
- data/doc/method_list.html +476 -26
- data/doc/top-level-namespace.html +3 -3
- data/lib/bovem.rb +8 -1
- data/lib/bovem/application.rb +158 -0
- data/lib/bovem/command.rb +529 -0
- data/lib/bovem/console.rb +8 -8
- data/lib/bovem/errors.rb +27 -0
- data/lib/bovem/localizer.rb +27 -0
- data/lib/bovem/logger.rb +2 -8
- data/lib/bovem/option.rb +250 -0
- data/lib/bovem/parser.rb +317 -0
- data/lib/bovem/shell.rb +2 -2
- data/lib/bovem/version.rb +3 -3
- data/locales/en.yml +33 -0
- data/locales/it.yml +33 -0
- data/spec/bovem/application_spec.rb +170 -0
- data/spec/bovem/command_spec.rb +526 -0
- data/spec/bovem/configuration_spec.rb +4 -4
- data/spec/bovem/console_spec.rb +22 -22
- data/spec/bovem/errors_spec.rb +18 -0
- data/spec/bovem/logger_spec.rb +22 -12
- data/spec/bovem/option_spec.rb +307 -0
- data/spec/bovem/parser_spec.rb +126 -0
- data/spec/bovem/shell_spec.rb +4 -4
- metadata +32 -5
@@ -0,0 +1,126 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# This file is part of the bovem gem. Copyright (C) 2013 and above Shogun <shogun_panda@me.com>.
|
4
|
+
# Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
|
5
|
+
#
|
6
|
+
|
7
|
+
require "spec_helper"
|
8
|
+
|
9
|
+
describe Bovem::Parser do
|
10
|
+
let(:application) {
|
11
|
+
Bovem::Application.new do
|
12
|
+
command :abc do
|
13
|
+
action do
|
14
|
+
end
|
15
|
+
|
16
|
+
command :def do
|
17
|
+
action do |command|
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
option :boolean, ["b", "boolean"], help: "BOOLEAN"
|
23
|
+
option :string, [nil, "string"], type: String, meta: "STRING", help: "STRING"
|
24
|
+
option :integer, ["i", nil], type: Integer, help: "INTEGER"
|
25
|
+
option :float, [nil, nil], type: Float, help: "FLOAT"
|
26
|
+
option :array, ["a", "array"], type: Array, help: "ARRAY"
|
27
|
+
option :choice, ["c", "choice"], type: String, help: "ARRAY", validator: ["yes", "no"]
|
28
|
+
option :regexp, ["r", "regexp"], type: String, help: "REGEXP", validator: /yes|no/i
|
29
|
+
option :action, ["A"] do |_, command|
|
30
|
+
p "[OPTION] BLOCK"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
}
|
34
|
+
|
35
|
+
let(:command) {
|
36
|
+
c = Bovem::Command.new
|
37
|
+
c.application = application
|
38
|
+
c
|
39
|
+
}
|
40
|
+
|
41
|
+
describe ".smart_join" do
|
42
|
+
it "should correctly join arrays" do
|
43
|
+
expect(Bovem::Parser.smart_join([])).to eq("")
|
44
|
+
expect(Bovem::Parser.smart_join(["A"], ", ", " and ", nil)).to eq("A")
|
45
|
+
expect(Bovem::Parser.smart_join(1, ", ", " and ", nil)).to eq("1")
|
46
|
+
expect(Bovem::Parser.smart_join(["A", 1], ", ", " and ", nil)).to eq("A and 1")
|
47
|
+
expect(Bovem::Parser.smart_join(["A", 1, true], ", ", " and ", nil)).to eq("A, 1 and true")
|
48
|
+
expect(Bovem::Parser.smart_join(["A", "B", "C"], "-", " and ", nil)).to eq("A-B and C")
|
49
|
+
expect(Bovem::Parser.smart_join(["A", "B", "C"], "-", "@", nil)).to eq("A-B@C")
|
50
|
+
expect(Bovem::Parser.smart_join(["A", "B", "C"], ", ", " and ", "@")).to eq("@A@, @B@ and @C@")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe ".find_command" do
|
55
|
+
it "should find commands" do
|
56
|
+
args = ["A", "B", "C"]
|
57
|
+
s1 = command.command("abc")
|
58
|
+
s2 = command.command("abd")
|
59
|
+
s1.command("def")
|
60
|
+
|
61
|
+
expect(Bovem::Parser.find_command("abc", command, args)).to eq({name: "abc", args: args})
|
62
|
+
expect(Bovem::Parser.find_command("abc:def", command, args)).to eq({name: "abc", args: ["def"] + args})
|
63
|
+
expect(Bovem::Parser.find_command("abc def", command, args, " ")).to eq({name: "abc", args: ["def"] + args})
|
64
|
+
expect(Bovem::Parser.find_command("d", s1, args)).to eq({name: "def", args: args})
|
65
|
+
expect{ Bovem::Parser.find_command("ab", command, args) }.to raise_error(Bovem::Errors::Error)
|
66
|
+
expect(Bovem::Parser.find_command("abc", s2, args)).to be_nil
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe ".parse" do
|
71
|
+
it "should instantiate a parser and then parse" do
|
72
|
+
expect(Bovem::Parser).to receive(:new).and_call_original
|
73
|
+
expect_any_instance_of(Bovem::Parser).to receive(:parse).with("COMMAND", "ARGS")
|
74
|
+
Bovem::Parser.parse("COMMAND", "ARGS")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "#parse" do
|
79
|
+
it "should iterate options" do
|
80
|
+
expect(application.options).to receive(:each_pair).exactly(2)
|
81
|
+
Bovem::Parser.parse(application, [])
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should set good values" do
|
85
|
+
expect(application.options["boolean"]).to receive("set").with(true)
|
86
|
+
expect(application.options["string"]).to receive("set").with("A")
|
87
|
+
expect(application.options["integer"]).to receive("set").with(1)
|
88
|
+
expect(application.options["float"]).to receive("set").with(2.0)
|
89
|
+
expect(application.options["array"]).to receive("set").with(["B", "C"])
|
90
|
+
expect(application.options["choice"]).to receive("set").with("yes")
|
91
|
+
expect(application.options["regexp"]).to receive("set").with("no")
|
92
|
+
expect(application.options["action"]).to receive("execute_action")
|
93
|
+
Bovem::Parser.parse(application, ["-b", "-s", "A", "-i", "1", "-f", "2.0", "-a", "B,C", "-c", "yes", "-r", "no", "-A"])
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should complain about invalid or additional values" do
|
97
|
+
expect { Bovem::Parser.parse(application, ["-b=f"]) }.to raise_error(Bovem::Errors::Error)
|
98
|
+
expect { Bovem::Parser.parse(application, ["-s"]) }.to raise_error(Bovem::Errors::Error)
|
99
|
+
expect { Bovem::Parser.parse(application, ["-i", "A"]) }.to raise_error(Bovem::Errors::Error)
|
100
|
+
expect { Bovem::Parser.parse(application, ["-f", "A"]) }.to raise_error(Bovem::Errors::Error)
|
101
|
+
expect { Bovem::Parser.parse(application, ["-c", "B"]) }.to raise_error(Bovem::Errors::Error)
|
102
|
+
expect { Bovem::Parser.parse(application, ["-r", "C"]) }.to raise_error(Bovem::Errors::Error)
|
103
|
+
expect { Bovem::Parser.parse(application, ["-R", "C"]) }.to raise_error(Bovem::Errors::Error)
|
104
|
+
application.option("R", [], {required: true})
|
105
|
+
expect { Bovem::Parser.parse(application, ["-b"]) }.to raise_error(Bovem::Errors::Error) # Because we're missing a required option
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should complain about duplicate options" do
|
109
|
+
application.option(:boolean2)
|
110
|
+
expect { Bovem::Parser.parse(application, ["-b"]) }.to raise_error(Bovem::Errors::Error)
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should return the command to execute" do
|
114
|
+
expect(Bovem::Parser.parse(application, ["a", "OTHER"])).to eq({name: "abc", args: ["OTHER"]})
|
115
|
+
expect(Bovem::Parser.parse(application, ["ab:d", "OTHER"])).to eq({name: "abc", args: ["d", "OTHER"]})
|
116
|
+
expect(Bovem::Parser.parse(application, ["abc", "d", "OTHER"])).to eq({name: "abc", args: ["d", "OTHER"]})
|
117
|
+
expect(Bovem::Parser.parse(application, ["d", "OTHER"])).to eq(nil)
|
118
|
+
|
119
|
+
application.clear_options
|
120
|
+
expect(Bovem::Parser.parse(application, ["a", "OTHER"])).to eq({name: "abc", args: ["OTHER"]})
|
121
|
+
expect(Bovem::Parser.parse(application, ["d:d", "OTHER"])).to eq(nil)
|
122
|
+
expect(Bovem::Parser.parse(application, ["d d", "OTHER"])).to eq(nil)
|
123
|
+
expect(Bovem::Parser.parse(application, ["d", "d", "OTHER"])).to eq(nil)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
data/spec/bovem/shell_spec.rb
CHANGED
@@ -8,7 +8,7 @@ require "spec_helper"
|
|
8
8
|
|
9
9
|
describe Bovem::Shell do
|
10
10
|
let(:shell) {
|
11
|
-
s =
|
11
|
+
s = Bovem::Shell.new
|
12
12
|
s.i18n = :en
|
13
13
|
s
|
14
14
|
}
|
@@ -24,14 +24,14 @@ describe Bovem::Shell do
|
|
24
24
|
|
25
25
|
describe ".instance" do
|
26
26
|
it "should always return the same instance" do
|
27
|
-
instance =
|
28
|
-
expect(
|
27
|
+
instance = Bovem::Shell.instance
|
28
|
+
expect(Bovem::Shell.instance).to be(instance)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
32
|
describe "#initialize" do
|
33
33
|
it "should correctly set defaults" do
|
34
|
-
expect(shell.console).to eq(
|
34
|
+
expect(shell.console).to eq(Bovem::Console.instance)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bovem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shogun
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 3.3.
|
19
|
+
version: 3.3.5
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 3.3.
|
26
|
+
version: 3.3.5
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: open4
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,7 +38,7 @@ dependencies:
|
|
38
38
|
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 1.3.0
|
41
|
-
description: A collection of utilities for developers.
|
41
|
+
description: A command line manager and a collection of utilities for developers.
|
42
42
|
email:
|
43
43
|
- shogun_panda@me.com
|
44
44
|
executables: []
|
@@ -54,6 +54,11 @@ files:
|
|
54
54
|
- Rakefile
|
55
55
|
- bovem.gemspec
|
56
56
|
- doc/Bovem.html
|
57
|
+
- doc/Bovem/Application.html
|
58
|
+
- doc/Bovem/Command.html
|
59
|
+
- doc/Bovem/CommandMethods.html
|
60
|
+
- doc/Bovem/CommandMethods/Children.html
|
61
|
+
- doc/Bovem/CommandMethods/Help.html
|
57
62
|
- doc/Bovem/Configuration.html
|
58
63
|
- doc/Bovem/Console.html
|
59
64
|
- doc/Bovem/ConsoleMethods.html
|
@@ -65,9 +70,16 @@ files:
|
|
65
70
|
- doc/Bovem/ConsoleMethods/StyleHandling.html
|
66
71
|
- doc/Bovem/ConsoleMethods/StyleHandling/ClassMethods.html
|
67
72
|
- doc/Bovem/Errors.html
|
73
|
+
- doc/Bovem/Errors/Error.html
|
68
74
|
- doc/Bovem/Errors/InvalidConfiguration.html
|
69
75
|
- doc/Bovem/Errors/InvalidLogger.html
|
76
|
+
- doc/Bovem/Localizer.html
|
70
77
|
- doc/Bovem/Logger.html
|
78
|
+
- doc/Bovem/Option.html
|
79
|
+
- doc/Bovem/Parser.html
|
80
|
+
- doc/Bovem/ParserMethods.html
|
81
|
+
- doc/Bovem/ParserMethods/General.html
|
82
|
+
- doc/Bovem/ParserMethods/General/ClassMethods.html
|
71
83
|
- doc/Bovem/Shell.html
|
72
84
|
- doc/Bovem/ShellMethods.html
|
73
85
|
- doc/Bovem/ShellMethods/Directories.html
|
@@ -91,17 +103,27 @@ files:
|
|
91
103
|
- doc/method_list.html
|
92
104
|
- doc/top-level-namespace.html
|
93
105
|
- lib/bovem.rb
|
106
|
+
- lib/bovem/application.rb
|
107
|
+
- lib/bovem/command.rb
|
94
108
|
- lib/bovem/configuration.rb
|
95
109
|
- lib/bovem/console.rb
|
96
110
|
- lib/bovem/errors.rb
|
111
|
+
- lib/bovem/localizer.rb
|
97
112
|
- lib/bovem/logger.rb
|
113
|
+
- lib/bovem/option.rb
|
114
|
+
- lib/bovem/parser.rb
|
98
115
|
- lib/bovem/shell.rb
|
99
116
|
- lib/bovem/version.rb
|
100
117
|
- locales/en.yml
|
101
118
|
- locales/it.yml
|
119
|
+
- spec/bovem/application_spec.rb
|
120
|
+
- spec/bovem/command_spec.rb
|
102
121
|
- spec/bovem/configuration_spec.rb
|
103
122
|
- spec/bovem/console_spec.rb
|
123
|
+
- spec/bovem/errors_spec.rb
|
104
124
|
- spec/bovem/logger_spec.rb
|
125
|
+
- spec/bovem/option_spec.rb
|
126
|
+
- spec/bovem/parser_spec.rb
|
105
127
|
- spec/bovem/shell_spec.rb
|
106
128
|
- spec/coverage_helper.rb
|
107
129
|
- spec/spec_helper.rb
|
@@ -127,11 +149,16 @@ rubyforge_project: bovem
|
|
127
149
|
rubygems_version: 2.0.6
|
128
150
|
signing_key:
|
129
151
|
specification_version: 4
|
130
|
-
summary: A collection of utilities for developers.
|
152
|
+
summary: A command line manager and a collection of utilities for developers.
|
131
153
|
test_files:
|
154
|
+
- spec/bovem/application_spec.rb
|
155
|
+
- spec/bovem/command_spec.rb
|
132
156
|
- spec/bovem/configuration_spec.rb
|
133
157
|
- spec/bovem/console_spec.rb
|
158
|
+
- spec/bovem/errors_spec.rb
|
134
159
|
- spec/bovem/logger_spec.rb
|
160
|
+
- spec/bovem/option_spec.rb
|
161
|
+
- spec/bovem/parser_spec.rb
|
135
162
|
- spec/bovem/shell_spec.rb
|
136
163
|
- spec/coverage_helper.rb
|
137
164
|
- spec/spec_helper.rb
|