cliqr 1.2.0 → 2.0.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
- data/CHANGELOG.md +95 -0
- data/README.md +9 -71
- data/examples/numbers +1 -2
- data/examples/vagrant +0 -3
- data/lib/cliqr.rb +52 -11
- data/lib/cliqr/argument_validation/argument_type_validator.rb +2 -2
- data/lib/cliqr/argument_validation/validator.rb +3 -3
- data/lib/cliqr/{cli → command}/argument_operator.rb +2 -2
- data/lib/cliqr/{cli → command}/argument_operator_context.rb +1 -1
- data/lib/cliqr/{cli/command.rb → command/base_command.rb} +2 -2
- data/lib/cliqr/command/color.rb +174 -0
- data/lib/cliqr/{cli → command}/command_context.rb +68 -20
- data/lib/cliqr/command/shell_banner_builder.rb +17 -0
- data/lib/cliqr/command/shell_command.rb +125 -0
- data/lib/cliqr/command/shell_prompt_builder.rb +26 -0
- data/lib/cliqr/config/action.rb +226 -0
- data/lib/cliqr/config/base.rb +84 -0
- data/lib/cliqr/config/command.rb +137 -0
- data/lib/cliqr/config/dsl.rb +81 -0
- data/lib/cliqr/config/event.rb +43 -0
- data/lib/cliqr/config/event_based.rb +78 -0
- data/lib/cliqr/config/named.rb +55 -0
- data/lib/cliqr/config/option.rb +95 -0
- data/lib/cliqr/config/option_based.rb +130 -0
- data/lib/cliqr/config/shell.rb +87 -0
- data/lib/cliqr/config/validation/validation_set.rb +66 -0
- data/lib/cliqr/config/validation/validator_factory.rb +403 -0
- data/lib/cliqr/config/validation/verifiable.rb +91 -0
- data/lib/cliqr/error.rb +20 -4
- data/lib/cliqr/events/event.rb +56 -0
- data/lib/cliqr/events/event_context.rb +31 -0
- data/lib/cliqr/events/handler.rb +32 -0
- data/lib/cliqr/events/invoker.rb +70 -0
- data/lib/cliqr/{cli → executor}/command_runner_factory.rb +3 -3
- data/lib/cliqr/{cli → executor}/router.rb +4 -4
- data/lib/cliqr/{cli/executor.rb → executor/runner.rb} +25 -10
- data/lib/cliqr/interface.rb +98 -0
- data/lib/cliqr/parser/token_factory.rb +1 -1
- data/lib/cliqr/usage/command_usage_context.rb +94 -0
- data/lib/cliqr/usage/option_usage_context.rb +86 -0
- data/lib/cliqr/usage/templates/partial/action_list.erb +10 -0
- data/lib/cliqr/usage/templates/partial/command_name.erb +3 -0
- data/lib/cliqr/usage/templates/partial/option_list.erb +18 -0
- data/lib/cliqr/usage/templates/partial/usage_info.erb +5 -0
- data/lib/cliqr/usage/templates/usage/cli.erb +4 -0
- data/lib/cliqr/usage/templates/usage/shell.erb +2 -0
- data/lib/cliqr/usage/usage_builder.rb +59 -0
- data/lib/cliqr/util.rb +81 -34
- data/lib/cliqr/version.rb +1 -1
- data/spec/config/action_config_validator_spec.rb +127 -5
- data/spec/config/config_finalize_spec.rb +3 -3
- data/spec/config/config_validator_spec.rb +120 -17
- data/spec/config/option_config_validator_spec.rb +1 -1
- data/spec/dsl/interface_spec.rb +2 -2
- data/spec/dsl/usage_spec.rb +461 -465
- data/spec/executor/action_executor_spec.rb +1 -1
- data/spec/executor/color_executor_spec.rb +125 -0
- data/spec/executor/command_runner_spec.rb +6 -8
- data/spec/executor/event_executor_spec.rb +365 -0
- data/spec/executor/executor_spec.rb +49 -11
- data/spec/executor/help_executor_spec.rb +107 -103
- data/spec/fixtures/action_reader_command.rb +1 -1
- data/spec/fixtures/test_arg_printer_event_handler.rb +9 -0
- data/spec/fixtures/test_color_shell_prompt.rb +13 -0
- data/spec/fixtures/test_empty_event_handler.rb +5 -0
- data/spec/fixtures/test_invoker_event_handler.rb +9 -0
- data/spec/fixtures/test_shell_banner.rb +8 -0
- data/spec/fixtures/test_shell_prompt.rb +13 -0
- data/spec/shell/shell_executor_spec.rb +700 -0
- data/spec/validation/validation_spec.rb +2 -2
- metadata +65 -27
- data/lib/cliqr/cli/config.rb +0 -554
- data/lib/cliqr/cli/interface.rb +0 -107
- data/lib/cliqr/cli/shell_command.rb +0 -69
- data/lib/cliqr/cli/usage_builder.rb +0 -185
- data/lib/cliqr/config_validation/validation_set.rb +0 -48
- data/lib/cliqr/config_validation/validator_factory.rb +0 -319
- data/lib/cliqr/config_validation/verifiable.rb +0 -89
- data/lib/cliqr/dsl.rb +0 -59
- data/spec/executor/shell_executor_spec.rb +0 -233
- data/templates/usage.erb +0 -39
data/lib/cliqr/version.rb
CHANGED
@@ -3,8 +3,9 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
require 'fixtures/test_command'
|
6
|
+
require 'fixtures/test_arg_printer_event_handler'
|
6
7
|
|
7
|
-
describe Cliqr::
|
8
|
+
describe Cliqr::Config do
|
8
9
|
it 'does not allow multiple actions with same name' do
|
9
10
|
def define_interface
|
10
11
|
Cliqr.interface do
|
@@ -91,7 +92,7 @@ describe Cliqr::CLI::Config do
|
|
91
92
|
"action \"my-action\" - invalid value for handler; fix one of - ['handler' cannot be nil]]"))
|
92
93
|
end
|
93
94
|
|
94
|
-
it 'only accepts command handler that extend from Cliqr::
|
95
|
+
it 'only accepts command handler that extend from Cliqr::Command::BaseCommand' do
|
95
96
|
def define_interface
|
96
97
|
Cliqr.interface do
|
97
98
|
name 'my-command'
|
@@ -106,7 +107,7 @@ describe Cliqr::CLI::Config do
|
|
106
107
|
expect { define_interface }.to(raise_error(Cliqr::Error::ValidationError,
|
107
108
|
'invalid Cliqr interface configuration - [' \
|
108
109
|
"action \"my-action\" - invalid value for handler; fix one of - [" \
|
109
|
-
"handler of type 'Object' does not extend from 'Cliqr::
|
110
|
+
"handler of type 'Object' does not extend from 'Cliqr::Command::BaseCommand', " \
|
110
111
|
"handler should be a 'Proc' not 'Object']]"))
|
111
112
|
end
|
112
113
|
|
@@ -134,13 +135,134 @@ describe Cliqr::CLI::Config do
|
|
134
135
|
'invalid Cliqr interface configuration - [' \
|
135
136
|
"value for 'name' must match /^[a-zA-Z0-9_\\-]+$/; actual: \"invalid-name-!@#\", " \
|
136
137
|
'invalid value for handler; fix one of - [' \
|
137
|
-
"handler of type 'Object' does not extend from 'Cliqr::
|
138
|
+
"handler of type 'Object' does not extend from 'Cliqr::Command::BaseCommand', " \
|
138
139
|
"handler should be a 'Proc' not 'Object'], " \
|
139
140
|
"action \"my-action\" - invalid value for handler; fix one of - [" \
|
140
|
-
"handler of type 'Object' does not extend from 'Cliqr::
|
141
|
+
"handler of type 'Object' does not extend from 'Cliqr::Command::BaseCommand', " \
|
141
142
|
"handler should be a 'Proc' not 'Object'], " \
|
142
143
|
"action \"my-action\" - actions[1] - 'name' cannot be nil, " \
|
143
144
|
"action \"my-action\" - actions[1] - invalid value for handler; fix one of - ['handler' cannot be nil], " \
|
144
145
|
"action \"my-action\" - action \"bla\" - invalid value for handler; fix one of - ['handler' cannot be nil]]"))
|
145
146
|
end
|
147
|
+
|
148
|
+
it 'does not allow event without handler' do
|
149
|
+
def define_interface
|
150
|
+
Cliqr.interface do
|
151
|
+
name 'my-command'
|
152
|
+
description 'a command used to test cliqr'
|
153
|
+
on :some_event
|
154
|
+
|
155
|
+
action 'my-action' do
|
156
|
+
on :deep_event
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
expect { define_interface }.to(raise_error(Cliqr::Error::ValidationError,
|
161
|
+
'invalid Cliqr interface configuration - [' \
|
162
|
+
"event \"some_event\" - invalid value for handler; fix one of - ['handler' cannot be nil], " \
|
163
|
+
"action \"my-action\" - event \"deep_event\" - invalid value for handler; fix one of - ['handler' cannot be nil]]"))
|
164
|
+
end
|
165
|
+
|
166
|
+
it 'does not allow event with invalid name' do
|
167
|
+
def define_interface
|
168
|
+
Cliqr.interface do
|
169
|
+
name 'my-command'
|
170
|
+
description 'a command used to test cliqr'
|
171
|
+
on '!@#', TestArgPrinterEventHandler
|
172
|
+
end
|
173
|
+
end
|
174
|
+
expect { define_interface }.to(raise_error(Cliqr::Error::ValidationError,
|
175
|
+
'invalid Cliqr interface configuration - [' \
|
176
|
+
"event \"!@#\" - value for 'name' must match /^[a-zA-Z0-9_\\-]+$/; actual: \"!@#\"]"))
|
177
|
+
end
|
178
|
+
|
179
|
+
it 'does not allow event handler class and handler proc at the same time' do
|
180
|
+
def define_interface
|
181
|
+
Cliqr.interface do
|
182
|
+
name 'my-command'
|
183
|
+
description 'a command used to test cliqr'
|
184
|
+
on :some_event, TestArgPrinterEventHandler do
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
expect { define_interface }.to(raise_error(Cliqr::Error::ValidationError,
|
189
|
+
'only one of event_class or event_block are allowed'))
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'does not allow event without name' do
|
193
|
+
def define_interface
|
194
|
+
Cliqr.interface do
|
195
|
+
name 'my-command'
|
196
|
+
description 'a command used to test cliqr'
|
197
|
+
on TestArgPrinterEventHandler
|
198
|
+
|
199
|
+
action 'my-action' do
|
200
|
+
on TestArgPrinterEventHandler
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
expect { define_interface }.to(raise_error(Cliqr::Error::ValidationError,
|
205
|
+
'invalid Cliqr interface configuration - [' \
|
206
|
+
"events[1] - 'name' cannot be empty, " \
|
207
|
+
"events[1] - invalid value for handler; fix one of - ['handler' cannot be nil], " \
|
208
|
+
"action \"my-action\" - events[1] - 'name' cannot be empty, " \
|
209
|
+
"action \"my-action\" - events[1] - invalid value for handler; fix one of - ['handler' cannot be nil]]"))
|
210
|
+
end
|
211
|
+
|
212
|
+
it 'does not allow event handler of any type other than string or symbol' do
|
213
|
+
def define_interface
|
214
|
+
Cliqr.interface do
|
215
|
+
name 'my-command'
|
216
|
+
description 'a command used to test cliqr'
|
217
|
+
on :base, Object
|
218
|
+
|
219
|
+
action 'my-action' do
|
220
|
+
on :third, []
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
224
|
+
expect { define_interface }.to(raise_error(Cliqr::Error::ValidationError,
|
225
|
+
'invalid Cliqr interface configuration - [' \
|
226
|
+
"event \"base\" - invalid value for handler; fix one of - [" \
|
227
|
+
"handler should be a 'Cliqr::Events::Handler' not 'Class', " \
|
228
|
+
"handler should be a 'Proc' not 'Class'], " \
|
229
|
+
"action \"my-action\" - event \"third\" - invalid value for handler; fix one of - [" \
|
230
|
+
"handler should be a 'Cliqr::Events::Handler' not 'Array', " \
|
231
|
+
"handler should be a 'Proc' not 'Array']]"))
|
232
|
+
end
|
233
|
+
|
234
|
+
it 'does not allow invalid name for shell config' do
|
235
|
+
def define_interface
|
236
|
+
Cliqr.interface do
|
237
|
+
name 'my-command'
|
238
|
+
|
239
|
+
shell do
|
240
|
+
name Object
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
expect { define_interface }.to(raise_error(Cliqr::Error::ValidationError,
|
245
|
+
'invalid Cliqr interface configuration - [' \
|
246
|
+
"shell - value for 'name' must match /^[a-zA-Z0-9_\\-]+$/; actual: Object]"))
|
247
|
+
end
|
248
|
+
|
249
|
+
it 'validates events inside shell config' do
|
250
|
+
def define_interface
|
251
|
+
Cliqr.interface do
|
252
|
+
name 'test-command'
|
253
|
+
|
254
|
+
shell do
|
255
|
+
on :third, []
|
256
|
+
on TestArgPrinterEventHandler
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
260
|
+
expect { define_interface }.to(raise_error(Cliqr::Error::ValidationError,
|
261
|
+
'invalid Cliqr interface configuration - [' \
|
262
|
+
"shell - event \"third\" - invalid value for handler; fix one of - [" \
|
263
|
+
"handler should be a 'Cliqr::Events::Handler' not 'Array', " \
|
264
|
+
"handler should be a 'Proc' not 'Array'], " \
|
265
|
+
"shell - events[2] - 'name' cannot be empty, " \
|
266
|
+
"shell - events[2] - invalid value for handler; fix one of - ['handler' cannot be nil]]"))
|
267
|
+
end
|
146
268
|
end
|
@@ -2,13 +2,13 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
describe Cliqr::
|
5
|
+
describe Cliqr::Config do
|
6
6
|
it 'sets proper defaults for unset values' do
|
7
|
-
config = Cliqr::
|
7
|
+
config = Cliqr::Config::Command.new
|
8
8
|
config.finalize
|
9
9
|
expect(config.name).to eq('')
|
10
10
|
expect(config.description).to eq('')
|
11
11
|
expect(config.handler).to eq(nil)
|
12
|
-
expect(config.options).to eq(
|
12
|
+
expect(config.options).to eq({})
|
13
13
|
end
|
14
14
|
end
|
@@ -4,7 +4,7 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
require 'fixtures/test_command'
|
6
6
|
|
7
|
-
describe Cliqr::
|
7
|
+
describe Cliqr::Config do
|
8
8
|
it 'does not allow empty name' do
|
9
9
|
expect do
|
10
10
|
Cliqr.interface do
|
@@ -47,40 +47,143 @@ describe Cliqr::CLI::Config do
|
|
47
47
|
"invalid value for handler; fix one of - ['handler' cannot be nil]]"))
|
48
48
|
end
|
49
49
|
|
50
|
-
it 'only accepts command handler that extend from Cliqr::
|
51
|
-
|
50
|
+
it 'only accepts command handler that extend from Cliqr::Command::BaseCommand' do
|
51
|
+
def define_interface
|
52
52
|
Cliqr.interface do
|
53
53
|
name 'my-command'
|
54
54
|
handler Object
|
55
55
|
end
|
56
|
-
end
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
56
|
+
end
|
57
|
+
|
58
|
+
expect { define_interface }.to(raise_error(Cliqr::Error::ValidationError,
|
59
|
+
'invalid Cliqr interface configuration - [' \
|
60
|
+
'invalid value for handler; fix one of - [' \
|
61
|
+
"handler of type 'Object' does not extend from 'Cliqr::Command::BaseCommand', " \
|
62
|
+
"handler should be a 'Proc' not 'Object']]"))
|
61
63
|
end
|
62
64
|
|
63
65
|
it 'expects that config options should not be nil' do
|
64
|
-
config = Cliqr::
|
66
|
+
config = Cliqr::Config::Command.new
|
65
67
|
config.name = 'my-command'
|
66
68
|
config.handler = TestCommand
|
67
69
|
config.options = nil
|
68
70
|
config.finalize
|
69
|
-
expect { Cliqr::
|
71
|
+
expect { Cliqr::Interface.build(config) }.to(
|
70
72
|
raise_error(Cliqr::Error::ValidationError, "invalid Cliqr interface configuration - ['options' cannot be nil]"))
|
71
73
|
end
|
72
74
|
|
73
75
|
it 'throws multiple errors if more than one issue exists in config' do
|
74
|
-
|
76
|
+
def define_interface
|
75
77
|
Cliqr.interface do
|
76
78
|
name 'invalid-name-!@#'
|
77
79
|
handler Object
|
78
80
|
end
|
79
|
-
end
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
81
|
+
end
|
82
|
+
|
83
|
+
expect { define_interface }.to(raise_error(Cliqr::Error::ValidationError,
|
84
|
+
'invalid Cliqr interface configuration - [' \
|
85
|
+
"value for 'name' must match /^[a-zA-Z0-9_\\-]+$/; actual: \"invalid-name-!@#\", " \
|
86
|
+
'invalid value for handler; fix one of - [' \
|
87
|
+
"handler of type 'Object' does not extend from 'Cliqr::Command::BaseCommand', " \
|
88
|
+
"handler should be a 'Proc' not 'Object']]"))
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'expects that shell be non-nil for command config' do
|
92
|
+
config = Cliqr::Config::Command.new
|
93
|
+
config.name = 'my-command'
|
94
|
+
config.handler = TestCommand
|
95
|
+
config.shell = nil
|
96
|
+
config.finalize
|
97
|
+
expect { Cliqr::Interface.build(config) }.to(
|
98
|
+
raise_error(NoMethodError, "undefined method `valid?' for nil:NilClass"))
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'validates shell enable setting' do
|
102
|
+
def define_interface
|
103
|
+
Cliqr.interface do
|
104
|
+
name 'test-command'
|
105
|
+
handler TestCommand
|
106
|
+
shell Object
|
107
|
+
end
|
108
|
+
end
|
109
|
+
expect { define_interface }.to(raise_error(Cliqr::Error::ValidationError,
|
110
|
+
"invalid Cliqr interface configuration - [shell - invalid type 'Object']"))
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'validates shell enable and prompt setting' do
|
114
|
+
def define_interface
|
115
|
+
Cliqr.interface do
|
116
|
+
name 'test-command'
|
117
|
+
handler TestCommand
|
118
|
+
shell do
|
119
|
+
prompt Object
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
expect { define_interface }.to(raise_error(Cliqr::Error::ValidationError,
|
124
|
+
'invalid Cliqr interface configuration - [' \
|
125
|
+
'shell - invalid value for prompt; fix one of - [' \
|
126
|
+
"prompt of type 'Class' does not extend from 'Cliqr::Command::ShellPromptBuilder', " \
|
127
|
+
"prompt should be a 'Proc' not 'Class', " \
|
128
|
+
"prompt should be a 'String' not 'Class']]"))
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'validates shell banner to be a string' do
|
132
|
+
def define_interface
|
133
|
+
Cliqr.interface do
|
134
|
+
name 'test-command'
|
135
|
+
handler TestCommand
|
136
|
+
shell do
|
137
|
+
banner Object
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
expect { define_interface }.to(raise_error(Cliqr::Error::ValidationError, \
|
142
|
+
'invalid Cliqr interface configuration - [' \
|
143
|
+
'shell - invalid value for banner; fix one of - [' \
|
144
|
+
"banner of type 'Class' does not extend from 'Cliqr::Command::ShellBannerBuilder', " \
|
145
|
+
"banner should be a 'Proc' not 'Class', " \
|
146
|
+
"banner should be a 'String' not 'Class']]"))
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'does not allow anything except :enable or :disable for color' do
|
150
|
+
def define_interface
|
151
|
+
Cliqr.interface do
|
152
|
+
name 'my-command'
|
153
|
+
color Object
|
154
|
+
end
|
155
|
+
end
|
156
|
+
expect { define_interface }.to(raise_error(Cliqr::Error::ValidationError,
|
157
|
+
"invalid Cliqr interface configuration - [invalid type 'Object']"))
|
158
|
+
end
|
159
|
+
|
160
|
+
it 'validates options inside shell config' do
|
161
|
+
def define_interface
|
162
|
+
Cliqr.interface do
|
163
|
+
name 'test-command'
|
164
|
+
handler TestCommand
|
165
|
+
shell do
|
166
|
+
option :foo do
|
167
|
+
type :blah
|
168
|
+
end
|
169
|
+
|
170
|
+
option :bar do
|
171
|
+
short ''
|
172
|
+
end
|
173
|
+
|
174
|
+
option nil do
|
175
|
+
operator Object
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
expect { define_interface }.to(raise_error(Cliqr::Error::ValidationError,
|
181
|
+
'invalid Cliqr interface configuration - [' \
|
182
|
+
"shell - option \"foo\" - invalid type 'blah', " \
|
183
|
+
"shell - option \"bar\" - 'short' cannot be empty, " \
|
184
|
+
"shell - options[3] - 'name' cannot be nil, " \
|
185
|
+
'shell - options[3] - invalid value for operator; fix one of - [' \
|
186
|
+
"operator of type 'Object' does not extend from 'Cliqr::Command::ArgumentOperator', " \
|
187
|
+
"operator should be a 'Proc' not 'Object']]"))
|
85
188
|
end
|
86
189
|
end
|
data/spec/dsl/interface_spec.rb
CHANGED
@@ -4,10 +4,10 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
require 'fixtures/test_command'
|
6
6
|
|
7
|
-
describe Cliqr::
|
7
|
+
describe Cliqr::Interface do
|
8
8
|
it 'does not allow empty config' do
|
9
9
|
expect do
|
10
|
-
Cliqr::
|
10
|
+
Cliqr::Interface.build(nil)
|
11
11
|
end.to(raise_error(Cliqr::Error::ConfigNotFound, 'a valid config should be defined'))
|
12
12
|
end
|
13
13
|
|
data/spec/dsl/usage_spec.rb
CHANGED
@@ -3,62 +3,88 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
require 'fixtures/test_command'
|
6
|
-
require 'fixtures/action_reader_command'
|
7
|
-
require 'fixtures/csv_argument_operator'
|
8
|
-
|
9
|
-
describe Cliqr::CLI::UsageBuilder do
|
10
|
-
################ BASE COMMAND ################
|
11
|
-
|
12
|
-
it 'builds a base command with name' do
|
13
|
-
cli = Cliqr.interface do
|
14
|
-
name 'my-command'
|
15
|
-
description 'a command used to test cliqr'
|
16
|
-
handler TestCommand
|
17
|
-
arguments :disable
|
18
|
-
help :disable
|
19
|
-
end
|
20
6
|
|
21
|
-
|
7
|
+
describe Cliqr::Usage::UsageBuilder do
|
8
|
+
describe 'base command' do
|
9
|
+
it 'builds a base command with name' do
|
10
|
+
cli = Cliqr.interface do
|
11
|
+
name 'my-command'
|
12
|
+
description 'a command used to test cliqr'
|
13
|
+
handler TestCommand
|
14
|
+
arguments :disable
|
15
|
+
help :disable
|
16
|
+
color :disable
|
17
|
+
end
|
18
|
+
|
19
|
+
expect(cli.usage).to eq <<-EOS
|
22
20
|
my-command -- a command used to test cliqr
|
23
21
|
|
24
22
|
USAGE:
|
25
23
|
my-command
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'only makes name and handler to be required' do
|
30
|
-
cli = Cliqr.interface do
|
31
|
-
name 'my-command'
|
32
|
-
handler TestCommand
|
33
|
-
arguments :disable
|
34
|
-
help :disable
|
24
|
+
EOS
|
35
25
|
end
|
36
26
|
|
37
|
-
|
27
|
+
it 'only makes name and handler to be required' do
|
28
|
+
cli = Cliqr.interface do
|
29
|
+
name 'my-command'
|
30
|
+
handler TestCommand
|
31
|
+
arguments :disable
|
32
|
+
help :disable
|
33
|
+
color :disable
|
34
|
+
end
|
35
|
+
|
36
|
+
expect(cli.usage).to eq <<-EOS
|
38
37
|
my-command
|
39
38
|
|
40
39
|
USAGE:
|
41
40
|
my-command
|
42
|
-
|
43
|
-
|
41
|
+
EOS
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'can add version to base command' do
|
45
|
+
cli = Cliqr.interface do
|
46
|
+
name 'my-command'
|
47
|
+
version '1234'
|
48
|
+
color :disable
|
49
|
+
end
|
50
|
+
result = cli.execute_internal %w(help), output: :buffer
|
51
|
+
expect(result[:stdout]).to eq <<-EOS
|
52
|
+
my-command
|
53
|
+
|
54
|
+
USAGE:
|
55
|
+
my-command [actions] [options] [arguments]
|
44
56
|
|
45
|
-
|
57
|
+
Available options:
|
46
58
|
|
47
|
-
|
48
|
-
|
49
|
-
name 'my-command'
|
50
|
-
description 'a command used to test cliqr'
|
51
|
-
handler TestCommand
|
52
|
-
arguments :disable
|
53
|
-
help :disable
|
59
|
+
--help, -h : Get helpful information for action "my-command" along with its usage information.
|
60
|
+
--version, -v : Get version information for command "my-command".
|
54
61
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
62
|
+
Available actions:
|
63
|
+
[ Type "my-command help [action-name]" to get more information about that action ]
|
64
|
+
|
65
|
+
help -- The help action for command "my-command" which provides details and usage information on how to use the command.
|
66
|
+
version -- Get version information for command "my-command".
|
67
|
+
EOS
|
59
68
|
end
|
69
|
+
end
|
60
70
|
|
61
|
-
|
71
|
+
describe 'options' do
|
72
|
+
it 'allows options for a command' do
|
73
|
+
cli = Cliqr.interface do
|
74
|
+
name 'my-command'
|
75
|
+
description 'a command used to test cliqr'
|
76
|
+
handler TestCommand
|
77
|
+
arguments :disable
|
78
|
+
help :disable
|
79
|
+
color :disable
|
80
|
+
|
81
|
+
option 'option-1' do
|
82
|
+
short 'p'
|
83
|
+
description 'a nice option to have'
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
expect(cli.usage).to eq <<-EOS
|
62
88
|
my-command -- a command used to test cliqr
|
63
89
|
|
64
90
|
USAGE:
|
@@ -67,21 +93,22 @@ USAGE:
|
|
67
93
|
Available options:
|
68
94
|
|
69
95
|
--option-1, -p : a nice option to have
|
70
|
-
|
71
|
-
|
96
|
+
EOS
|
97
|
+
end
|
72
98
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
99
|
+
it 'allows command options to optionally have description, type and short name' do
|
100
|
+
cli = Cliqr.interface do
|
101
|
+
name 'my-command'
|
102
|
+
description 'a command used to test cliqr'
|
103
|
+
handler TestCommand
|
104
|
+
arguments :disable
|
105
|
+
help :disable
|
106
|
+
color :disable
|
80
107
|
|
81
|
-
|
82
|
-
|
108
|
+
option 'option-1'
|
109
|
+
end
|
83
110
|
|
84
|
-
|
111
|
+
expect(cli.usage).to eq <<-EOS
|
85
112
|
my-command -- a command used to test cliqr
|
86
113
|
|
87
114
|
USAGE:
|
@@ -90,41 +117,41 @@ USAGE:
|
|
90
117
|
Available options:
|
91
118
|
|
92
119
|
--option-1
|
93
|
-
|
94
|
-
|
120
|
+
EOS
|
121
|
+
end
|
95
122
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
123
|
+
it 'has options if added during build phase' do
|
124
|
+
cli = Cliqr.interface do
|
125
|
+
name 'my-command'
|
126
|
+
description 'a command used to test cliqr'
|
127
|
+
handler TestCommand
|
101
128
|
|
102
|
-
|
103
|
-
|
104
|
-
|
129
|
+
option 'option-1' do
|
130
|
+
short 'p'
|
131
|
+
description 'a nice option to have'
|
132
|
+
end
|
105
133
|
end
|
134
|
+
expect(cli.config.options?).to be_truthy
|
106
135
|
end
|
107
|
-
expect(cli.config.options?).to be_truthy
|
108
|
-
end
|
109
|
-
|
110
|
-
################ OPTION TYPES ################
|
111
136
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
137
|
+
describe 'types' do
|
138
|
+
it 'allows command options to have a numeric value type' do
|
139
|
+
cli = Cliqr.interface do
|
140
|
+
name 'my-command'
|
141
|
+
description 'a command used to test cliqr'
|
142
|
+
handler TestCommand
|
143
|
+
arguments :disable
|
144
|
+
help :disable
|
145
|
+
color :disable
|
119
146
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
147
|
+
option 'option-1' do
|
148
|
+
description 'a numeric option'
|
149
|
+
short 'p'
|
150
|
+
type :numeric
|
151
|
+
end
|
152
|
+
end
|
126
153
|
|
127
|
-
|
154
|
+
expect(cli.usage).to eq <<-EOS
|
128
155
|
my-command -- a command used to test cliqr
|
129
156
|
|
130
157
|
USAGE:
|
@@ -133,25 +160,26 @@ USAGE:
|
|
133
160
|
Available options:
|
134
161
|
|
135
162
|
--option-1, -p : <numeric> a numeric option (default => 0)
|
136
|
-
|
137
|
-
end
|
138
|
-
|
139
|
-
it 'allows command options to have a boolean value type' do
|
140
|
-
cli = Cliqr.interface do
|
141
|
-
name 'my-command'
|
142
|
-
description 'a command used to test cliqr'
|
143
|
-
handler TestCommand
|
144
|
-
arguments :disable
|
145
|
-
help :disable
|
146
|
-
|
147
|
-
option 'option-1' do
|
148
|
-
description 'a boolean option'
|
149
|
-
short 'p'
|
150
|
-
type :boolean
|
163
|
+
EOS
|
151
164
|
end
|
152
|
-
end
|
153
165
|
|
154
|
-
|
166
|
+
it 'allows command options to have a boolean value type' do
|
167
|
+
cli = Cliqr.interface do
|
168
|
+
name 'my-command'
|
169
|
+
description 'a command used to test cliqr'
|
170
|
+
handler TestCommand
|
171
|
+
arguments :disable
|
172
|
+
help :disable
|
173
|
+
color :disable
|
174
|
+
|
175
|
+
option 'option-1' do
|
176
|
+
description 'a boolean option'
|
177
|
+
short 'p'
|
178
|
+
type :boolean
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
expect(cli.usage).to eq <<-EOS
|
155
183
|
my-command -- a command used to test cliqr
|
156
184
|
|
157
185
|
USAGE:
|
@@ -160,24 +188,25 @@ USAGE:
|
|
160
188
|
Available options:
|
161
189
|
|
162
190
|
--[no-]option-1, -p : <boolean> a boolean option (default => false)
|
163
|
-
|
164
|
-
end
|
165
|
-
|
166
|
-
it 'allows command options to have a boolean value type and no description' do
|
167
|
-
cli = Cliqr.interface do
|
168
|
-
name 'my-command'
|
169
|
-
description 'a command used to test cliqr'
|
170
|
-
handler TestCommand
|
171
|
-
arguments :disable
|
172
|
-
help :disable
|
173
|
-
|
174
|
-
option 'option-1' do
|
175
|
-
short 'p'
|
176
|
-
type :boolean
|
191
|
+
EOS
|
177
192
|
end
|
178
|
-
end
|
179
193
|
|
180
|
-
|
194
|
+
it 'allows command options to have a boolean value type and no description' do
|
195
|
+
cli = Cliqr.interface do
|
196
|
+
name 'my-command'
|
197
|
+
description 'a command used to test cliqr'
|
198
|
+
handler TestCommand
|
199
|
+
arguments :disable
|
200
|
+
help :disable
|
201
|
+
color :disable
|
202
|
+
|
203
|
+
option 'option-1' do
|
204
|
+
short 'p'
|
205
|
+
type :boolean
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
expect(cli.usage).to eq <<-EOS
|
181
210
|
my-command -- a command used to test cliqr
|
182
211
|
|
183
212
|
USAGE:
|
@@ -186,38 +215,43 @@ USAGE:
|
|
186
215
|
Available options:
|
187
216
|
|
188
217
|
--[no-]option-1, -p : <boolean> (default => false)
|
189
|
-
|
190
|
-
|
218
|
+
EOS
|
219
|
+
end
|
220
|
+
end
|
191
221
|
|
192
|
-
|
222
|
+
describe 'default values' do
|
223
|
+
it 'allows options to have default value' do
|
224
|
+
cli = Cliqr.interface do
|
225
|
+
name 'my-command'
|
226
|
+
handler TestCommand
|
227
|
+
help :disable
|
228
|
+
color :disable
|
193
229
|
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
handler TestCommand
|
198
|
-
arguments :enable
|
199
|
-
help :disable
|
200
|
-
end
|
230
|
+
option 'test-option' do
|
231
|
+
default :a_symbol
|
232
|
+
end
|
201
233
|
|
202
|
-
|
203
|
-
|
234
|
+
option :another do
|
235
|
+
short 'a'
|
236
|
+
description 'another option'
|
237
|
+
type :numeric
|
238
|
+
default %w(test array default)
|
239
|
+
end
|
204
240
|
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
end
|
241
|
+
option 'nil-option' do
|
242
|
+
default nil
|
243
|
+
end
|
209
244
|
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
handler TestCommand
|
214
|
-
arguments :enable
|
215
|
-
help :disable
|
245
|
+
option 'string-option' do
|
246
|
+
default 'string'
|
247
|
+
end
|
216
248
|
|
217
|
-
|
218
|
-
|
249
|
+
option 'hash-option' do
|
250
|
+
default(:key => 'val')
|
251
|
+
end
|
252
|
+
end
|
219
253
|
|
220
|
-
|
254
|
+
expect(cli.usage).to eq <<-EOS
|
221
255
|
my-command
|
222
256
|
|
223
257
|
USAGE:
|
@@ -225,436 +259,380 @@ USAGE:
|
|
225
259
|
|
226
260
|
Available options:
|
227
261
|
|
228
|
-
--option
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
it 'allows command to have an action' do
|
235
|
-
cli = Cliqr.interface do
|
236
|
-
name 'my-command'
|
237
|
-
handler TestCommand
|
238
|
-
help :disable
|
239
|
-
shell :disable
|
240
|
-
|
241
|
-
action 'my-action' do
|
242
|
-
handler TestCommand
|
243
|
-
arguments :disable
|
262
|
+
--test-option : (default => :a_symbol)
|
263
|
+
--another, -a : <numeric> another option (default => [\"test\", \"array\", \"default\"])
|
264
|
+
--nil-option
|
265
|
+
--string-option : (default => "string")
|
266
|
+
--hash-option : (default => {:key=>"val"})
|
267
|
+
EOS
|
244
268
|
end
|
245
|
-
end
|
246
269
|
|
247
|
-
|
270
|
+
it 'boolean option is false by default' do
|
271
|
+
cli = Cliqr.interface do
|
272
|
+
name 'my-command'
|
273
|
+
handler TestCommand
|
274
|
+
help :disable
|
275
|
+
color :disable
|
276
|
+
|
277
|
+
option :another do
|
278
|
+
short 'a'
|
279
|
+
description 'another option'
|
280
|
+
type :boolean
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
expect(cli.usage).to eq <<-EOS
|
248
285
|
my-command
|
249
286
|
|
250
287
|
USAGE:
|
251
|
-
my-command [
|
252
|
-
|
253
|
-
Available actions:
|
254
|
-
|
255
|
-
my-action
|
256
|
-
EOS
|
257
|
-
end
|
288
|
+
my-command [options] [arguments]
|
258
289
|
|
259
|
-
|
260
|
-
cli = Cliqr.interface do
|
261
|
-
name 'my-command'
|
262
|
-
handler TestCommand
|
263
|
-
help :disable
|
264
|
-
shell :disable
|
290
|
+
Available options:
|
265
291
|
|
266
|
-
|
267
|
-
|
268
|
-
description 'this is a test action'
|
269
|
-
arguments :disable
|
292
|
+
--[no-]another, -a : <boolean> another option (default => false)
|
293
|
+
EOS
|
270
294
|
end
|
271
|
-
end
|
272
295
|
|
273
|
-
|
296
|
+
it 'numeric option is 0 by default' do
|
297
|
+
cli = Cliqr.interface do
|
298
|
+
name 'my-command'
|
299
|
+
handler TestCommand
|
300
|
+
help :disable
|
301
|
+
color :disable
|
302
|
+
|
303
|
+
option :another do
|
304
|
+
short 'a'
|
305
|
+
description 'another option'
|
306
|
+
type :numeric
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
expect(cli.usage).to eq <<-EOS
|
274
311
|
my-command
|
275
312
|
|
276
313
|
USAGE:
|
277
|
-
my-command [
|
278
|
-
|
279
|
-
Available actions:
|
280
|
-
|
281
|
-
my-action -- this is a test action
|
282
|
-
EOS
|
283
|
-
end
|
314
|
+
my-command [options] [arguments]
|
284
315
|
|
285
|
-
|
286
|
-
cli = Cliqr.interface do
|
287
|
-
name 'my-command'
|
288
|
-
handler TestCommand
|
289
|
-
help :disable
|
290
|
-
shell :disable
|
316
|
+
Available options:
|
291
317
|
|
292
|
-
|
293
|
-
|
294
|
-
description 'this is a test action'
|
295
|
-
arguments :disable
|
318
|
+
--another, -a : <numeric> another option (default => 0)
|
319
|
+
EOS
|
296
320
|
end
|
297
321
|
|
298
|
-
|
299
|
-
|
322
|
+
it 'boolean option can be made default true' do
|
323
|
+
cli = Cliqr.interface do
|
324
|
+
name 'my-command'
|
325
|
+
handler TestCommand
|
326
|
+
help :disable
|
327
|
+
color :disable
|
328
|
+
|
329
|
+
option :another do
|
330
|
+
short 'a'
|
331
|
+
description 'another option'
|
332
|
+
type :boolean
|
333
|
+
default true
|
334
|
+
end
|
335
|
+
end
|
300
336
|
|
301
|
-
|
337
|
+
expect(cli.usage).to eq <<-EOS
|
302
338
|
my-command
|
303
339
|
|
304
340
|
USAGE:
|
305
|
-
my-command [
|
341
|
+
my-command [options] [arguments]
|
306
342
|
|
307
343
|
Available options:
|
308
344
|
|
309
|
-
--option
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
my-action -- this is a test action
|
314
|
-
EOS
|
345
|
+
--[no-]another, -a : <boolean> another option (default => true)
|
346
|
+
EOS
|
347
|
+
end
|
348
|
+
end
|
315
349
|
end
|
316
350
|
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
help :disable
|
322
|
-
shell :disable
|
323
|
-
|
324
|
-
action 'my-action' do
|
351
|
+
describe 'arguments' do
|
352
|
+
it 'allows interface to enable arbitrary argument list parsing without options' do
|
353
|
+
cli = Cliqr.interface do
|
354
|
+
name 'my-command'
|
325
355
|
handler TestCommand
|
326
|
-
|
327
|
-
|
328
|
-
|
356
|
+
arguments :enable
|
357
|
+
help :disable
|
358
|
+
color :disable
|
329
359
|
end
|
330
360
|
|
331
|
-
|
332
|
-
end
|
333
|
-
|
334
|
-
expect(cli.usage).to eq <<-EOS
|
361
|
+
expect(cli.usage).to eq <<-EOS
|
335
362
|
my-command
|
336
363
|
|
337
364
|
USAGE:
|
338
|
-
my-command [
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
--option-1
|
343
|
-
|
344
|
-
Available actions:
|
345
|
-
|
346
|
-
my-action -- this is a test action
|
347
|
-
EOS
|
348
|
-
end
|
349
|
-
|
350
|
-
it 'allows command to have multiple actions and multiple options' do
|
351
|
-
cli = Cliqr.interface do
|
352
|
-
name 'my-command'
|
353
|
-
handler TestCommand
|
354
|
-
help :disable
|
355
|
-
shell :disable
|
356
|
-
|
357
|
-
option 'option-1'
|
365
|
+
my-command [arguments]
|
366
|
+
EOS
|
367
|
+
end
|
358
368
|
|
359
|
-
|
369
|
+
it 'allows interface to enable arbitrary argument list parsing' do
|
370
|
+
cli = Cliqr.interface do
|
371
|
+
name 'my-command'
|
360
372
|
handler TestCommand
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
end
|
365
|
-
|
366
|
-
option 'option-2'
|
373
|
+
arguments :enable
|
374
|
+
help :disable
|
375
|
+
color :disable
|
367
376
|
|
368
|
-
|
369
|
-
handler TestCommand
|
370
|
-
description 'this is another test action'
|
371
|
-
arguments :disable
|
377
|
+
option 'option-1'
|
372
378
|
end
|
373
379
|
|
374
|
-
|
375
|
-
end
|
376
|
-
|
377
|
-
expect(cli.usage).to eq <<-EOS
|
380
|
+
expect(cli.usage).to eq <<-EOS
|
378
381
|
my-command
|
379
382
|
|
380
383
|
USAGE:
|
381
|
-
my-command [
|
384
|
+
my-command [options] [arguments]
|
382
385
|
|
383
386
|
Available options:
|
384
387
|
|
385
388
|
--option-1
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
Available actions:
|
390
|
-
|
391
|
-
my-action -- this is a test action
|
392
|
-
|
393
|
-
another-action -- this is another test action
|
394
|
-
EOS
|
389
|
+
EOS
|
390
|
+
end
|
395
391
|
end
|
396
392
|
|
397
|
-
|
398
|
-
|
399
|
-
Cliqr.interface do
|
393
|
+
describe 'actions' do
|
394
|
+
it 'allows command to have an action' do
|
395
|
+
cli = Cliqr.interface do
|
400
396
|
name 'my-command'
|
401
397
|
handler TestCommand
|
402
398
|
help :disable
|
403
399
|
shell :disable
|
400
|
+
color :disable
|
404
401
|
|
405
|
-
|
406
|
-
|
402
|
+
action 'my-action' do
|
403
|
+
arguments :disable
|
404
|
+
end
|
405
|
+
end
|
407
406
|
|
408
|
-
|
409
|
-
|
407
|
+
expect(cli.usage).to eq <<-EOS
|
408
|
+
my-command
|
410
409
|
|
411
|
-
|
412
|
-
|
410
|
+
USAGE:
|
411
|
+
my-command [actions] [arguments]
|
413
412
|
|
414
|
-
|
415
|
-
option 'test-option-2'
|
413
|
+
Available actions:
|
416
414
|
|
417
|
-
|
418
|
-
|
415
|
+
my-action
|
416
|
+
EOS
|
417
|
+
end
|
419
418
|
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
419
|
+
it 'allows command to have an action with description' do
|
420
|
+
cli = Cliqr.interface do
|
421
|
+
name 'my-command'
|
422
|
+
handler TestCommand
|
423
|
+
help :disable
|
424
|
+
shell :disable
|
425
|
+
color :disable
|
425
426
|
|
426
|
-
action '
|
427
|
-
|
427
|
+
action 'my-action' do
|
428
|
+
description 'this is a test action'
|
428
429
|
arguments :disable
|
429
430
|
end
|
430
431
|
end
|
431
|
-
|
432
|
-
|
432
|
+
|
433
|
+
expect(cli.usage).to eq <<-EOS
|
433
434
|
my-command
|
434
435
|
|
435
436
|
USAGE:
|
436
|
-
my-command [actions] [
|
437
|
-
|
438
|
-
Available options:
|
439
|
-
|
440
|
-
--test-option-1
|
441
|
-
--test-option-2
|
437
|
+
my-command [actions] [arguments]
|
442
438
|
|
443
439
|
Available actions:
|
444
440
|
|
445
|
-
my-action
|
441
|
+
my-action -- this is a test action
|
442
|
+
EOS
|
443
|
+
end
|
446
444
|
|
447
|
-
|
448
|
-
|
449
|
-
|
445
|
+
it 'cannot add version to action' do
|
446
|
+
def define_interface
|
447
|
+
Cliqr.interface do
|
448
|
+
name 'my-command'
|
450
449
|
|
451
|
-
|
450
|
+
action :bla do
|
451
|
+
version '1234'
|
452
|
+
end
|
453
|
+
end
|
454
|
+
end
|
455
|
+
expect { define_interface }.to(raise_error(NoMethodError))
|
456
|
+
end
|
452
457
|
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
+
describe 'shell action' do
|
459
|
+
it 'adds shell action to the base command only when there are sub actions' do
|
460
|
+
cli = Cliqr.interface do
|
461
|
+
name 'my-command'
|
462
|
+
handler TestCommand
|
463
|
+
help :disable
|
464
|
+
color :disable
|
458
465
|
|
459
|
-
|
460
|
-
|
461
|
-
end
|
466
|
+
action :bla
|
467
|
+
end
|
462
468
|
|
463
|
-
|
464
|
-
|
465
|
-
description 'another option'
|
466
|
-
type :numeric
|
467
|
-
default %w(test array default)
|
469
|
+
expect(cli.usage).to eq <<-EOS
|
470
|
+
my-command
|
468
471
|
|
469
|
-
|
470
|
-
|
472
|
+
USAGE:
|
473
|
+
my-command [actions] [arguments]
|
471
474
|
|
472
|
-
|
473
|
-
default nil
|
474
|
-
end
|
475
|
+
Available actions:
|
475
476
|
|
476
|
-
|
477
|
-
|
477
|
+
bla
|
478
|
+
shell -- Execute a shell in the context of "my-command" command.
|
479
|
+
EOS
|
478
480
|
end
|
479
481
|
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
482
|
+
it 'does not add shell action to the base command if it does not have actions' do
|
483
|
+
cli = Cliqr.interface do
|
484
|
+
name 'my-command'
|
485
|
+
handler TestCommand
|
486
|
+
help :disable
|
487
|
+
color :disable
|
488
|
+
end
|
484
489
|
|
485
|
-
|
490
|
+
expect(cli.usage).to eq <<-EOS
|
486
491
|
my-command
|
487
492
|
|
488
493
|
USAGE:
|
489
|
-
my-command [
|
490
|
-
|
491
|
-
|
494
|
+
my-command [arguments]
|
495
|
+
EOS
|
496
|
+
end
|
492
497
|
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
--hash-option : (default => {:key=>"val"})
|
498
|
-
EOS
|
499
|
-
end
|
498
|
+
it 'can not add shell action to a sub-action' do
|
499
|
+
def define_interface
|
500
|
+
Cliqr.interface do
|
501
|
+
name 'my-command'
|
500
502
|
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
503
|
+
action :bla do
|
504
|
+
shell :enable
|
505
|
+
end
|
506
|
+
end
|
507
|
+
end
|
508
|
+
expect { define_interface }.to(raise_error(NoMethodError))
|
509
|
+
end
|
506
510
|
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
+
it 'can name a shell action as something else' do
|
512
|
+
cli = Cliqr.interface do
|
513
|
+
name 'my-command'
|
514
|
+
handler TestCommand
|
515
|
+
color :disable
|
511
516
|
|
512
|
-
|
513
|
-
|
514
|
-
|
517
|
+
shell do
|
518
|
+
name 'my-custom-shell'
|
519
|
+
description 'this is a custom shell implementation'
|
520
|
+
end
|
521
|
+
end
|
515
522
|
|
516
|
-
|
523
|
+
expect(cli.usage).to eq <<-EOS
|
517
524
|
my-command
|
518
525
|
|
519
526
|
USAGE:
|
520
|
-
my-command [options] [arguments]
|
527
|
+
my-command [actions] [options] [arguments]
|
521
528
|
|
522
529
|
Available options:
|
523
530
|
|
524
|
-
--
|
525
|
-
EOS
|
526
|
-
end
|
527
|
-
|
528
|
-
it 'numeric option is 0 by default' do
|
529
|
-
cli = Cliqr.interface do
|
530
|
-
name 'my-command'
|
531
|
-
handler TestCommand
|
532
|
-
help :disable
|
531
|
+
--help, -h : Get helpful information for action "my-command" along with its usage information.
|
533
532
|
|
534
|
-
|
535
|
-
|
536
|
-
description 'another option'
|
537
|
-
type :numeric
|
533
|
+
Available actions:
|
534
|
+
[ Type "my-command help [action-name]" to get more information about that action ]
|
538
535
|
|
539
|
-
|
536
|
+
help -- The help action for command "my-command" which provides details and usage information on how to use the command.
|
537
|
+
my-custom-shell -- this is a custom shell implementation
|
538
|
+
EOS
|
540
539
|
end
|
541
540
|
end
|
542
|
-
|
543
|
-
expect(cli.usage).to eq <<-EOS
|
544
|
-
my-command
|
545
|
-
|
546
|
-
USAGE:
|
547
|
-
my-command [options] [arguments]
|
548
|
-
|
549
|
-
Available options:
|
550
|
-
|
551
|
-
--another, -a : <numeric> another option (default => 0)
|
552
|
-
EOS
|
553
541
|
end
|
554
542
|
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
543
|
+
describe 'actions and options' do
|
544
|
+
it 'allows command to have an action and an option' do
|
545
|
+
cli = Cliqr.interface do
|
546
|
+
name 'my-command'
|
547
|
+
handler TestCommand
|
548
|
+
help :disable
|
549
|
+
shell :disable
|
550
|
+
color :disable
|
560
551
|
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
default true
|
552
|
+
action 'my-action' do
|
553
|
+
description 'this is a test action'
|
554
|
+
arguments :disable
|
555
|
+
end
|
566
556
|
|
567
|
-
|
557
|
+
option 'option-1'
|
568
558
|
end
|
569
|
-
end
|
570
559
|
|
571
|
-
|
560
|
+
expect(cli.usage).to eq <<-EOS
|
572
561
|
my-command
|
573
562
|
|
574
563
|
USAGE:
|
575
|
-
my-command [options] [arguments]
|
564
|
+
my-command [actions] [options] [arguments]
|
576
565
|
|
577
566
|
Available options:
|
578
567
|
|
579
|
-
--
|
580
|
-
EOS
|
581
|
-
end
|
582
|
-
|
583
|
-
################ SHELL ACTION ################
|
568
|
+
--option-1
|
584
569
|
|
585
|
-
|
586
|
-
cli = Cliqr.interface do
|
587
|
-
name 'my-command'
|
588
|
-
handler TestCommand
|
589
|
-
help :disable
|
570
|
+
Available actions:
|
590
571
|
|
591
|
-
|
572
|
+
my-action -- this is a test action
|
573
|
+
EOS
|
592
574
|
end
|
593
575
|
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
576
|
+
it 'allows command to have an action with options' do
|
577
|
+
cli = Cliqr.interface do
|
578
|
+
name 'my-command'
|
579
|
+
handler TestCommand
|
580
|
+
help :disable
|
581
|
+
shell :disable
|
582
|
+
color :disable
|
601
583
|
|
602
|
-
|
584
|
+
action 'my-action' do
|
585
|
+
description 'this is a test action'
|
603
586
|
|
604
|
-
|
605
|
-
|
606
|
-
end
|
587
|
+
option 'action-option'
|
588
|
+
end
|
607
589
|
|
608
|
-
|
609
|
-
|
610
|
-
name 'my-command'
|
611
|
-
handler TestCommand
|
612
|
-
help :disable
|
613
|
-
end
|
590
|
+
option 'option-1'
|
591
|
+
end
|
614
592
|
|
615
|
-
|
593
|
+
expect(cli.usage).to eq <<-EOS
|
616
594
|
my-command
|
617
595
|
|
618
596
|
USAGE:
|
619
|
-
my-command [arguments]
|
620
|
-
|
621
|
-
|
597
|
+
my-command [actions] [options] [arguments]
|
598
|
+
|
599
|
+
Available options:
|
622
600
|
|
623
|
-
|
624
|
-
cli = Cliqr.interface do
|
625
|
-
name 'my-command'
|
601
|
+
--option-1
|
626
602
|
|
627
|
-
|
628
|
-
|
629
|
-
|
603
|
+
Available actions:
|
604
|
+
|
605
|
+
my-action -- this is a test action
|
606
|
+
EOS
|
630
607
|
end
|
631
|
-
result = cli.execute_internal %w(my-command bla), output: :buffer
|
632
|
-
expect(result[:stdout]).to eq <<-EOS
|
633
|
-
my-command bla
|
634
608
|
|
635
|
-
|
636
|
-
|
609
|
+
it 'allows command to have multiple actions and multiple options' do
|
610
|
+
cli = Cliqr.interface do
|
611
|
+
name 'my-command'
|
612
|
+
handler TestCommand
|
613
|
+
help :disable
|
614
|
+
shell :disable
|
615
|
+
color :disable
|
637
616
|
|
638
|
-
|
617
|
+
option 'option-1'
|
639
618
|
|
640
|
-
|
619
|
+
action 'my-action' do
|
620
|
+
description 'this is a test action'
|
641
621
|
|
642
|
-
|
643
|
-
|
622
|
+
option 'action-option'
|
623
|
+
end
|
644
624
|
|
645
|
-
|
625
|
+
option 'option-2'
|
646
626
|
|
647
|
-
|
648
|
-
|
649
|
-
|
627
|
+
action 'another-action' do
|
628
|
+
description 'this is another test action'
|
629
|
+
arguments :disable
|
630
|
+
end
|
650
631
|
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
end
|
656
|
-
result = cli.execute_internal %w(help), output: :buffer
|
657
|
-
expect(result[:stdout]).to eq <<-EOS
|
632
|
+
option 'option-3'
|
633
|
+
end
|
634
|
+
|
635
|
+
expect(cli.usage).to eq <<-EOS
|
658
636
|
my-command
|
659
637
|
|
660
638
|
USAGE:
|
@@ -662,44 +640,62 @@ USAGE:
|
|
662
640
|
|
663
641
|
Available options:
|
664
642
|
|
665
|
-
--
|
666
|
-
--
|
643
|
+
--option-1
|
644
|
+
--option-2
|
645
|
+
--option-3
|
667
646
|
|
668
647
|
Available actions:
|
669
|
-
[ Type "my-command help [action-name]" to get more information about that action ]
|
670
648
|
|
671
|
-
|
649
|
+
my-action -- this is a test action
|
650
|
+
another-action -- this is another test action
|
651
|
+
EOS
|
652
|
+
end
|
672
653
|
|
673
|
-
|
674
|
-
|
675
|
-
|
654
|
+
it 'allows nested actions with a mix of same options and same names' do
|
655
|
+
def define_interface
|
656
|
+
Cliqr.interface do
|
657
|
+
name 'my-command'
|
658
|
+
handler TestCommand
|
659
|
+
help :disable
|
660
|
+
shell :disable
|
661
|
+
color :disable
|
676
662
|
|
677
|
-
|
678
|
-
|
679
|
-
name 'my-command'
|
663
|
+
option 'test-option-1'
|
664
|
+
option 'test-option-2'
|
680
665
|
|
681
|
-
|
682
|
-
|
666
|
+
action 'my-action-1' do
|
667
|
+
action 'my-action-1' do
|
668
|
+
option 'test-option-1'
|
669
|
+
option 'test-option-2'
|
670
|
+
|
671
|
+
action 'my-action-1' do
|
672
|
+
option 'test-option-1'
|
673
|
+
option 'test-option-2'
|
674
|
+
end
|
675
|
+
end
|
676
|
+
end
|
677
|
+
|
678
|
+
action 'another-action' do
|
679
|
+
arguments :disable
|
680
|
+
end
|
681
|
+
end
|
683
682
|
end
|
684
|
-
|
685
|
-
|
686
|
-
expect(result[:stdout]).to eq <<-EOS
|
687
|
-
my-command bla
|
683
|
+
expect(define_interface.usage).to eq <<-EOS
|
684
|
+
my-command
|
688
685
|
|
689
686
|
USAGE:
|
690
|
-
my-command
|
687
|
+
my-command [actions] [options] [arguments]
|
691
688
|
|
692
689
|
Available options:
|
693
690
|
|
694
|
-
--
|
695
|
-
--
|
691
|
+
--test-option-1
|
692
|
+
--test-option-2
|
696
693
|
|
697
694
|
Available actions:
|
698
|
-
[ Type "my-command bla help [action-name]" to get more information about that action ]
|
699
|
-
|
700
|
-
version -- Get version information for command "my-command bla".
|
701
695
|
|
702
|
-
|
703
|
-
|
696
|
+
my-action-1
|
697
|
+
another-action
|
698
|
+
EOS
|
699
|
+
end
|
704
700
|
end
|
705
701
|
end
|