hammer_cli 0.0.18 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -314
- data/bin/hammer +45 -6
- data/config/cli.modules.d/module_config_template.yml +4 -0
- data/config/cli_config.template.yml +9 -11
- data/doc/developer_docs.md +1 -0
- data/doc/i18n.md +85 -0
- data/doc/installation.md +321 -0
- data/lib/hammer_cli.rb +3 -0
- data/lib/hammer_cli/abstract.rb +15 -24
- data/lib/hammer_cli/apipie/command.rb +13 -7
- data/lib/hammer_cli/apipie/options.rb +14 -16
- data/lib/hammer_cli/apipie/read_command.rb +6 -1
- data/lib/hammer_cli/apipie/resource.rb +48 -58
- data/lib/hammer_cli/apipie/write_command.rb +5 -1
- data/lib/hammer_cli/completer.rb +77 -21
- data/lib/hammer_cli/connection.rb +44 -0
- data/lib/hammer_cli/exception_handler.rb +15 -4
- data/lib/hammer_cli/exceptions.rb +6 -0
- data/lib/hammer_cli/i18n.rb +95 -0
- data/lib/hammer_cli/logger.rb +3 -3
- data/lib/hammer_cli/main.rb +12 -11
- data/lib/hammer_cli/modules.rb +19 -6
- data/lib/hammer_cli/options/normalizers.rb +42 -7
- data/lib/hammer_cli/options/option_definition.rb +2 -2
- data/lib/hammer_cli/output.rb +1 -0
- data/lib/hammer_cli/output/adapter/abstract.rb +20 -0
- data/lib/hammer_cli/output/adapter/base.rb +49 -78
- data/lib/hammer_cli/output/adapter/csv.rb +5 -5
- data/lib/hammer_cli/output/adapter/table.rb +41 -10
- data/lib/hammer_cli/output/dsl.rb +1 -1
- data/lib/hammer_cli/output/field_filter.rb +21 -0
- data/lib/hammer_cli/output/fields.rb +44 -78
- data/lib/hammer_cli/output/formatters.rb +38 -0
- data/lib/hammer_cli/settings.rb +28 -6
- data/lib/hammer_cli/shell.rb +58 -57
- data/lib/hammer_cli/utils.rb +14 -0
- data/lib/hammer_cli/validator.rb +5 -5
- data/lib/hammer_cli/version.rb +1 -1
- data/locale/Makefile +64 -0
- data/locale/hammer-cli.pot +203 -0
- data/locale/zanata.xml +29 -0
- data/test/unit/apipie/command_test.rb +42 -25
- data/test/unit/apipie/read_command_test.rb +10 -7
- data/test/unit/apipie/write_command_test.rb +9 -8
- data/test/unit/completer_test.rb +206 -21
- data/test/unit/connection_test.rb +68 -0
- data/test/unit/fixtures/apipie/architectures.json +153 -0
- data/test/unit/fixtures/apipie/documented.json +79 -0
- data/test/unit/fixtures/json_input/invalid.json +12 -0
- data/test/unit/fixtures/json_input/valid.json +12 -0
- data/test/unit/history_test.rb +71 -0
- data/test/unit/main_test.rb +9 -0
- data/test/unit/modules_test.rb +22 -6
- data/test/unit/options/field_filter_test.rb +27 -0
- data/test/unit/options/normalizers_test.rb +53 -0
- data/test/unit/output/adapter/base_test.rb +162 -10
- data/test/unit/output/adapter/csv_test.rb +16 -3
- data/test/unit/output/adapter/table_test.rb +97 -13
- data/test/unit/output/dsl_test.rb +74 -6
- data/test/unit/output/fields_test.rb +93 -62
- data/test/unit/output/formatters_test.rb +47 -0
- data/test/unit/settings_test.rb +35 -4
- data/test/unit/utils_test.rb +45 -0
- metadata +85 -4
- data/test/unit/apipie/fake_api.rb +0 -101
data/locale/zanata.xml
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
2
|
+
<config xmlns="http://zanata.org/namespace/config/">
|
3
|
+
<url>https://translate.zanata.org/zanata/</url>
|
4
|
+
<project>satellite6-hammer-cli</project>
|
5
|
+
<project-version>6.0</project-version>
|
6
|
+
<project-type>podir</project-type>
|
7
|
+
<locales>
|
8
|
+
<locale>fr</locale>
|
9
|
+
<locale>it</locale>
|
10
|
+
<locale>ja</locale>
|
11
|
+
<locale>ko</locale>
|
12
|
+
<locale>gu</locale>
|
13
|
+
<locale>hi</locale>
|
14
|
+
<locale>mr</locale>
|
15
|
+
<locale>or</locale>
|
16
|
+
<locale>ru</locale>
|
17
|
+
<locale>te</locale>
|
18
|
+
<locale>pa</locale>
|
19
|
+
<locale>kn</locale>
|
20
|
+
<locale>de</locale>
|
21
|
+
<locale>es</locale>
|
22
|
+
<locale>gl</locale>
|
23
|
+
<locale map-from="pt_BR">pt-BR</locale>
|
24
|
+
<locale map-from="bn">bn-IN</locale>
|
25
|
+
<locale map-from="ta">ta-IN</locale>
|
26
|
+
<locale map-from="zh_CN">zh-Hans-CN</locale>
|
27
|
+
<locale map-from="zh_TW">zh-Hant-TW</locale>
|
28
|
+
</locales>
|
29
|
+
</config>
|
@@ -1,15 +1,20 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '../test_helper')
|
2
|
-
require File.join(File.dirname(__FILE__), 'fake_api')
|
3
2
|
|
4
3
|
|
5
4
|
describe HammerCLI::Apipie::Command do
|
6
5
|
|
7
|
-
class
|
6
|
+
class TestCommand < HammerCLI::Apipie::Command
|
7
|
+
def self.resource_config
|
8
|
+
{ :apidoc_cache_dir => 'test/unit/fixtures/apipie', :apidoc_cache_name => 'architectures' }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class ParentCommand < TestCommand
|
8
13
|
action :show
|
9
14
|
end
|
10
15
|
|
11
|
-
class CommandA <
|
12
|
-
resource
|
16
|
+
class CommandA < TestCommand
|
17
|
+
resource :architectures, :index
|
13
18
|
|
14
19
|
class CommandB < ParentCommand
|
15
20
|
end
|
@@ -18,17 +23,20 @@ describe HammerCLI::Apipie::Command do
|
|
18
23
|
class CommandC < CommandA
|
19
24
|
end
|
20
25
|
|
21
|
-
|
22
26
|
let(:ctx) { { :adapter => :silent, :interactive => false } }
|
23
|
-
let(:cmd_class) {
|
27
|
+
let(:cmd_class) { TestCommand.dup }
|
24
28
|
let(:cmd) { cmd_class.new("", ctx) }
|
25
29
|
|
30
|
+
before :each do
|
31
|
+
HammerCLI::Connection.drop_all
|
32
|
+
end
|
33
|
+
|
26
34
|
context "setting identifiers" do
|
27
35
|
|
28
36
|
let(:option_switches) { cmd_class.declared_options.map(&:switches).sort }
|
29
37
|
let(:option_attribute_names) { cmd_class.declared_options.map(&:attribute_name).sort }
|
30
38
|
|
31
|
-
class Cmd1 <
|
39
|
+
class Cmd1 < TestCommand
|
32
40
|
identifiers :id, :name, :label
|
33
41
|
apipie_options
|
34
42
|
end
|
@@ -107,31 +115,31 @@ describe HammerCLI::Apipie::Command do
|
|
107
115
|
context "setting resources" do
|
108
116
|
|
109
117
|
it "should set resource and action together" do
|
110
|
-
cmd_class.resource
|
118
|
+
cmd_class.resource :architectures, :index
|
111
119
|
|
112
|
-
cmd.resource.
|
113
|
-
cmd_class.resource.
|
120
|
+
cmd.resource.name.must_equal :architectures
|
121
|
+
cmd_class.resource.name.must_equal :architectures
|
114
122
|
|
115
123
|
cmd.action.must_equal :index
|
116
124
|
cmd_class.action.must_equal :index
|
117
125
|
end
|
118
126
|
|
119
127
|
it "should set resource alone" do
|
120
|
-
cmd_class.resource
|
128
|
+
cmd_class.resource :architectures
|
121
129
|
|
122
|
-
cmd.resource.
|
123
|
-
cmd_class.resource.
|
130
|
+
cmd.resource.name.must_equal :architectures
|
131
|
+
cmd_class.resource.name.must_equal :architectures
|
124
132
|
|
125
133
|
cmd.action.must_equal nil
|
126
134
|
cmd_class.action.must_equal nil
|
127
135
|
end
|
128
136
|
|
129
137
|
it "should set resource and action alone" do
|
130
|
-
cmd_class.resource
|
138
|
+
cmd_class.resource :architectures
|
131
139
|
cmd_class.action :index
|
132
140
|
|
133
|
-
cmd.resource.
|
134
|
-
cmd_class.resource.
|
141
|
+
cmd.resource.name.must_equal :architectures
|
142
|
+
cmd_class.resource.name.must_equal :architectures
|
135
143
|
|
136
144
|
cmd.action.must_equal :index
|
137
145
|
cmd_class.action.must_equal :index
|
@@ -145,25 +153,34 @@ describe HammerCLI::Apipie::Command do
|
|
145
153
|
|
146
154
|
it "looks up resource in the class' modules" do
|
147
155
|
cmd_b = CommandA::CommandB.new("", ctx)
|
148
|
-
cmd_b.resource.
|
149
|
-
cmd_b.class.resource.
|
156
|
+
cmd_b.resource.name.must_equal :architectures
|
157
|
+
cmd_b.class.resource.name.must_equal :architectures
|
150
158
|
end
|
151
159
|
|
152
160
|
it "looks up resource in the superclass" do
|
153
161
|
cmd_c = CommandC.new("", ctx)
|
154
|
-
cmd_c.resource.
|
155
|
-
cmd_c.class.resource.
|
162
|
+
cmd_c.resource.name.must_equal :architectures
|
163
|
+
cmd_c.class.resource.name.must_equal :architectures
|
156
164
|
end
|
157
165
|
end
|
158
166
|
|
159
167
|
context "apipie generated options" do
|
160
168
|
|
169
|
+
class DocumentedCommand < HammerCLI::Apipie::Command
|
170
|
+
def self.resource_config
|
171
|
+
{ :apidoc_cache_dir => 'test/unit/fixtures/apipie', :apidoc_cache_name => 'documented' }
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
let(:cmd_class) { DocumentedCommand.dup }
|
176
|
+
let(:cmd) { cmd_class.new("", ctx) }
|
177
|
+
|
161
178
|
context "with one simple param" do
|
162
179
|
|
163
180
|
let(:option) { cmd_class.declared_options[0] }
|
164
181
|
|
165
182
|
before :each do
|
166
|
-
cmd_class.resource
|
183
|
+
cmd_class.resource :documented, :index
|
167
184
|
cmd_class.apipie_options
|
168
185
|
end
|
169
186
|
|
@@ -186,7 +203,7 @@ describe HammerCLI::Apipie::Command do
|
|
186
203
|
|
187
204
|
context "required options" do
|
188
205
|
before :each do
|
189
|
-
cmd_class.resource
|
206
|
+
cmd_class.resource :documented, :create
|
190
207
|
cmd_class.apipie_options
|
191
208
|
end
|
192
209
|
|
@@ -199,7 +216,7 @@ describe HammerCLI::Apipie::Command do
|
|
199
216
|
|
200
217
|
context "with hash params" do
|
201
218
|
before :each do
|
202
|
-
cmd_class.resource
|
219
|
+
cmd_class.resource :documented, :create
|
203
220
|
cmd_class.apipie_options
|
204
221
|
end
|
205
222
|
|
@@ -214,7 +231,7 @@ describe HammerCLI::Apipie::Command do
|
|
214
231
|
|
215
232
|
context "array params" do
|
216
233
|
before :each do
|
217
|
-
cmd_class.resource
|
234
|
+
cmd_class.resource :documented, :create
|
218
235
|
cmd_class.apipie_options
|
219
236
|
end
|
220
237
|
|
@@ -244,7 +261,7 @@ describe HammerCLI::Apipie::Command do
|
|
244
261
|
|
245
262
|
context "filtering options" do
|
246
263
|
before :each do
|
247
|
-
cmd_class.resource
|
264
|
+
cmd_class.resource :documented, :create
|
248
265
|
end
|
249
266
|
|
250
267
|
it "should skip filtered options" do
|
@@ -1,10 +1,15 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '../test_helper')
|
2
|
-
require File.join(File.dirname(__FILE__), 'fake_api')
|
3
2
|
|
4
3
|
|
5
4
|
describe HammerCLI::Apipie::ReadCommand do
|
6
5
|
|
7
|
-
|
6
|
+
class TestReadCommand < HammerCLI::Apipie::ReadCommand
|
7
|
+
def self.resource_config
|
8
|
+
{ :apidoc_cache_dir => 'test/unit/fixtures/apipie', :apidoc_cache_name => 'architectures' }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:cmd_class) { TestReadCommand.dup }
|
8
13
|
let(:cmd) { cmd_class.new("", { :adapter => :silent, :interactive => false }) }
|
9
14
|
let(:cmd_run) { cmd.run([]) }
|
10
15
|
|
@@ -16,11 +21,9 @@ describe HammerCLI::Apipie::ReadCommand do
|
|
16
21
|
context "resource defined" do
|
17
22
|
|
18
23
|
before :each do
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
arch.expects(:some_action).returns([])
|
23
|
-
FakeApi::Resources::Architecture.stubs(:new).returns(arch)
|
24
|
+
HammerCLI::Connection.drop_all
|
25
|
+
ApipieBindings::API.any_instance.stubs(:call).returns([])
|
26
|
+
cmd_class.resource :architectures, :index
|
24
27
|
end
|
25
28
|
|
26
29
|
it "should perform a call to api when resource is defined" do
|
@@ -1,11 +1,14 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '../test_helper')
|
2
|
-
require File.join(File.dirname(__FILE__), 'fake_api')
|
3
2
|
|
4
3
|
describe HammerCLI::Apipie::WriteCommand do
|
5
4
|
|
5
|
+
class TestWriteCommand < HammerCLI::Apipie::WriteCommand
|
6
|
+
def self.resource_config
|
7
|
+
{ :apidoc_cache_dir => 'test/unit/fixtures/apipie', :apidoc_cache_name => 'architectures' }
|
8
|
+
end
|
9
|
+
end
|
6
10
|
|
7
|
-
let(:
|
8
|
-
let(:cmd) { HammerCLI::Apipie::WriteCommand.new("", ctx) }
|
11
|
+
let(:cmd) { TestWriteCommand.new("") }
|
9
12
|
let(:cmd_run) { cmd.run([]) }
|
10
13
|
|
11
14
|
it "should raise exception when no action is defined" do
|
@@ -16,11 +19,9 @@ describe HammerCLI::Apipie::WriteCommand do
|
|
16
19
|
context "resource defined" do
|
17
20
|
|
18
21
|
before :each do
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
arch.expects(:some_action).returns([])
|
23
|
-
FakeApi::Resources::Architecture.stubs(:new).returns(arch)
|
22
|
+
HammerCLI::Connection.drop_all
|
23
|
+
ApipieBindings::API.any_instance.stubs(:call).returns([])
|
24
|
+
cmd.class.resource :architectures, :index
|
24
25
|
end
|
25
26
|
|
26
27
|
it "should perform a call to api when resource is defined" do
|
data/test/unit/completer_test.rb
CHANGED
@@ -2,40 +2,198 @@ require File.join(File.dirname(__FILE__), 'test_helper')
|
|
2
2
|
require 'tempfile'
|
3
3
|
|
4
4
|
|
5
|
-
describe HammerCLI::
|
5
|
+
describe HammerCLI::CompleterWord do
|
6
|
+
|
7
|
+
|
8
|
+
describe "quote" do
|
9
|
+
it "returns empty string for empty word" do
|
10
|
+
word = HammerCLI::CompleterWord.new('')
|
11
|
+
word.quote.must_equal ""
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns empty string for word without quotes" do
|
15
|
+
word = HammerCLI::CompleterWord.new('word')
|
16
|
+
word.quote.must_equal ""
|
17
|
+
end
|
18
|
+
|
19
|
+
it "recognizes double quotes" do
|
20
|
+
word = HammerCLI::CompleterWord.new('"word')
|
21
|
+
word.quote.must_equal '"'
|
22
|
+
end
|
23
|
+
|
24
|
+
it "recognizes single quotes" do
|
25
|
+
word = HammerCLI::CompleterWord.new('\'word')
|
26
|
+
word.quote.must_equal "'"
|
27
|
+
end
|
28
|
+
end
|
6
29
|
|
7
|
-
|
8
|
-
|
30
|
+
describe "quoted?" do
|
31
|
+
it "returns false for an unquoted word" do
|
32
|
+
word = HammerCLI::CompleterWord.new('word')
|
33
|
+
word.quoted?.must_equal false
|
34
|
+
end
|
35
|
+
|
36
|
+
it "returns true for double quotes" do
|
37
|
+
word = HammerCLI::CompleterWord.new('"word')
|
38
|
+
word.quoted?.must_equal true
|
39
|
+
end
|
40
|
+
|
41
|
+
it "returns true for single quotes" do
|
42
|
+
word = HammerCLI::CompleterWord.new('\'word')
|
43
|
+
word.quoted?.must_equal true
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "complete?" do
|
48
|
+
it "considers a word without quotes complete" do
|
49
|
+
word = HammerCLI::CompleterWord.new('word')
|
50
|
+
word.complete?.must_equal false
|
51
|
+
end
|
52
|
+
|
53
|
+
it "considers a word without quotes ending with space incomplete" do
|
54
|
+
word = HammerCLI::CompleterWord.new('word ')
|
55
|
+
word.complete?.must_equal true
|
56
|
+
end
|
57
|
+
|
58
|
+
it "considers open double quotes incomplete" do
|
59
|
+
word = HammerCLI::CompleterWord.new('"word')
|
60
|
+
word.complete?.must_equal false
|
61
|
+
end
|
62
|
+
|
63
|
+
it "considers open double quotes with spaces incomplete" do
|
64
|
+
word = HammerCLI::CompleterWord.new('"word ')
|
65
|
+
word.complete?.must_equal false
|
66
|
+
end
|
67
|
+
|
68
|
+
it "considers closed double quotes complete" do
|
69
|
+
word = HammerCLI::CompleterWord.new('"word"')
|
70
|
+
word.complete?.must_equal true
|
71
|
+
end
|
72
|
+
|
73
|
+
it "considers open single quotes incomplete" do
|
74
|
+
word = HammerCLI::CompleterWord.new('\'word')
|
75
|
+
word.complete?.must_equal false
|
76
|
+
end
|
77
|
+
|
78
|
+
it "considers open single quotes with spaces incomplete" do
|
79
|
+
word = HammerCLI::CompleterWord.new('\'word ')
|
80
|
+
word.complete?.must_equal false
|
81
|
+
end
|
82
|
+
|
83
|
+
it "considers closed single quotes complete" do
|
84
|
+
word = HammerCLI::CompleterWord.new('\'word\'')
|
85
|
+
word.complete?.must_equal true
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
describe HammerCLI::CompleterLine do
|
9
92
|
|
10
93
|
context "splitting words" do
|
11
94
|
|
12
95
|
it "should split basic line" do
|
13
|
-
line = HammerCLI::CompleterLine.new(
|
96
|
+
line = HammerCLI::CompleterLine.new("architecture list --name arch")
|
14
97
|
line.must_equal ["architecture", "list", "--name", "arch"]
|
15
98
|
end
|
16
99
|
|
17
100
|
it "should split basic line with space at the end" do
|
18
|
-
line = HammerCLI::CompleterLine.new(
|
101
|
+
line = HammerCLI::CompleterLine.new("architecture list --name arch ")
|
19
102
|
line.must_equal ["architecture", "list", "--name", "arch"]
|
20
103
|
end
|
21
104
|
|
105
|
+
it "should split on equal sign" do
|
106
|
+
line = HammerCLI::CompleterLine.new("--name=arch")
|
107
|
+
line.must_equal ["--name", "arch"]
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should split when last character is equal sign" do
|
111
|
+
line = HammerCLI::CompleterLine.new("--name=")
|
112
|
+
line.must_equal ["--name"]
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should split on equal sign when quotes are used" do
|
116
|
+
line = HammerCLI::CompleterLine.new("--name='arch' ")
|
117
|
+
line.must_equal ["--name", "arch"]
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should split line with single quotes" do
|
121
|
+
line = HammerCLI::CompleterLine.new("--name 'arch' ")
|
122
|
+
line.must_equal ["--name", "arch"]
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should split line with double quotes" do
|
126
|
+
line = HammerCLI::CompleterLine.new("--name \"arch\"")
|
127
|
+
line.must_equal ["--name", "arch"]
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should split line with single quotes and space between" do
|
131
|
+
line = HammerCLI::CompleterLine.new("--name 'ar ch '")
|
132
|
+
line.must_equal ["--name", "ar ch "]
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should split line with one single quote and space between" do
|
136
|
+
line = HammerCLI::CompleterLine.new("--name 'ar ch ")
|
137
|
+
line.must_equal ["--name", "ar ch "]
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should split line with double quotes and space between" do
|
141
|
+
line = HammerCLI::CompleterLine.new("--name \"ar ch \"")
|
142
|
+
line.must_equal ["--name", "ar ch "]
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should split line with one double quote and space between" do
|
146
|
+
line = HammerCLI::CompleterLine.new("--name \"ar ch ")
|
147
|
+
line.must_equal ["--name", "ar ch "]
|
148
|
+
end
|
149
|
+
|
22
150
|
end
|
23
151
|
|
24
|
-
context "
|
152
|
+
context "line complete" do
|
153
|
+
|
154
|
+
it "should recongize incomplete line" do
|
155
|
+
line = HammerCLI::CompleterLine.new("architecture list --name arch")
|
156
|
+
line.complete?.must_equal false
|
157
|
+
end
|
158
|
+
|
159
|
+
it "should recongize complete line" do
|
160
|
+
line = HammerCLI::CompleterLine.new("architecture list --name arch ")
|
161
|
+
line.complete?.must_equal true
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should recongize complete line that ends with quotes" do
|
165
|
+
line = HammerCLI::CompleterLine.new("--name 'ar ch'")
|
166
|
+
line.complete?.must_equal true
|
167
|
+
end
|
25
168
|
|
26
|
-
it "should recongize
|
27
|
-
line = HammerCLI::CompleterLine.new(
|
28
|
-
line.
|
169
|
+
it "should recongize complete line that ends with quotes followed by space" do
|
170
|
+
line = HammerCLI::CompleterLine.new("--name 'ar ch' ")
|
171
|
+
line.complete?.must_equal true
|
29
172
|
end
|
30
173
|
|
31
|
-
it "should recongize
|
32
|
-
line = HammerCLI::CompleterLine.new(
|
33
|
-
line.
|
174
|
+
it "should recongize complete line that ends with double quotes" do
|
175
|
+
line = HammerCLI::CompleterLine.new("--name \"ar ch\"")
|
176
|
+
line.complete?.must_equal true
|
34
177
|
end
|
35
178
|
|
36
|
-
it "should recongize
|
179
|
+
it "should recongize one quote as incomplete" do
|
180
|
+
line = HammerCLI::CompleterLine.new("--name '")
|
181
|
+
line.complete?.must_equal false
|
182
|
+
end
|
183
|
+
|
184
|
+
it "should recongize one quote followed by space as incomplete" do
|
185
|
+
line = HammerCLI::CompleterLine.new("--name ' ")
|
186
|
+
line.complete?.must_equal false
|
187
|
+
end
|
188
|
+
|
189
|
+
it "should recongize one double quote as incomplete" do
|
190
|
+
line = HammerCLI::CompleterLine.new("--name \"")
|
191
|
+
line.complete?.must_equal false
|
192
|
+
end
|
193
|
+
|
194
|
+
it "should recongize empty line as complete" do
|
37
195
|
line = HammerCLI::CompleterLine.new("")
|
38
|
-
line.
|
196
|
+
line.complete?.must_equal true
|
39
197
|
end
|
40
198
|
|
41
199
|
end
|
@@ -55,7 +213,7 @@ describe HammerCLI::Completer do
|
|
55
213
|
end
|
56
214
|
|
57
215
|
def complete(val)
|
58
|
-
["small ", "tall "]
|
216
|
+
["small ", "tall ", "smel ly"]
|
59
217
|
end
|
60
218
|
|
61
219
|
end
|
@@ -103,6 +261,9 @@ describe HammerCLI::Completer do
|
|
103
261
|
let(:completer) { HammerCLI::Completer.new(FakeMainCmd) }
|
104
262
|
|
105
263
|
context "command completion" do
|
264
|
+
|
265
|
+
let(:ape_completions) { ["makkak ", "malpa ", "orangutan ", "--hairy ", "--weight ", "--height ", "-h ", "--help "] }
|
266
|
+
|
106
267
|
it "should offer all available commands" do
|
107
268
|
completer.complete("").sort.must_equal ["anabolic ", "ape ", "apocalypse ", "beast ", "-h ", "--help "].sort
|
108
269
|
end
|
@@ -120,30 +281,54 @@ describe HammerCLI::Completer do
|
|
120
281
|
end
|
121
282
|
|
122
283
|
it "should offer all available subcommands and options" do
|
123
|
-
completer.complete("ape ").sort.must_equal
|
284
|
+
completer.complete("ape ").sort.must_equal ape_completions.sort
|
124
285
|
end
|
125
286
|
|
126
287
|
it "should offer all available subcommands and options even if a flag has been passed" do
|
127
|
-
completer.complete("ape --hairy ").sort.must_equal
|
288
|
+
completer.complete("ape --hairy ").sort.must_equal ape_completions.sort
|
128
289
|
end
|
129
290
|
|
130
291
|
it "should offer all available subcommands and options even if an option has been passed" do
|
131
|
-
completer.complete("ape --weight 12kg ").sort.must_equal
|
292
|
+
completer.complete("ape --weight 12kg ").sort.must_equal ape_completions.sort
|
132
293
|
end
|
133
294
|
|
134
295
|
it "should offer all available subcommands and options even if an egual sign option has been passed" do
|
135
|
-
completer.complete("ape --weight=12kg ").sort.must_equal
|
296
|
+
completer.complete("ape --weight=12kg ").sort.must_equal ape_completions.sort
|
297
|
+
end
|
298
|
+
|
299
|
+
it "should offer all available subcommands and options when quoted value was passed" do
|
300
|
+
completer.complete("ape --weight '12 kg' ").sort.must_equal ape_completions.sort
|
301
|
+
end
|
302
|
+
|
303
|
+
it "should offer all available subcommands and options when double quoted value was passed" do
|
304
|
+
completer.complete("ape --weight \"12 kg\" ").sort.must_equal ape_completions.sort
|
305
|
+
end
|
306
|
+
|
307
|
+
it "should offer all available subcommands and options when quoted value with equal sign was passed" do
|
308
|
+
completer.complete("ape --weight='12 kg' ").sort.must_equal ape_completions.sort
|
136
309
|
end
|
137
310
|
end
|
138
311
|
|
139
312
|
|
140
313
|
context "option value completion" do
|
141
314
|
it "should complete option values" do
|
142
|
-
completer.complete("ape --height ").sort.must_equal ["small ", "tall "].sort
|
315
|
+
completer.complete("ape --height ").sort.must_equal ["small ", "tall ", "smel ly"].sort
|
316
|
+
end
|
317
|
+
|
318
|
+
it "should complete option values when equal sign is used" do
|
319
|
+
completer.complete("ape --height=").sort.must_equal ["small ", "tall ", "smel ly"].sort
|
143
320
|
end
|
144
321
|
|
145
322
|
it "should complete option values" do
|
146
|
-
completer.complete("ape --height s").must_equal ["small "]
|
323
|
+
completer.complete("ape --height s").must_equal ["small ", "smel ly"]
|
324
|
+
end
|
325
|
+
|
326
|
+
it "should complete quoted option values" do
|
327
|
+
completer.complete("ape --height 's").must_equal ["'small' ", "'smel ly"]
|
328
|
+
end
|
329
|
+
|
330
|
+
it "should complete quoted option values" do
|
331
|
+
completer.complete("ape --height 'smel l").must_equal ["'smel ly"]
|
147
332
|
end
|
148
333
|
end
|
149
334
|
|