bashly 0.4.5 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ebe193249a02f2a5d25cd5a80a3172dbbc43ea16d18653368e4687841f19846c
4
- data.tar.gz: d38bbde76e731eaf5a0455edc8b47ef011c6c8dba40ec9a220f7747bb98b238c
3
+ metadata.gz: 6b573ae52d9c93016675adc209eeb011d3f6897791b0e159e25af5a76e7290d6
4
+ data.tar.gz: 69b99fb9b6729dd21d748688c11041130f3e35852212d148afe8af715b13804f
5
5
  SHA512:
6
- metadata.gz: d0963491e70542e96061395cbe7568d8c77014024ca53bdf2e56c93c3a2588bd5d46ea9e6952d8d0c1166772e46d47f69227c0e45e763970120a805079cd60a8
7
- data.tar.gz: 9896cbf1635cf43f30c42452273c93bed40fbb4d126d9dcf921fdc6a9609b3db70a0a2cee5e7753e8974a182b550c3976ac8d45d968399ed870f0c27ca43d73e
6
+ metadata.gz: f624d54df411325e3b4b6c8446a56d6e6bbd22e9caa2310c13d4c9d254920f84db1f19684355255374cbfa41653020a9f9d848acfa97afb88d76e448928f00d7
7
+ data.tar.gz: 1a98f13669d2de4a9b092afba7fdaebff16c0647a41ccf1696b6abdcda114661e6fb9995cfba1e0da348e30c79a9ae0777078bff3fc8a82cdcfd650c152c528b
data/README.md CHANGED
@@ -31,6 +31,7 @@ Create beautiful bash scripts from simple YAML configuration
31
31
  - [Argument options](#argument-options)
32
32
  - [Flag options](#flag-options)
33
33
  - [Environment Variable options](#environment-variable-options)
34
+ - [Extensible Commands](#extensible-commands)
34
35
  - [Real World Examples](#real-world-examples)
35
36
  - [Contributing / Support](#contributing--support)
36
37
 
@@ -203,6 +204,7 @@ command and subcommands (under the `commands` definition).
203
204
  `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.
204
205
  `version` | The string to display when using `--version`. *Applicable only in the main command*.
205
206
  `default` | Setting this to `true` on any command, will cause any unrecognized command line to be passed to this command. *Applicable only in subcommands*.
207
+ `extensible` | Specify that this command can be [externally extended](#extensible-commands).
206
208
  `examples` | Specify an array of examples to show when using `--help`. Each example can have multiple lines.
207
209
  `environment_variables` | Specify an array of [environment variables](#environment-variable-options) needed by your script.
208
210
  `commands` | Specify the array of [commands](#command-options). Each command will have its own args and flags. Note: if `commands` is provided, you cannot specify flags or args at the same level.
@@ -262,6 +264,82 @@ set.
262
264
  `required` | Specify if this variable is required.
263
265
 
264
266
 
267
+ ## Extensible Commands
268
+
269
+ You may configure your generated bash script to delegate any unknown command
270
+ to an external executable, by setting the `extensible` option to either `true`,
271
+ or to a different external command.
272
+
273
+ This is similar to how `git` works. When you execute `git whatever`, the `git`
274
+ command will look for a file named `git-whatever` in the path, and execute it.
275
+
276
+ Note that this option cannot be specified together with the `default` option,
277
+ since both specify a handler for unknown commands.
278
+
279
+ Bashly supports two operation modes.
280
+
281
+ ### Extension Mode (`extensible: true`)
282
+
283
+ By setting `extensible` to `true`, a specially named executable will be called
284
+ when an unknown command is called by the user.
285
+
286
+ Given this `bashly.yml` configuration:
287
+
288
+ ```yaml
289
+ name: myscript
290
+ help: Example
291
+ version: 0.1.0
292
+ extensible: true
293
+
294
+ commands:
295
+ - name: upload
296
+ help: Upload a file
297
+ ```
298
+
299
+ And this user command:
300
+
301
+ ```
302
+ $ myscript something
303
+
304
+ ```
305
+
306
+ The generated script will look for an executable named `myscript-something`
307
+ in the path. If found, it will be called.
308
+
309
+ See the [extensible example](examples/extensible).
310
+
311
+
312
+ ### Delegate Mode (`extensible: <executable name>`)
313
+
314
+ By setting `extensible` to any string, unknown command calls by the user will
315
+ be delegated to the executable with that name.
316
+
317
+ Given this `bashly.yml` configuration:
318
+
319
+ ```yaml
320
+ name: mygit
321
+ help: Example
322
+ version: 0.1.0
323
+ extensible: git
324
+
325
+ commands:
326
+ - name: push
327
+ help: Push to my repository
328
+ ```
329
+
330
+ And this user command:
331
+
332
+ ```
333
+ $ mygit status
334
+
335
+ ```
336
+
337
+ The generated script will execute `git status`.
338
+
339
+ See the [extensible-delegate example](examples/extensible-delegate).
340
+
341
+
342
+
265
343
  ## Real World Examples
266
344
 
267
345
  - [Rush][rush] - a Personal Package Manager
@@ -14,6 +14,7 @@ module Bashly
14
14
  description
15
15
  environment_variables
16
16
  examples
17
+ extensible
17
18
  flags
18
19
  group
19
20
  help
@@ -1,3 +1,3 @@
1
1
  module Bashly
2
- VERSION = "0.4.5"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -0,0 +1,45 @@
1
+ # :command.command_fallback
2
+ <%- if default_command -%>
3
+ "" )
4
+ <%= function_name %>_usage
5
+ exit 1
6
+ ;;
7
+
8
+ * )
9
+ action="<%= default_command.name %>"
10
+ <%= default_command.function_name %>_parse_requirements "$@"
11
+ shift $#
12
+ ;;
13
+ <%- elsif extensible.is_a? String -%>
14
+ "" )
15
+ <%= function_name %>_usage
16
+ exit 1
17
+ ;;
18
+
19
+ * )
20
+ if [[ -x "$(command -v "<%= extensible %>")" ]]; then
21
+ exec <%= extensible %> "$@"
22
+ else
23
+ <%= function_name %>_usage
24
+ exit 1
25
+ fi
26
+ <%- elsif extensible -%>
27
+ "" )
28
+ <%= function_name %>_usage
29
+ exit 1
30
+ ;;
31
+
32
+ * )
33
+ if [[ -x "$(command -v "<%= function_name %>-$action")" ]]; then
34
+ shift
35
+ exec "<%= function_name %>-$action" "$@"
36
+ else
37
+ <%= function_name %>_usage
38
+ exit 1
39
+ fi
40
+ <%- else -%>
41
+ * )
42
+ <%= function_name %>_usage
43
+ exit 1
44
+ ;;
45
+ <%- end -%>
@@ -15,25 +15,7 @@ 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 -%>
31
- * )
32
- <%= function_name %>_usage
33
- exit 1
34
- ;;
35
-
36
- <%- end -%>
18
+ <%= render :command_fallback %>
37
19
  esac
38
20
  <%- else -%>
39
21
  action="<%= action_name %>"
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.4.5
4
+ version: 0.5.0
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: 2021-06-24 00:00:00.000000000 Z
11
+ date: 2021-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colsole
@@ -92,6 +92,7 @@ files:
92
92
  - lib/bashly/templates/strings.yml
93
93
  - lib/bashly/version.rb
94
94
  - lib/bashly/views/argument/usage.erb
95
+ - lib/bashly/views/command/command_fallback.erb
95
96
  - lib/bashly/views/command/command_filter.erb
96
97
  - lib/bashly/views/command/command_functions.erb
97
98
  - lib/bashly/views/command/default_assignments.erb