bashly 0.5.0 → 0.6.2
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/README.md +4 -332
- data/lib/bashly/commands/add.rb +82 -0
- data/lib/bashly/concerns/completions.rb +47 -0
- data/lib/bashly/concerns/renderable.rb +1 -4
- data/lib/bashly/models/base.rb +2 -0
- data/lib/bashly/models/command.rb +7 -0
- data/lib/bashly/version.rb +1 -1
- data/lib/bashly/views/command/environment_variables_filter.erb +5 -0
- data/lib/bashly/views/command/footer.erb +2 -0
- data/lib/bashly/views/command/usage.erb +1 -0
- data/lib/bashly/views/environment_variable/usage.erb +3 -0
- metadata +25 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd9fb393dfda0c4529dc984e9ee12660e310c014a41e4fac031c3d7b33420bad
|
4
|
+
data.tar.gz: 3496cc3d2d8715332fce5d163b4ebe0d6ea9eb5441378c75dae3a070fbf8db18
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 430ac01ae504b3f54e6c812d13729806c494cf5912833bf2b5360645040c368b1f514c538c66d701672f12ae6c1ba77849691c1666f4f6d11a43b44bc79d0f17
|
7
|
+
data.tar.gz: 41784e22ff19801e5e6be60be31652ea751f30a21c027d40ba59d9f29a08ed0e5074fa1c87518bb54fd0d41bc94ad475f7f91764bbf3cde85f09868e4ccda46f
|
data/README.md
CHANGED
@@ -15,336 +15,9 @@ Create beautiful bash scripts from simple YAML configuration
|
|
15
15
|
|
16
16
|
</div>
|
17
17
|
|
18
|
-
##
|
18
|
+
## Documentation
|
19
19
|
|
20
|
-
|
21
|
-
- [Installation](#installation)
|
22
|
-
- [Prerequisites](#prerequisites)
|
23
|
-
- [What is Bashly](#what-is-bashly)
|
24
|
-
- [Usage](#usage)
|
25
|
-
- [Using the input arguments in your code](#using-the-input-arguments-in-your-code)
|
26
|
-
- [Examples](#examples)
|
27
|
-
- [Sample configuration for a script without commands](#sample-configuration-for-a-script-without-commands)
|
28
|
-
- [Sample configuration for a script with commands](#sample-configuration-for-a-script-with-commands)
|
29
|
-
- [Configuration Reference](#configuration-reference)
|
30
|
-
- [Command options](#command-options)
|
31
|
-
- [Argument options](#argument-options)
|
32
|
-
- [Flag options](#flag-options)
|
33
|
-
- [Environment Variable options](#environment-variable-options)
|
34
|
-
- [Extensible Commands](#extensible-commands)
|
35
|
-
- [Real World Examples](#real-world-examples)
|
36
|
-
- [Contributing / Support](#contributing--support)
|
37
|
-
|
38
|
-
---
|
39
|
-
|
40
|
-
## Installation
|
41
|
-
|
42
|
-
```shell
|
43
|
-
$ gem install bashly
|
44
|
-
```
|
45
|
-
|
46
|
-
or with Docker:
|
47
|
-
|
48
|
-
```shell
|
49
|
-
$ alias bashly='docker run --rm -it --volume "$PWD:/app" dannyben/bashly'
|
50
|
-
```
|
51
|
-
|
52
|
-
## Prerequisites
|
53
|
-
|
54
|
-
The bash scripts generated by bashly require bash 4 or higher due to heavy
|
55
|
-
use of associative arrays.
|
56
|
-
|
57
|
-
|
58
|
-
## What is Bashly
|
59
|
-
|
60
|
-
Bashly is a command line application (written in Ruby) that lets you generate
|
61
|
-
feature-rich bash command line tools.
|
62
|
-
|
63
|
-
The design intention is to let you focus on your specific code, without
|
64
|
-
worrying about command line argument parsing, usage texts, error messages
|
65
|
-
and other functions that are usually handled by a framework in any other
|
66
|
-
programming language.
|
67
|
-
|
68
|
-
Bahsly is responsible for:
|
69
|
-
|
70
|
-
- Generating a **single, standalone bash script**.
|
71
|
-
- Generating **usage texts** and help screens, showing your tool's arguments,
|
72
|
-
flags and commands (works for subcommands also).
|
73
|
-
- Parsing the user's command line and extracting:
|
74
|
-
- Optional or required **positional arguments**.
|
75
|
-
- Optional or required **option flags** (with or without flag arguments).
|
76
|
-
- **Commands** (and subcommands).
|
77
|
-
- Standard flags (like **--help** and **--version**).
|
78
|
-
- Providing you with a place to input your code for each of the functions
|
79
|
-
your tool performs, and merging it back to the final script.
|
80
|
-
- Providing you with additional (optional) framework-style, standard
|
81
|
-
library functions:
|
82
|
-
- **Color output**.
|
83
|
-
- **Config file management** (INI format).
|
84
|
-
- **YAML parsing**.
|
85
|
-
- and more.
|
86
|
-
|
87
|
-
## Usage
|
88
|
-
|
89
|
-
In an empty directory, create a sample configuration file by running
|
90
|
-
|
91
|
-
```shell
|
92
|
-
$ bashly init
|
93
|
-
# or, to generate a simpler configuration:
|
94
|
-
$ bashly init --minimal
|
95
|
-
```
|
96
|
-
|
97
|
-
This will create a sample `src/bashly.yml` file.
|
98
|
-
You can edit this file to specify which arguments, flags and commands you
|
99
|
-
need in your bash script.
|
100
|
-
|
101
|
-
Then, generate an initial bash script and function placeholder scripts by
|
102
|
-
running
|
103
|
-
|
104
|
-
```shell
|
105
|
-
$ bashly generate
|
106
|
-
```
|
107
|
-
|
108
|
-
This will:
|
109
|
-
|
110
|
-
1. Create the bash executable script.
|
111
|
-
2. Create files for you to edit in the `src` folder.
|
112
|
-
|
113
|
-
Finally, edit the files in the `src` folder. Each of your script's commands
|
114
|
-
get their own file. Once you edit, run `bashly generate` again to merge the
|
115
|
-
content from your functions back into the script.
|
116
|
-
|
117
|
-
### Using the input arguments in your code
|
118
|
-
|
119
|
-
In order to access the parsed arguments in any of your partial scripts, you
|
120
|
-
may simply access the `$args` associative array.
|
121
|
-
|
122
|
-
For example:
|
123
|
-
|
124
|
-
1. Generate a minimal configuration with `bashly init --minimal`
|
125
|
-
2. Generate the bash script with `bashly generate`
|
126
|
-
3. Run the script with `./download hello --force`
|
127
|
-
|
128
|
-
You will notice that all the arguments of the associative array are printed
|
129
|
-
on screen. This is done by the `inspect_args` function that was inserted into
|
130
|
-
the generated partial script `src/root_command.sh`.
|
131
|
-
|
132
|
-
You can now access these variables by modifying `sec/root_command.sh` like
|
133
|
-
this:
|
134
|
-
|
135
|
-
|
136
|
-
```bash
|
137
|
-
# src/root_command.sh
|
138
|
-
source_url=${args[source]}
|
139
|
-
force=${args[--force]}
|
140
|
-
|
141
|
-
if [[ $force ]]; then
|
142
|
-
echo "downloading $source_url with --force"
|
143
|
-
else
|
144
|
-
echo "downloading $source_url"
|
145
|
-
fi
|
146
|
-
```
|
147
|
-
|
148
|
-
After editing the file, run `bashly generate` (or `bashly g` for short) and
|
149
|
-
run:
|
150
|
-
|
151
|
-
```
|
152
|
-
$ ./download a --force
|
153
|
-
downloading a with --force
|
154
|
-
```
|
155
|
-
|
156
|
-
## Examples
|
157
|
-
|
158
|
-
The `bashly.yml` file can be set up to generate two types of scripts:
|
159
|
-
|
160
|
-
1. Script with commands (for example, like `docker` or `git`).
|
161
|
-
2. Script without commands (for example, like `ls`)
|
162
|
-
|
163
|
-
This is detected automatically by the contents of the configuration: If it
|
164
|
-
contains a `commands` definition, it will generate a script with commands.
|
165
|
-
|
166
|
-
|
167
|
-
### Sample configuration for a script without commands
|
168
|
-
|
169
|
-
- Generate this script by running `bashly generate --minimal`
|
170
|
-
- [See the initial sample bashly.yml file](examples/minimal/src/bashly.yml)
|
171
|
-
- [See the generated bash script](examples/minimal/download)
|
172
|
-
|
173
|
-
### Sample configuration for a script with commands
|
174
|
-
|
175
|
-
- Generate this script by running `bashly generate`
|
176
|
-
- [See the initial sample bashly.yml file](examples/commands/src/bashly.yml)
|
177
|
-
- [See the generated bash script](examples/commands/cli)
|
178
|
-
|
179
|
-
|
180
|
-
See the [examples](examples) folder for more examples.
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
## Configuration Reference
|
185
|
-
|
186
|
-
The `bashly.yml` configuration file consists of these types:
|
187
|
-
|
188
|
-
- [Command](#command-options) - defines the root command as well as any
|
189
|
-
subcommand.
|
190
|
-
- [Argument](#argument-options) - defines positional arguments.
|
191
|
-
- [Flag](#flag-options) - defines option flags.
|
192
|
-
- [Environment Variable](#environment-variable-options) - defines
|
193
|
-
environment variables required (or desired) by your script.
|
194
|
-
|
195
|
-
### Command options
|
196
|
-
|
197
|
-
Unless otherwise specified, these definitions can be used for both the root
|
198
|
-
command and subcommands (under the `commands` definition).
|
199
|
-
|
200
|
-
Option | Description
|
201
|
-
-----------|-------------
|
202
|
-
`name` | The name of the script or subcommand.
|
203
|
-
`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*.
|
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.
|
205
|
-
`version` | The string to display when using `--version`. *Applicable only in the main command*.
|
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).
|
208
|
-
`examples` | Specify an array of examples to show when using `--help`. Each example can have multiple lines.
|
209
|
-
`environment_variables` | Specify an array of [environment variables](#environment-variable-options) needed by your script.
|
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.
|
211
|
-
`args` | Specify the array of [positional arguments](#argument-options) this script needs.
|
212
|
-
`flags` | Specify the array of option [flags](#flag-options) this script needs.
|
213
|
-
`catch_all` | Specify that this command should allow for additional arbitrary arguments or flags. It can be set in one of three ways:<br>- Set to `true` to just enable it.<br>- Set to a string, to use this string in the usage help text.<br>- Set to a hash containing `label` and `help` keys, to show a detailed help for it when running with `--help`.
|
214
|
-
`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.
|
215
|
-
`group` | In case you have many commands, use this option to specify a caption to display before this command. This option is purely for display purposes, and needs to be specified only for the first command in each group.
|
216
|
-
|
217
|
-
### Argument options
|
218
|
-
|
219
|
-
The argument's value will be available to you as `${args[user]}` in your
|
220
|
-
bash function.
|
221
|
-
|
222
|
-
Option | Description
|
223
|
-
-----------|-------------
|
224
|
-
`name` | The name of the argument.
|
225
|
-
`help` | The message to display when using `--help`. Can have multiple lines.
|
226
|
-
`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.
|
227
|
-
`default` | The value to use in case it is not provided by the user. Implies that this argument is optional.
|
228
|
-
`allowed` | Limit the allowed values by providing an array.
|
229
|
-
|
230
|
-
### Flag options
|
231
|
-
|
232
|
-
The flag's value will be available to you as `${args[--output]}` in your
|
233
|
-
bash function (regardless of whether the user provided it with the long or
|
234
|
-
short form).
|
235
|
-
|
236
|
-
Option | Description
|
237
|
-
-----------|-------------
|
238
|
-
`long` | The long form of the flag.
|
239
|
-
`short` | The short form of the flag.
|
240
|
-
`help` | The text to display when using `--help`. Can have multiple lines.
|
241
|
-
`arg` | If the flag requires an argument, specify its name here.
|
242
|
-
`required` | Specify if this flag is required.
|
243
|
-
`default` | The value to use in case it is not provided by the user. Implies that this flag is optional, and only makes sense when the flag has an argument.
|
244
|
-
`allowed` | For flags with an argument, you can limit the allowed values by providing an array.
|
245
|
-
|
246
|
-
#### Special handling for -v and -h
|
247
|
-
|
248
|
-
The `-v` and `-h` flags will be used as the short options for `--version` and
|
249
|
-
`--help` respectively **only if you are not using them in any of your own
|
250
|
-
flags**.
|
251
|
-
|
252
|
-
### Environment Variable options
|
253
|
-
|
254
|
-
The below configuration generates this environment variable usage text:
|
255
|
-
|
256
|
-
If an environment variable is defined as required (false by default), the
|
257
|
-
execution of the script will be halted with a friendly error if it is not
|
258
|
-
set.
|
259
|
-
|
260
|
-
Option | Description
|
261
|
-
-----------|-------------
|
262
|
-
`name` | The name of the variable (it will be automatically capitalized).
|
263
|
-
`help` | The message to display when using --help. Can have multiple lines.
|
264
|
-
`required` | Specify if this variable is required.
|
265
|
-
|
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
|
-
|
343
|
-
## Real World Examples
|
344
|
-
|
345
|
-
- [Rush][rush] - a Personal Package Manager
|
346
|
-
- [Alf][alf] - a generator for bash aliases and sub-aliases
|
347
|
-
- [git-changelog][git-changelog] - a change log generator
|
20
|
+
Visit the [Bashly Documentation][docs] site.
|
348
21
|
|
349
22
|
|
350
23
|
## Contributing / Support
|
@@ -355,6 +28,5 @@ to contribute, feel free to [open an issue][issues].
|
|
355
28
|
|
356
29
|
|
357
30
|
[issues]: https://github.com/DannyBen/bashly/issues
|
358
|
-
[
|
359
|
-
|
360
|
-
[git-changelog]: https://github.com/DannyBen/git-changelog
|
31
|
+
[docs]: https://bashly.dannyb.co/
|
32
|
+
|
data/lib/bashly/commands/add.rb
CHANGED
@@ -8,15 +8,24 @@ module Bashly
|
|
8
8
|
usage "bashly add config [--force]"
|
9
9
|
usage "bashly add colors [--force]"
|
10
10
|
usage "bashly add yaml [--force]"
|
11
|
+
usage "bashly add comp FORMAT [OUTPUT]"
|
11
12
|
usage "bashly add (-h|--help)"
|
12
13
|
|
13
14
|
option "-f --force", "Overwrite existing files"
|
14
15
|
|
16
|
+
param "FORMAT", "Output format, can be one of:\n function : generate a function file to be included in your script.\n script : generate a standalone bash completions script\n yaml : generate a yaml compatible with 'completely'"
|
17
|
+
param "OUTPUT", "For the 'comp function' command: Name of the generated function.\nFor the 'comp script' or 'comp yaml' commands: path to output file.\nIn all cases, this is optional and will have sensible defaults."
|
18
|
+
|
15
19
|
command "strings", "Copy an additional configuration file to your project, allowing you to customize all the tips and error strings."
|
16
20
|
command "lib", "Create the additional lib directory for additional user scripts. All *.sh scripts in this folder will be included in the final bash script."
|
17
21
|
command "config", "Add standard functions for handling INI files to the lib directory."
|
18
22
|
command "colors", "Add standard functions for printing colorful and formatted text to the lib directory."
|
19
23
|
command "yaml", "Add standard functions for reading YAML files to the lib directory."
|
24
|
+
command "comp", "Generate a bash completions script or function."
|
25
|
+
|
26
|
+
example "bashly add strings --force"
|
27
|
+
example "bashly add comp function"
|
28
|
+
example "bashly add comp script completions.bash"
|
20
29
|
|
21
30
|
environment "BASHLY_SOURCE_DIR", "The path containing the bashly configuration and source files [default: src]"
|
22
31
|
|
@@ -40,7 +49,25 @@ module Bashly
|
|
40
49
|
safe_copy_lib "yaml.sh"
|
41
50
|
end
|
42
51
|
|
52
|
+
def comp_command
|
53
|
+
format = args['FORMAT']
|
54
|
+
output = args['OUTPUT']
|
55
|
+
|
56
|
+
case format
|
57
|
+
when "function"
|
58
|
+
save_comp_function output
|
59
|
+
when "yaml"
|
60
|
+
save_comp_yaml output
|
61
|
+
when "script"
|
62
|
+
save_comp_script output
|
63
|
+
else
|
64
|
+
raise Error, "Unrecognized format: #{format}"
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
43
69
|
private
|
70
|
+
|
44
71
|
def safe_copy_lib(libfile)
|
45
72
|
safe_copy asset("templates/lib/#{libfile}"), "#{Settings.source_dir}/lib/#{libfile}"
|
46
73
|
end
|
@@ -63,6 +90,61 @@ module Bashly
|
|
63
90
|
FileUtils.mkdir_p target_dir unless Dir.exist? target_dir
|
64
91
|
FileUtils.cp source, target
|
65
92
|
end
|
93
|
+
|
94
|
+
def config
|
95
|
+
@config ||= Config.new "#{Settings.source_dir}/bashly.yml"
|
96
|
+
end
|
97
|
+
|
98
|
+
def command
|
99
|
+
@command ||= Models::Command.new config
|
100
|
+
end
|
101
|
+
|
102
|
+
def completions
|
103
|
+
@completions ||= command.completion_data
|
104
|
+
end
|
105
|
+
|
106
|
+
def completions_script
|
107
|
+
@completions_script ||= command.completion_script
|
108
|
+
end
|
109
|
+
|
110
|
+
def completions_function
|
111
|
+
@completions_function ||= command.completion_function
|
112
|
+
end
|
113
|
+
|
114
|
+
def save_comp_yaml(filename = nil)
|
115
|
+
filename ||= "#{Settings.target_dir}/completions.yml"
|
116
|
+
File.write filename, completions.to_yaml
|
117
|
+
say "created !txtgrn!#{filename}"
|
118
|
+
say ""
|
119
|
+
say "This file can be converted to a completions script using the !txtgrn!completely!txtrst! gem."
|
120
|
+
end
|
121
|
+
|
122
|
+
def save_comp_script(filename = nil)
|
123
|
+
filename ||= "#{Settings.target_dir}/completions.bash"
|
124
|
+
File.write filename, completions_script
|
125
|
+
say "created !txtgrn!#{filename}"
|
126
|
+
say ""
|
127
|
+
say "In order to enable completions, run:"
|
128
|
+
say ""
|
129
|
+
say " !txtpur!$ source #{filename}"
|
130
|
+
end
|
131
|
+
|
132
|
+
def save_comp_function(name = nil)
|
133
|
+
name ||= "send_completions"
|
134
|
+
target_dir = "#{Settings.source_dir}/lib"
|
135
|
+
filename = "#{target_dir}/#{name}.sh"
|
136
|
+
|
137
|
+
FileUtils.mkdir_p target_dir unless Dir.exist? target_dir
|
138
|
+
File.write filename, completions_function
|
139
|
+
|
140
|
+
say "created !txtgrn!#{filename}"
|
141
|
+
say ""
|
142
|
+
say "In order to use it in your script, create a command or a flag (for example: !txtgrn!#{command.name} completions!txtrst! or !txtgrn!#{command.name} --completions!txtrst!) that calls the !txtgrn!#{name}!txtrst! function."
|
143
|
+
say "Your users can then run something like this to enable completions:"
|
144
|
+
say ""
|
145
|
+
say " !txtpur!$ eval \"$(#{command.name} completions)\""
|
146
|
+
end
|
147
|
+
|
66
148
|
end
|
67
149
|
end
|
68
150
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'completely'
|
2
|
+
|
3
|
+
module Bashly
|
4
|
+
# This is a `Command` concern responsible for providing bash completion data
|
5
|
+
module Completions
|
6
|
+
def completion_data(with_version: true)
|
7
|
+
result = { full_name => completion_words(with_version: with_version) }
|
8
|
+
|
9
|
+
commands.each do |command|
|
10
|
+
result.merge! command.completion_data(with_version: false)
|
11
|
+
end
|
12
|
+
|
13
|
+
result
|
14
|
+
end
|
15
|
+
|
16
|
+
def completion_script
|
17
|
+
completion_generator.script
|
18
|
+
end
|
19
|
+
|
20
|
+
def completion_function(name = nil)
|
21
|
+
completion_generator.wrapper_function(name)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def completion_generator
|
27
|
+
Completely::Completions.new(completion_data)
|
28
|
+
end
|
29
|
+
|
30
|
+
def completion_flag_names
|
31
|
+
flags.map(&:name) + flags.map(&:short)
|
32
|
+
end
|
33
|
+
|
34
|
+
def completion_words(with_version: false)
|
35
|
+
trivial_flags = %w[--help -h]
|
36
|
+
trivial_flags += %w[--version -v] if with_version
|
37
|
+
all = (
|
38
|
+
command_names + trivial_flags +
|
39
|
+
completion_flag_names
|
40
|
+
)
|
41
|
+
|
42
|
+
all += completions if completions
|
43
|
+
all.compact.uniq.sort
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
@@ -4,10 +4,7 @@ module Bashly
|
|
4
4
|
module Renderable
|
5
5
|
def render(view)
|
6
6
|
template = File.read view_path(view)
|
7
|
-
|
8
|
-
# So for now, we keep the old deprecated syntax
|
9
|
-
# ERB.new(template, trim_mode: '%-').result(binding)
|
10
|
-
ERB.new(template, nil, '%-').result(binding)
|
7
|
+
ERB.new(template, trim_mode: '%-').result(binding)
|
11
8
|
end
|
12
9
|
|
13
10
|
def strings
|
data/lib/bashly/models/base.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module Bashly
|
2
2
|
module Models
|
3
3
|
class Command < Base
|
4
|
+
include Completions
|
5
|
+
|
4
6
|
# Returns the name to be used as an action.
|
5
7
|
# - If it is the root command, the action is "root"
|
6
8
|
# - Else, it is all the parents, except the first tone (root) joined
|
@@ -90,6 +92,11 @@ module Bashly
|
|
90
92
|
commands.find { |c| c.default }
|
91
93
|
end
|
92
94
|
|
95
|
+
# Returns an array of all the default Environment Variables
|
96
|
+
def default_environment_variables
|
97
|
+
environment_variables.select &:default
|
98
|
+
end
|
99
|
+
|
93
100
|
# Returns an array of all the default Flags
|
94
101
|
def default_flags
|
95
102
|
flags.select &:default
|
data/lib/bashly/version.rb
CHANGED
@@ -1,4 +1,9 @@
|
|
1
1
|
# :command.environment_variables_filter
|
2
|
+
<%- if default_environment_variables.any? -%>
|
3
|
+
<%- default_environment_variables.each do |env_var| -%>
|
4
|
+
export <%= env_var.name.upcase %>="${<%= env_var.name.upcase %>:-<%= env_var.default %>}"
|
5
|
+
<%- end -%>
|
6
|
+
<%- end -%>
|
2
7
|
<%- if required_environment_variables.any? -%>
|
3
8
|
<%- required_environment_variables.each do |env_var| -%>
|
4
9
|
if [[ -z "$<%= env_var.name.upcase %>" ]]; then
|
@@ -40,6 +40,7 @@
|
|
40
40
|
<%= render(:usage_args).indent 4 if args.any? or catch_all_help %>
|
41
41
|
<%= render(:usage_environment_variables).indent 4 if environment_variables.any? %>
|
42
42
|
<%= render(:usage_examples).indent 4 if examples %>
|
43
|
+
<%= render(:footer).indent 4 if footer %>
|
43
44
|
|
44
45
|
fi
|
45
46
|
}
|
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
|
+
version: 0.6.2
|
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-
|
11
|
+
date: 2021-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colsole
|
@@ -24,6 +24,26 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: completely
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.1'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 0.1.2
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0.1'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.1.2
|
27
47
|
- !ruby/object:Gem::Dependency
|
28
48
|
name: mister_bin
|
29
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -69,6 +89,7 @@ files:
|
|
69
89
|
- lib/bashly/commands/init.rb
|
70
90
|
- lib/bashly/commands/preview.rb
|
71
91
|
- lib/bashly/concerns/asset_helper.rb
|
92
|
+
- lib/bashly/concerns/completions.rb
|
72
93
|
- lib/bashly/concerns/renderable.rb
|
73
94
|
- lib/bashly/config.rb
|
74
95
|
- lib/bashly/exceptions.rb
|
@@ -102,6 +123,7 @@ files:
|
|
102
123
|
- lib/bashly/views/command/dependencies_filter.erb
|
103
124
|
- lib/bashly/views/command/environment_variables_filter.erb
|
104
125
|
- lib/bashly/views/command/fixed_flags_filter.erb
|
126
|
+
- lib/bashly/views/command/footer.erb
|
105
127
|
- lib/bashly/views/command/function.erb
|
106
128
|
- lib/bashly/views/command/initialize.erb
|
107
129
|
- lib/bashly/views/command/inspect_args.erb
|
@@ -140,7 +162,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
140
162
|
requirements:
|
141
163
|
- - ">="
|
142
164
|
- !ruby/object:Gem::Version
|
143
|
-
version: 2.
|
165
|
+
version: 2.7.0
|
144
166
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
167
|
requirements:
|
146
168
|
- - ">="
|