bashly 0.3.0 → 0.3.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b40fa2dc3cc6b3f0f65b961ea06dab0230eb0346eaa7c51575f12e27f16bcc3e
4
- data.tar.gz: 704cc06b8d06539c123d2fabd450764fa8926705acc584ef47da87e5f2ab3e87
3
+ metadata.gz: 457aceee843507aa8834ede40e17d0ede1bfdfadea943688d5d74277bdee1446
4
+ data.tar.gz: 56b445b5d0517045e5deafbd994bce1ef5cf60b8fae536bd522a53d82bf20bf4
5
5
  SHA512:
6
- metadata.gz: 6b5755ebda8ded8cc3a414063b8c9f7559b34fb5682d8f351f55f2be768ac4d39868cacca11c7b6a39741f3c00b13c8ee1f2d14d24307518f8e9954afabbe3d4
7
- data.tar.gz: 540459bf266a62c289fd0fc0799f45e0e72bfbe3117dcf975ad623c022beba7327f97331d6a6539b69901ccf82fc2696a329622f0b7126951fc53cfdf583d0c7
6
+ metadata.gz: 00f9df5aa5d43035267d49ec83ccfff4225f8866da6b350ee085d42e968ab04739feacbcf6e85a5d105f6c40ccc504f1be6bc2423a87c96c2a740157f6fd8fd6
7
+ data.tar.gz: d372d3e369e6d3a3e54a6630285db36251b89149717813248e1370ee9f2ec93ea98d594addc68e1499174e2b48a0c1bc67a9c7c437b7f71abe4fd7e80651c02e
data/README.md CHANGED
@@ -133,147 +133,59 @@ The `bashly.yml` configuration file consists of these types:
133
133
  Unless otherwise specified, these definitiona can be used for both the root
134
134
  command and subcommands (under the `commands` definition).
135
135
 
136
- ```yaml
137
- # The name of the script or subcommand
138
- name: myscript
139
-
140
- # An additional, optional pattern - usually used to denote a one letter
141
- # variation of the command name.
142
- # You can add '*' as suffix, to denote a "starts with" pattern.
143
- # Applicable only in subcommands
144
- short: m*
145
-
146
- # The header text to display when using --help
147
- # This can have multiple lines. In this case, the first line will be used as
148
- # summary wherever appropriate.
149
- help: a sample script generated with bashly
150
-
151
- # The string to display when using --version
152
- # Applicable only in the main command
153
- version: 0.1.0
154
-
155
- # Specify an array of examples to show when using --help
156
- # Each example can have multiple lines.
157
- examples:
158
- - myscript download
159
- - myscript download --force
160
-
161
- # Specify an array of environment variables needed by your script.
162
- environment_variables:
163
- - ... see below ...
164
-
165
- # Specify the array of subcommands to generate.
166
- # Each subcommand will have its own args and flags.
167
- # If this is provided, you cannot specify flags or args.
168
- commands:
169
- - ...
170
-
171
- # Specify the array of positional arguments this script needs.
172
- # If this is provided, then you cannot specify commands.
173
- args:
174
- - ... see below ...
175
-
176
- # Specify the array of option flags this script needs.
177
- # If this is provided, then you cannot specify commands.
178
- flags:
179
- - ... see below ...
180
-
181
- # Specify an array of any required external dependencies (commands).
182
- # The script execution will be halted with a friendly error unless all
183
- # dependency commands exist.
184
- dependencies:
185
- - curl
186
- ```
187
136
 
137
+ Option | Description
138
+ -----------|-------------
139
+ `name` | The name of the script or subcommand.
140
+ `short` | An additional, optional pattern - usually used to denote a one letter variation of the command name. You can add `*` as a suffix, to denote a "starts with" pattern - for example `short: m*`. *Applicable only in subcommands*.
141
+ `help` | The header text to display when using `--help`. This option can have multiple lines. In this case, the first line will be used as summary wherever appropriate.
142
+ `version` | The string to display when using `--version`. *Applicable only in the main command*.
143
+ `default` | Setting this to `yes` on any subcommand, will make unrecognized command line arguments to be passed to this command. *Applicable only in subcommands*.
144
+ `examples` | Specify an array of examples to show when using `--help`. Each example can have multiple lines.
145
+ `environment_variables` | Specify an array of environment variables needed by your script.
146
+ `commands` | Specify the array of subcommands. Each subcommand will have its own args and flags. Note: if `commands` is provided, you cannot specify flags or args at the same level.
147
+ `args` | Specify the array of positional arguments this script needs.
148
+ `flags` | Specify the array of option flags this script needs.
149
+ `dependencies` | Specify an array of any required external dependencies (commands). The script execution will be halted with a friendly error unless all dependency commands exist.
188
150
 
189
151
  ### Argument options
190
152
 
191
- The below configuration generates this argument:
192
-
193
- ```
194
- Usage:
195
- myscript USER
196
-
197
- Arguments:
198
- USER
199
- Username to use for logging in
200
- ```
201
-
202
153
  The argument's value will be available to you as `${args[user]}` in your
