vagrant-devcommands 0.11.1 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +41 -41
- data/README.md +98 -84
- data/lib/vagrant/devcommands/command.rb +7 -13
- data/lib/vagrant/devcommands/commandfile/modeler.rb +3 -3
- data/lib/vagrant/devcommands/commandfile/reader.rb +10 -8
- data/lib/vagrant/devcommands/commandfile.rb +2 -0
- data/lib/vagrant/devcommands/help_printer/chain.rb +8 -6
- data/lib/vagrant/devcommands/help_printer/command.rb +8 -6
- data/lib/vagrant/devcommands/help_printer/command_alias.rb +8 -6
- data/lib/vagrant/devcommands/internal_command/completion_data.rb +2 -0
- data/lib/vagrant/devcommands/internal_command/help.rb +10 -8
- data/lib/vagrant/devcommands/internal_command/version.rb +2 -0
- data/lib/vagrant/devcommands/internal_spec.rb +12 -10
- data/lib/vagrant/devcommands/messages.rb +3 -6
- data/lib/vagrant/devcommands/model/chain.rb +3 -6
- data/lib/vagrant/devcommands/model/command.rb +14 -96
- data/lib/vagrant/devcommands/model/command_alias.rb +3 -9
- data/lib/vagrant/devcommands/param_parser.rb +131 -0
- data/lib/vagrant/devcommands/plugin.rb +2 -0
- data/lib/vagrant/devcommands/registry/messager.rb +14 -2
- data/lib/vagrant/devcommands/registry/resolver.rb +4 -8
- data/lib/vagrant/devcommands/registry/validator.rb +4 -2
- data/lib/vagrant/devcommands/registry.rb +70 -7
- data/lib/vagrant/devcommands/runner/chain.rb +2 -0
- data/lib/vagrant/devcommands/runner/command.rb +5 -3
- data/lib/vagrant/devcommands/runner/command_alias.rb +2 -0
- data/lib/vagrant/devcommands/runner/internal_command.rb +3 -1
- data/lib/vagrant/devcommands/synopsis.rb +3 -1
- data/lib/vagrant/devcommands/util/jaro_winkler.rb +5 -1
- data/lib/vagrant/devcommands/util.rb +4 -2
- data/lib/vagrant/devcommands/version.rb +3 -1
- data/lib/vagrant/devcommands.rb +4 -1
- data/locales/en.yml +2 -4
- metadata +19 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c87a4a5395ff70331bc828e00f95e4f2bd17b75dbc57561a9a512b2fa94d5402
|
4
|
+
data.tar.gz: ba566aeb333eb32fab9389b979df2f54e2326e0b98cd1beff1e94b07a52a45dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18314207fb498117756f3b0b1023c72c75c5c157408895e9d92fcc56f980039f8601f2797ca7013d0c9386f98349566662d4615f5bb329960ac895e49a4814e6
|
7
|
+
data.tar.gz: 6d92ec349743a1658fb1160b45f87c57eaf6785dba47f0c7130f4bf7249d35f40ea67897a6fdbd0b0c1fedf79711bc4d655f95e7650ea8de3e24b859d1aeb451
|
data/CHANGELOG.md
CHANGED
@@ -1,62 +1,68 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## v0.14.0 (2022-08-23)
|
4
|
+
|
5
|
+
- Enhancements
|
6
|
+
- Lambda/Proc values of command scripts are now executed in the instance of the command when running
|
7
|
+
- Lambda/Proc scripts get the parsed argv values as the first (and only) argument unless defined with a zero arity
|
8
|
+
|
9
|
+
- Bug fixes
|
10
|
+
- Parameters with a default value configured will now be properly displayed as optional in the detailed command help
|
11
|
+
|
12
|
+
## v0.13.0 (2018-07-19)
|
13
|
+
|
14
|
+
- Enhancements
|
15
|
+
- Unknown parameters can be catched and used by setting the option `passthru: true` on one of your parameters ([#3](https://github.com/mneudert/vagrant-devcommands/issues/3))
|
16
|
+
|
17
|
+
## v0.12.0 (2018-04-21)
|
18
|
+
|
19
|
+
- Enhancements
|
20
|
+
- Command parameters can define alias values to be replaced before escaping
|
21
|
+
- Commandfile entries with duplicate names will now issue a warning while still discarding all previous definitions
|
22
|
+
- Commandfile entries with unknown options will issue a warning
|
23
|
+
|
24
|
+
- Backwards incompatible changes
|
25
|
+
- Support for the already deprecated configuration parameter `:box` has been removed
|
26
|
+
|
3
27
|
## v0.11.1 (2017-10-04)
|
4
28
|
|
5
29
|
- Bug fixes
|
6
|
-
- The machine of a command alias definition is now correctly preferred over
|
7
|
-
the machine of the command definition
|
30
|
+
- The machine of a command alias definition is now correctly preferred over the machine of the command definition
|
8
31
|
|
9
32
|
## v0.11.0 (2017-10-02)
|
10
33
|
|
11
34
|
- Enhancements
|
12
|
-
- Command aliases can be used to provide multiple ways to call a single
|
13
|
-
command including automatically populated arguments
|
35
|
+
- Command aliases can be used to provide multiple ways to call a single command including automatically populated arguments
|
14
36
|
- Commands can define if they need a tty by using the new `:tty` option
|
15
37
|
|
16
38
|
- Backwards incompatible changes
|
17
|
-
- By default a command does not use a tty. This potentially breaks commands
|
18
|
-
requiring one, e.g. a mysql console command
|
39
|
+
- By default a command does not use a tty. This potentially breaks commands requiring one, e.g. a mysql console command
|
19
40
|
|
20
41
|
## v0.10.1 (2017-08-08)
|
21
42
|
|
22
43
|
- Bug fixes
|
23
|
-
- Vagrant introduced a tty flag for ssh command execution in version `1.9.6`.
|
24
|
-
This broke some commands requiring an interactive terminal
|
25
|
-
(like a mysql client). This flag is now permanently active to restore the
|
26
|
-
function of these commands until the next regular release introduces a
|
27
|
-
full per command tty configuration
|
44
|
+
- Vagrant introduced a tty flag for ssh command execution in version `1.9.6`. This broke some commands requiring an interactive terminal (like a mysql client). This flag is now permanently active to restore the function of these commands until the next regular release introduces a full per command tty configuration
|
28
45
|
|
29
46
|
## v0.10.0 (2017-07-02)
|
30
47
|
|
31
48
|
- Enhancements
|
32
|
-
- Command alternatives provided by the "did-you-mean" feature no longer
|
33
|
-
|
34
|
-
-
|
35
|
-
will be presented instead of a full command list (help)
|
36
|
-
- Minimal data for shell completion is available via the internal
|
37
|
-
`completion-data` command
|
49
|
+
- Command alternatives provided by the "did-you-mean" feature no longer display the full command list (help)
|
50
|
+
- Depending on the internal scoring multiple alternative commands will be presented instead of a full command list (help)
|
51
|
+
- Minimal data for shell completion is available via the internal `completion-data` command
|
38
52
|
- Parameters can limit the values you are allowed to pass in
|
39
|
-
- Spaces in chain/command names are now officially disallowed. Those
|
40
|
-
would have always been broken anyways, but now there is a nice message
|
41
|
-
and the commands are excluded from the various listings
|
53
|
+
- Spaces in chain/command names are now officially disallowed. Those would have always been broken anyways, but now there is a nice message and the commands are excluded from the various listings
|
42
54
|
|
43
55
|
- Bug fixes
|
44
|
-
- Chain names can no longer conflict with internal commands like `help`
|
45
|
-
or `version`. The respective chain definitions are dropped and a warning
|
46
|
-
is issued
|
56
|
+
- Chain names can no longer conflict with internal commands like `help` or `version`. The respective chain definitions are dropped and a warning is issued
|
47
57
|
|
48
58
|
## v0.9.0 (2017-05-20)
|
49
59
|
|
50
60
|
- Enhancements
|
51
61
|
- Every command in a chain can specify the machine to be used
|
52
|
-
- If an unknown command is requested a possible alternative
|
53
|
-
is suggested based on the calculated
|
54
|
-
[Jaro-Winkler distance](https://en.wikipedia.org/wiki/Jaro%E2%80%93Winkler_distance)
|
62
|
+
- If an unknown command is requested a possible alternative is suggested based on the calculated [Jaro-Winkler distance](https://en.wikipedia.org/wiki/Jaro%E2%80%93Winkler_distance)
|
55
63
|
|
56
64
|
- Deprecations
|
57
|
-
- The configuration parameter `:box` has been renamed to `:machine` to
|
58
|
-
match the vagrant naming. Support for the old configuration will be
|
59
|
-
dropped in a future version
|
65
|
+
- The configuration parameter `:box` has been renamed to `:machine` to match the Vagrant naming. Support for the old configuration will be dropped in a future version
|
60
66
|
|
61
67
|
## v0.8.0 (2017-04-19)
|
62
68
|
|
@@ -67,14 +73,12 @@
|
|
67
73
|
## v0.7.2 (2017-03-12)
|
68
74
|
|
69
75
|
- Bug fixes
|
70
|
-
- Machine names passed via argv are properly detected and used
|
71
|
-
([#1](https://github.com/mneudert/vagrant-devcommands/pull/1))
|
76
|
+
- Machine names passed via argv are properly detected and used ([#1](https://github.com/mneudert/vagrant-devcommands/pull/1))
|
72
77
|
|
73
78
|
## v0.7.1 (2017-02-15)
|
74
79
|
|
75
80
|
- Bug fixes
|
76
|
-
- Wrapping of optional parameters should now properly be done only if
|
77
|
-
at least an empty string is defined as a default value
|
81
|
+
- Wrapping of optional parameters should now properly be done only if at least an empty string is defined as a default value
|
78
82
|
|
79
83
|
## v0.7.0 (2016-09-26)
|
80
84
|
|
@@ -87,16 +91,12 @@
|
|
87
91
|
- Enhancements
|
88
92
|
- Command usage now displays the correct parameter syntax
|
89
93
|
- Command usage always displays mandatory parameters before optional ones
|
90
|
-
- Error output (e.g. "missing Commandfile") is now printed using
|
91
|
-
|
92
|
-
- Global commands can be defined using a file
|
93
|
-
named `.vagrant.devcommands` located under `Dir.home()`
|
94
|
+
- Error output (e.g. "missing Commandfile") is now printed using the configured ui class (allows colored output)
|
95
|
+
- Global commands can be defined using a file named `.vagrant.devcommands` located under `Dir.home()`
|
94
96
|
- Invalid parameters are displayed in the error message
|
95
97
|
- Missing parameters are displayed in the error message
|
96
|
-
- Parameter wrapping is only done if a value is passed
|
97
|
-
|
98
|
-
- Warnings about using internal command names or missing scripts are now
|
99
|
-
printed using the configured ui class (allows colored output)
|
98
|
+
- Parameter wrapping is only done if a value is passed or a default (at least empty string) is configured
|
99
|
+
- Warnings about using internal command names or missing scripts are now printed using the configured ui class (allows colored output)
|
100
100
|
|
101
101
|
## v0.5.0 (2016-03-21)
|
102
102
|
|
data/README.md
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# Vagrant DevCommands
|
2
2
|
|
3
|
-
Runs
|
4
|
-
|
3
|
+
Runs Vagrant commands from a Commandfile.
|
5
4
|
|
6
5
|
## Usage
|
7
6
|
|
@@ -32,7 +31,7 @@ Add to a `Commandfile` besides your `Vagrantfile`:
|
|
32
31
|
command 'basic', 'hostname'
|
33
32
|
|
34
33
|
command 'with_options',
|
35
|
-
machine:
|
34
|
+
machine: 'my_machine',
|
36
35
|
desc: 'executes "hostname" on the machine "my_machine"',
|
37
36
|
script: 'hostname',
|
38
37
|
tty: true,
|
@@ -46,28 +45,24 @@ of the command name using either %{command} or %<command>s.
|
|
46
45
|
eoh
|
47
46
|
```
|
48
47
|
|
49
|
-
_Note_: If you are defining literal `%` (percent sign) in your commands you
|
50
|
-
have to escape them using a second `%`. For example `date "+%%Y-%%m-%%d"`.
|
48
|
+
_Note_: If you are defining literal `%` (percent sign) in your commands you have to escape them using a second `%`. For example `date '+%%Y-%%m-%%d'`.
|
51
49
|
|
52
|
-
_Note_: Spaces in command names are not supported. Definitions with spaces will
|
53
|
-
be ignored.
|
50
|
+
_Note_: Spaces in command names are not supported. Definitions with spaces will be ignored.
|
54
51
|
|
55
|
-
_Note_: Please be aware that setting a custom `usage` hides the original usage
|
56
|
-
line from the help output.
|
52
|
+
_Note_: Please be aware that setting a custom `usage` hides the original usage line from the help output.
|
57
53
|
|
58
54
|
#### Commands with Parameters
|
59
55
|
|
60
|
-
Passing additional parameters to a command is (minimally) supported using an
|
61
|
-
sprintf syntax:
|
56
|
+
Passing additional parameters to a command is (minimally) supported using an sprintf syntax:
|
62
57
|
|
63
58
|
```ruby
|
64
59
|
command 'with_param',
|
65
60
|
parameters: {
|
66
61
|
# mandatory parameter with a description
|
67
|
-
p_mandatory: { desc:
|
62
|
+
p_mandatory: { desc: 'mandatory parameter to do... stuff!' },
|
68
63
|
|
69
64
|
# parameter with default (implies optional)
|
70
|
-
p_default: { default:
|
65
|
+
p_default: { default: 'always' },
|
71
66
|
|
72
67
|
# parameter with escaping rule
|
73
68
|
p_escaped: { escape: { '*' => '\\' }},
|
@@ -76,52 +71,64 @@ command 'with_param',
|
|
76
71
|
p_optional: { optional: true },
|
77
72
|
|
78
73
|
# wrapped option value
|
79
|
-
p_wrapped: { wrap:
|
74
|
+
p_wrapped: { wrap: '--and %s wrapped' },
|
75
|
+
|
76
|
+
# parameters with aliased values
|
77
|
+
# the aliases are resolved prior to escaping/wrapping/allowance!
|
78
|
+
# aliases are resolved in order of definition (multiple can apply)
|
79
|
+
p_aliased: { aliases: { 'foo' => 'bar' }},
|
80
80
|
|
81
81
|
# parameters with a limited set of allowed values
|
82
82
|
# the allowed values are checked prior to escaping/wrapping!
|
83
83
|
# optional parameters are only validated if given!
|
84
|
-
p_limited: { allowed: ['completely'] }
|
84
|
+
p_limited: { allowed: ['completely'] },
|
85
|
+
|
86
|
+
# you can define a specific parameter to receive
|
87
|
+
# all otherwise unknown parameters and flags
|
88
|
+
p_passthru: { optional: true, passthru: true }
|
85
89
|
},
|
86
|
-
script:
|
90
|
+
script: %(
|
91
|
+
echo %<p_mandatory>s \
|
92
|
+
%<p_default>s \
|
93
|
+
%<p_escaped>s \
|
94
|
+
%<p_optional>s \
|
95
|
+
%<p_wrapped>s \
|
96
|
+
%<p_limited>s \
|
97
|
+
%<p_passthru>s
|
98
|
+
)
|
87
99
|
```
|
88
100
|
|
89
101
|
This allows you to execute the following command:
|
90
102
|
|
91
103
|
```shell
|
92
|
-
# will execute 'echo works always'
|
104
|
+
# will execute 'echo "works always"'
|
93
105
|
vagrant run with_param --p_mandatory works
|
94
106
|
|
95
|
-
# will execute 'echo works always like a charm'
|
96
|
-
vagrant run with_param --p_mandatory works --p_optional
|
107
|
+
# will execute 'echo "works always like a charm"'
|
108
|
+
vagrant run with_param --p_mandatory works --p_optional 'like a charm'
|
97
109
|
|
98
|
-
# will execute 'echo works sometimes like a charm --and is wrapped completely'
|
110
|
+
# will execute 'echo "works sometimes like a charm --and is wrapped completely"'
|
99
111
|
vagrant run with_param \
|
100
112
|
--p_mandatory works \
|
101
113
|
--p_default sometimes \
|
102
|
-
--p_optional
|
103
|
-
--p_wrapped is
|
114
|
+
--p_optional 'like a charm' \
|
115
|
+
--p_wrapped is \
|
104
116
|
--p_limited completely
|
105
117
|
```
|
106
118
|
|
107
|
-
For now a command expecting one or more parameters will fail if the user does
|
108
|
-
not provide them. Any arguments exceeding the number used are silently
|
109
|
-
discarded.
|
119
|
+
For now a command expecting one or more parameters will fail if the user does not provide them. Any arguments exceeding the number used are silently discarded.
|
110
120
|
|
111
|
-
Escaping rules are defined as `{
|
112
|
-
These are applied prior to interpolation into the command. Regular ruby escaping
|
113
|
-
rules apply.
|
121
|
+
Escaping rules are defined as `{ 'char_to_escape' => 'char_to_use_as_escape' }`. These are applied prior to interpolation into the command. Regular ruby escaping rules apply.
|
114
122
|
|
115
123
|
#### Commands with Flags
|
116
124
|
|
117
|
-
Every command can be associated with (by definition optional) flags available
|
118
|
-
for later command interpolation:
|
125
|
+
Every command can be associated with (by definition optional) flags available for later command interpolation:
|
119
126
|
|
120
127
|
```ruby
|
121
128
|
command 'with_flags',
|
122
129
|
flags: {
|
123
|
-
f_standard: { desc:
|
124
|
-
f_valued: { value:
|
130
|
+
f_standard: { desc: 'standard flag' },
|
131
|
+
f_valued: { value: '--f_modified' }
|
125
132
|
},
|
126
133
|
script: 'echo "flags: %<f_standard>s"'
|
127
134
|
```
|
@@ -139,28 +146,46 @@ vagrant run with_flags --f_standard
|
|
139
146
|
vagrant run with_flags --f_valued
|
140
147
|
```
|
141
148
|
|
142
|
-
By default a flag gets interpolated as
|
143
|
-
this value will be interpolated unmodified.
|
149
|
+
By default a flag gets interpolated as `--#{flagname}`. If a value is defined this value will be interpolated unmodified.
|
144
150
|
|
145
151
|
#### Commands defined by Lambda/Proc
|
146
152
|
|
147
|
-
You can (more or less) dynamically generate your scripts by defining the
|
148
|
-
command with a lambda or proc as its script.
|
153
|
+
You can (more or less) dynamically generate your scripts by defining the command with a lambda or proc as its script.
|
149
154
|
|
150
155
|
```ruby
|
151
156
|
command 'from_lambda', script: lambda { 'echo "lambda works"' }
|
152
157
|
command 'from_proc', script: proc { 'echo "proc works"' }
|
158
|
+
|
159
|
+
command 'from_lambda_params',
|
160
|
+
parameters: { argv_param: {} },
|
161
|
+
script: lambda { |params|
|
162
|
+
'echo "lambda works: ' + params[:argv_param] + '"'
|
163
|
+
}
|
164
|
+
|
165
|
+
command 'from_proc_params',
|
166
|
+
parameters: { argv_param: {} },
|
167
|
+
script: proc { |params|
|
168
|
+
'echo "proc works: ' + params[:argv_param] + '"'
|
169
|
+
}
|
153
170
|
```
|
154
171
|
|
155
|
-
These will be evaluated when running the command.
|
172
|
+
These will be evaluated when running the command and optionally received the parsed shell arguments when defined with an arity of one.
|
173
|
+
|
174
|
+
Every rule from regular scripts (parameters, escaping `%`, ...) still apply.
|
175
|
+
|
176
|
+
#### Commands with a TTY ("interactive")
|
177
|
+
|
178
|
+
If you have a command that expects some sort of interaction with the user you may need to set the `tty` option for a command:
|
179
|
+
|
180
|
+
```ruby
|
181
|
+
command 'interactive', tty: true
|
182
|
+
```
|
156
183
|
|
157
|
-
|
184
|
+
This allows full interaction with programs like `irb` or `mysql`.
|
158
185
|
|
159
186
|
### Global Command Definitions
|
160
187
|
|
161
|
-
To have commands available even wihout a `Commandfile` you can define the
|
162
|
-
globally. To do this just create a file named `.vagrant.devcommands` in your
|
163
|
-
`$HOME` directory.
|
188
|
+
To have commands available even wihout a `Commandfile` you can define the globally. To do this just create a file named `.vagrant.devcommands` in your `$HOME` directory.
|
164
189
|
|
165
190
|
You can use this command to find the correct path if unsure:
|
166
191
|
|
@@ -191,20 +216,15 @@ eoh
|
|
191
216
|
|
192
217
|
The configured commands will be executed in the order defined.
|
193
218
|
|
194
|
-
If one or more of your commands requires parameters all of them have to be
|
195
|
-
passed to the chain execution.
|
219
|
+
If one or more of your commands requires parameters all of them have to be passed to the chain execution.
|
196
220
|
|
197
|
-
By default a chain breaks upon the first non-zero return value of any
|
198
|
-
configured command. To deactivate this behaviour you can set `:break_on_error`
|
199
|
-
to `false`. Any value other than `false` will stick to the default.
|
221
|
+
By default a chain breaks upon the first non-zero return value of any configured command. To deactivate this behaviour you can set `:break_on_error` to `false`. Any value other than `false` will stick to the default.
|
200
222
|
|
201
|
-
_Note_: Spaces in command names are not supported. Definitions with spaces will
|
202
|
-
be ignored.
|
223
|
+
_Note_: Spaces in command names are not supported. Definitions with spaces will be ignored.
|
203
224
|
|
204
225
|
#### Chain Definitions with Pre-Defined Parameters
|
205
226
|
|
206
|
-
If required you can modify the arguments given to each chain element by setting
|
207
|
-
additional/custom argv values for a single chain element:
|
227
|
+
If required you can modify the arguments given to each chain element by setting additional/custom argv values for a single chain element:
|
208
228
|
|
209
229
|
```ruby
|
210
230
|
command 'chainecho',
|
@@ -222,16 +242,14 @@ chain 'my_customized_chain',
|
|
222
242
|
Running the chain will execute the following commands:
|
223
243
|
|
224
244
|
```shell
|
225
|
-
> vagrant run my_customized_chain --first=
|
245
|
+
> vagrant run my_customized_chain --first='initial' --second='initial'
|
226
246
|
|
227
|
-
vagrant run chainecho --first=
|
228
|
-
vagrant run chainecho --first=
|
229
|
-
vagrant run chainecho --first=
|
247
|
+
vagrant run chainecho --first='param' --second='initial'
|
248
|
+
vagrant run chainecho --first='initial' --second='initial'
|
249
|
+
vagrant run chainecho --first='param' --second='param'
|
230
250
|
```
|
231
251
|
|
232
|
-
By default every command will be executed using the machine defined by the
|
233
|
-
command itself or the only one available. You can, however, run the complete
|
234
|
-
chain against a specific machine using `vagrant run your_machine your_chain`.
|
252
|
+
By default every command will be executed using the machine defined by the command itself or the only one available. You can, however, run the complete chain against a specific machine using `vagrant run your_machine your_chain`.
|
235
253
|
|
236
254
|
#### Chain Definitions with Specific Machines
|
237
255
|
|
@@ -259,13 +277,11 @@ vagrant run secondary chainhost
|
|
259
277
|
vagrant run tertiary chainhost
|
260
278
|
```
|
261
279
|
|
262
|
-
This configuration can itself be modified by passing a machine name to run
|
263
|
-
all chain commands on using using `vagrant run your_machine your_chain`.
|
280
|
+
This configuration can itself be modified by passing a machine name to run all chain commands on using using `vagrant run your_machine your_chain`.
|
264
281
|
|
265
282
|
### Abort Parsing inside Commandfile
|
266
283
|
|
267
|
-
If you, for whatever reasons, want to abort further parsing of a `Commandfile`
|
268
|
-
you can simple return from it:
|
284
|
+
If you, for whatever reasons, want to abort further parsing of a `Commandfile` you can simple return from it:
|
269
285
|
|
270
286
|
```ruby
|
271
287
|
command 'foo', script: 'foo'
|
@@ -280,16 +296,13 @@ return if v_cur < v_min
|
|
280
296
|
command 'bar', script: 'bar'
|
281
297
|
```
|
282
298
|
|
283
|
-
This example leads to the command `bar` not being available if the currently
|
284
|
-
installed plugin has a version below `1.3.3.7`.
|
299
|
+
This example leads to the command `bar` not being available if the currently installed plugin has a version below `1.3.3.7`.
|
285
300
|
|
286
|
-
Please be aware that returning from a global commandfile completely skips
|
287
|
-
evaluating a local one.
|
301
|
+
Please be aware that returning from a global commandfile completely skips evaluating a local one.
|
288
302
|
|
289
|
-
###
|
303
|
+
### Command Alias Definitions
|
290
304
|
|
291
|
-
For commands you want to keep generic but often call with a specific set of
|
292
|
-
parameter values you can define an alias:
|
305
|
+
For commands you want to keep generic but often call with a specific set of parameter values you can define an alias:
|
293
306
|
|
294
307
|
```ruby
|
295
308
|
command 'customecho',
|
@@ -307,9 +320,7 @@ I get displayed when running "vagrant run help aliasecho".
|
|
307
320
|
eoh
|
308
321
|
```
|
309
322
|
|
310
|
-
The setting `command` is required, the other options `argv` and `machine` are
|
311
|
-
optional and used for the actual customization. Any argument configured will
|
312
|
-
take precedence over the value given to `vagrant run` itself.
|
323
|
+
The setting `command` is required, the other options `argv` and `machine` are optional and used for the actual customization. Any argument configured will take precedence over the value given to `vagrant run` itself.
|
313
324
|
|
314
325
|
### Experimental: Shell Completion
|
315
326
|
|
@@ -323,35 +334,38 @@ vagrant run completion-data
|
|
323
334
|
vagrant run completion-data my-command
|
324
335
|
```
|
325
336
|
|
326
|
-
|
327
337
|
## Notes for Windows Users
|
328
338
|
|
329
339
|
### SSH
|
330
340
|
|
331
|
-
If you are using this plugin on a Windows host system, please make sure your
|
332
|
-
regular `vagrant ssh [machine]` succeeds. In some cases you may need to add the
|
333
|
-
`ssh.exe` (e.g. from a git installation) manually to your `%PATH%`.
|
341
|
+
If you are using this plugin on a Windows host system, please make sure your regular `vagrant ssh [machine]` succeeds. In some cases you may need to add the `ssh.exe` (e.g. from a git installation) manually to your `%PATH%`.
|
334
342
|
|
335
343
|
### Command Definition
|
336
344
|
|
337
|
-
When using multi-line commands you probably need to define your command using
|
338
|
-
a sigil notation like the following:
|
345
|
+
When using multi-line commands you probably need to define your command using a sigil notation like the following:
|
339
346
|
|
340
347
|
```ruby
|
341
348
|
command 'long_running_task',
|
342
349
|
script: %(cd /path/to/somewhere \
|
343
|
-
&& echo
|
350
|
+
&& echo 'starting long running task' \
|
344
351
|
&& ./long_running_task.sh \
|
345
|
-
&& echo
|
352
|
+
&& echo 'finished long running task')
|
346
353
|
```
|
347
354
|
|
348
|
-
Using a quote delimited command definition might otherwise result in not that
|
349
|
-
|
355
|
+
Using a quote delimited command definition might otherwise result in not that helpful error messages about a bad shell command.
|
356
|
+
|
357
|
+
It might also help to double check the line endings in your Commandfile are set unix-style (`\n`) and not windows-style (`\r\n`) if you get errors when running your commands.
|
350
358
|
|
351
|
-
|
352
|
-
unix-style (`\n`) and not windows-style (`\r\n`) if you get errors when running
|
353
|
-
your commands.
|
359
|
+
## Development
|
354
360
|
|
361
|
+
You can always install the plugin directly from source:
|
362
|
+
|
363
|
+
```shell
|
364
|
+
gem build vagrant-devcommands.gemspec
|
365
|
+
|
366
|
+
vagrant plugin uninstall vagrant-devcommands
|
367
|
+
vagrant plugin install vagrant-devcommands-x.x.x.dev.gem
|
368
|
+
```
|
355
369
|
|
356
370
|
## License
|
357
371
|
|
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module VagrantPlugins
|
2
4
|
module DevCommands
|
3
5
|
# Defines the executable vagrant command
|
4
6
|
class Command < Vagrant.plugin(2, :command)
|
5
|
-
I18N_KEY = 'vagrant_devcommands.'
|
7
|
+
I18N_KEY = 'vagrant_devcommands.'
|
6
8
|
|
7
9
|
def self.synopsis
|
8
10
|
synopsis = VagrantPlugins::DevCommands::SYNOPSIS
|
@@ -19,8 +21,6 @@ module VagrantPlugins
|
|
19
21
|
def execute
|
20
22
|
return 127 unless read_commandfile
|
21
23
|
|
22
|
-
deprecated_box_config?
|
23
|
-
|
24
24
|
command = Util.argv_command(@argv, @env)
|
25
25
|
|
26
26
|
return 127 unless non_empty?(command)
|
@@ -47,12 +47,6 @@ module VagrantPlugins
|
|
47
47
|
@registry.available?(command)
|
48
48
|
end
|
49
49
|
|
50
|
-
def deprecated_box_config?
|
51
|
-
return unless @registry.commands.values.any?(&:deprecated_box_config)
|
52
|
-
|
53
|
-
Messages.deprecated_box_config(&@env.ui.method(:warn))
|
54
|
-
end
|
55
|
-
|
56
50
|
def display_alternatives(command)
|
57
51
|
alternatives = Util.did_you_mean(command, @registry)
|
58
52
|
alternatives = alternatives.select { |_k, v| v > 0.8 }
|
@@ -60,15 +54,15 @@ module VagrantPlugins
|
|
60
54
|
return false if alternatives.empty?
|
61
55
|
|
62
56
|
if alternatives.length == 1
|
63
|
-
display_error(I18n.t("#{I18N_KEY}.did_you_mean_single"), true)
|
57
|
+
display_error(I18n.t("#{I18N_KEY}.did_you_mean_single"), pre_ln: true)
|
64
58
|
else
|
65
|
-
display_error(I18n.t("#{I18N_KEY}.did_you_mean_multi"), true)
|
59
|
+
display_error(I18n.t("#{I18N_KEY}.did_you_mean_multi"), pre_ln: true)
|
66
60
|
end
|
67
61
|
|
68
62
|
alternatives.sort.each { |(k, _v)| display_error(" #{k}") }
|
69
63
|
end
|
70
64
|
|
71
|
-
def display_error(msg, pre_ln
|
65
|
+
def display_error(msg, pre_ln: false, post_ln: false)
|
72
66
|
@env.ui.error '' if pre_ln
|
73
67
|
@env.ui.error msg
|
74
68
|
@env.ui.error '' if post_ln
|
@@ -104,7 +98,7 @@ module VagrantPlugins
|
|
104
98
|
|
105
99
|
runner.run(runnable)
|
106
100
|
rescue RuntimeError => e
|
107
|
-
display_error(e.message,
|
101
|
+
display_error(e.message, post_ln: true)
|
108
102
|
run_internal('help', [command])
|
109
103
|
|
110
104
|
nil
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module VagrantPlugins
|
2
4
|
module DevCommands
|
3
5
|
class Commandfile
|
@@ -33,9 +35,7 @@ module VagrantPlugins
|
|
33
35
|
options = { script: options } unless options.is_a?(Hash)
|
34
36
|
options[:name] = name
|
35
37
|
|
36
|
-
unless valid_script?(options[:script])
|
37
|
-
raise ArgumentError, 'command_no_script'
|
38
|
-
end
|
38
|
+
raise ArgumentError, 'command_no_script' unless valid_script?(options[:script])
|
39
39
|
|
40
40
|
VagrantPlugins::DevCommands::Model::Command.new(options)
|
41
41
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module VagrantPlugins
|
2
4
|
module DevCommands
|
3
5
|
class Commandfile
|
@@ -17,8 +19,8 @@ module VagrantPlugins
|
|
17
19
|
local = @commandfile.path
|
18
20
|
|
19
21
|
contents = ''
|
20
|
-
contents += "\n
|
21
|
-
contents += "\n
|
22
|
+
contents += "\n#{global.read}" unless global.nil?
|
23
|
+
contents += "\n#{local.read}" unless local.nil?
|
22
24
|
|
23
25
|
instance_eval(contents)
|
24
26
|
|
@@ -29,24 +31,24 @@ module VagrantPlugins
|
|
29
31
|
|
30
32
|
def chain(name, options = nil)
|
31
33
|
@entries << {
|
32
|
-
type:
|
33
|
-
name:
|
34
|
+
type: :chain,
|
35
|
+
name: name.to_s,
|
34
36
|
options: options
|
35
37
|
}
|
36
38
|
end
|
37
39
|
|
38
40
|
def command(name, options = nil)
|
39
41
|
@entries << {
|
40
|
-
type:
|
41
|
-
name:
|
42
|
+
type: :command,
|
43
|
+
name: name.to_s,
|
42
44
|
options: options
|
43
45
|
}
|
44
46
|
end
|
45
47
|
|
46
48
|
def command_alias(name, options = nil)
|
47
49
|
@entries << {
|
48
|
-
type:
|
49
|
-
name:
|
50
|
+
type: :command_alias,
|
51
|
+
name: name.to_s,
|
50
52
|
options: options
|
51
53
|
}
|
52
54
|
end
|
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module VagrantPlugins
|
2
4
|
module DevCommands
|
3
5
|
module HelpPrinter
|
4
6
|
# Prints help for a command chain
|
5
7
|
class Chain
|
6
|
-
I18N_KEY = 'vagrant_devcommands.internal.help'
|
8
|
+
I18N_KEY = 'vagrant_devcommands.internal.help'
|
7
9
|
UTIL = VagrantPlugins::DevCommands::Util
|
8
10
|
MESSAGES = VagrantPlugins::DevCommands::Messages
|
9
11
|
|
@@ -20,9 +22,9 @@ module VagrantPlugins
|
|
20
22
|
private
|
21
23
|
|
22
24
|
def body(help)
|
23
|
-
return message(:chain_no_help, true) if help.nil?
|
25
|
+
return message(:chain_no_help, pre_ln: true) if help.nil?
|
24
26
|
|
25
|
-
info(help.strip, true)
|
27
|
+
info(help.strip, pre_ln: true)
|
26
28
|
end
|
27
29
|
|
28
30
|
def chain_help_line(cmd)
|
@@ -32,7 +34,7 @@ module VagrantPlugins
|
|
32
34
|
end
|
33
35
|
|
34
36
|
def commands(chain)
|
35
|
-
info('Chained commands (in order):', true)
|
37
|
+
info('Chained commands (in order):', pre_ln: true)
|
36
38
|
|
37
39
|
chain.commands.each do |cmd|
|
38
40
|
info(UTIL.padded_columns(0, chain_help_line(cmd)))
|
@@ -50,12 +52,12 @@ module VagrantPlugins
|
|
50
52
|
info(I18n.t("#{I18N_KEY}.usage", what: usage))
|
51
53
|
end
|
52
54
|
|
53
|
-
def info(msg, pre_ln
|
55
|
+
def info(msg, pre_ln: false)
|
54
56
|
@env.ui.info '' if pre_ln
|
55
57
|
@env.ui.info msg
|
56
58
|
end
|
57
59
|
|
58
|
-
def message(msg, pre_ln
|
60
|
+
def message(msg, pre_ln: false)
|
59
61
|
if pre_ln
|
60
62
|
MESSAGES.pre_ln(msg, &@env.ui.method(:info))
|
61
63
|
else
|