203
154
  bash function.
204
155
 
205
- ```yaml
206
- # The name of the argument.
207
- name: user
208
-
209
- # The message to display when using --help.
210
- # This can have multiple lines.
211
- help: Username to use for logging in
212
-
213
- # Specify if this argument is required.
214
- # Note that once you define an optional argument (without required: true)
215
- # then you cannot define required arguments after it.
216
- required: true
217
- ```
156
+ Option | Description
157
+ -----------|-------------
158
+ `name` | The name of the argument.
159
+ `help` | The message to display when using `--help`. Can have multiple lines.
160
+ `required` | Specify if this argument is required. Note that once you define an optional argument (without required: true) then you cannot define required arguments after it.
218
161
 
219
162
  ### Flag options
220
163
 
221
- The below configuration generates this flag:
222
-
223
- ```
224
- Options:
225
- -o, --output DIRECTORY (required)
226
- Specify the output directory
227
- ```
228
-
229
164
  The flag's value will be available to you as `${args[--output]}` in your
230
165
  bash function (regardless of whether the user provided ut with the long or
231
166
  short form).
232
167
 
233
- ```yaml
234
- # The long form of the flag.
235
- long: --output
236
-
237
- # The short form of the flag.
238
- short: -o
239
-
240
- # The text to display when using --help
241
- # This can have multiple lines.
242
- help: Specify the output directory
243
-
244
- # If the flag requires an argument, specify its name here.
245
- arg: directory
246
-
247
- # Specify if this flag is required.
248
- required: true
249
- ```
168
+ Option | Description
169
+ -----------|-------------
170
+ `long` | The long form of the flag.
171
+ `short` | The short form of the flag.
172
+ `help` | The text to display when using `--help`. Can have multiple lines.
173
+ `arg` | If the flag requires an argument, specify its name here.
174
+ `required` | Specify if this flag is required.
250
175
 
251
176
  ### Environment Variable options
252
177
 
253
178
  The below configuration generates this environment variable usage text:
254
179
 
255
- ```
256
- Environment Variables:
257
- SECRET_KEY (required)
258
- Your API secret key
259
- ```
260
-
261
180
  If an environment variable is defined as required (false by default), the
262
181
  execution of the script will be halted with a friendly error if it is not
263
182
  set.
264
183
 
265
- ```yaml
266
- # The name of the variable (it will be automatically capitalized).
267
- name: secret_key
268
-
269
- # The message to display when using --help.
270
- # This can have multiple lines.
271
- help: Your API secret key
272
-
273
- # Specify if this variable is required.
274
- required: true
275
- ```
276
-
184
+ Option | Description
185
+ -----------|-------------
186
+ `name` | The name of the variable (it will be automatically capitalized).
187
+ `help` | The message to display when using --help. Can have multiple lines.
188
+ `required` | Specify if this variable is required.
277
189
 
278
190
 
279
191
  Real World Examples
@@ -9,6 +9,7 @@ module Bashly
9
9
  arg
10
10
  dependencies
11
11
  description
12
+ default
12
13
  environment_variables
13
14
  examples
14
15
  flags
@@ -55,6 +55,12 @@ module Bashly
55
55
  result
56
56
  end
57
57
 
58
+ # If any of this command's subcommands has the default option set to
59
+ # true, this default command will be returned, nil otherwise.
60
+ def default_command
61
+ commands.find { |c| c.default }
62
+ end
63
+
58
64
  # Returns an array of EnvironmentVariables
59
65
  def environment_variables
60
66
  return [] unless options["environment_variables"]
@@ -1,3 +1,3 @@
1
1
  module Bashly
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -15,11 +15,25 @@ case $action in
15
15
  ;;
16
16
 
17
17
  <%- end -%>
18
+ <%- if default_command -%>
19
+ "" )
20
+ <%= function_name %>_usage
21
+ exit 1
22
+ ;;
23
+
24
+ * )
25
+ action="<%= default_command.name %>"
26
+ <%= default_command.function_name %>_parse_requirements "$@"
27
+ shift $#
28
+ ;;
29
+
30
+ <%- else -%>
18
31
  * )
19
32
  <%= function_name %>_usage
20
33
  exit 1
21
34
  ;;
22
35
 
36
+ <%- end -%>
23
37
  esac
24
38
  <%- else -%>
25
39
  action="<%= action_name %>"
@@ -2,6 +2,8 @@
2
2
  echo -e "<%= strings[:commands] %>"
3
3
  <%- maxlen = command_names.map(&:size).max -%>
4
4
  <%- commands.each do |command| -%>
5
- echo " <%= command.name.ljust maxlen %> <%= command.summary %>"
5
+ <%- summary = command.summary -%>
6
+ <%- summary = "#{summary} (default)" if command.default -%>
7
+ echo " <%= command.name.ljust maxlen %> <%= summary %>"
6
8
  <%- end -%>
7
9
  echo
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bashly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-28 00:00:00.000000000 Z
11
+ date: 2019-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colsole