Skip to content

Commit f60ef78

Browse files
committed
clean readme, docs moved to bashly.dannyb.co
1 parent a6b7794 commit f60ef78

File tree

2 files changed

+14
-369
lines changed

2 files changed

+14
-369
lines changed

README.md

Lines changed: 4 additions & 368 deletions
Original file line numberDiff line numberDiff line change
@@ -15,370 +15,9 @@ Create beautiful bash scripts from simple YAML configuration
1515

1616
</div>
1717

18+
## Documentation
1819

19-
## Table of Contents
20-
21-
- [Table of Contents](#table-of-contents)
22-
- [Installation](#installation)
23-
- [Prerequisites](#prerequisites)
24-
- [What is Bashly](#what-is-bashly)
25-
- [Usage](#usage)
26-
- [Using the input arguments in your code](#using-the-input-arguments-in-your-code)
27-
- [Examples](#examples)
28-
- [Configuration Reference](#configuration-reference)
29-
- [Command options](#command-options)
30-
- [Argument options](#argument-options)
31-
- [Flag options](#flag-options)
32-
- [Environment Variable options](#environment-variable-options)
33-
- [Extensible Scripts](#extensible-scripts)
34-
- [Bash Completions](#bash-completions)
35-
- [Real World Examples](#real-world-examples)
36-
- [Contributing / Support](#contributing--support)
37-
38-
---
39-
40-
41-
## Installation
42-
43-
```shell
44-
$ gem install bashly
45-
```
46-
47-
or with Docker:
48-
49-
```shell
50-
$ alias bashly='docker run --rm -it --volume "$PWD:/app" dannyben/bashly'
51-
```
52-
53-
## Prerequisites
54-
55-
The bash scripts generated by bashly require bash 4 or higher due to heavy
56-
use of associative arrays.
57-
58-
59-
## What is Bashly
60-
61-
Bashly is a command line application (written in Ruby) that lets you generate
62-
feature-rich bash command line tools.
63-
64-
The design intention is to let you focus on your specific code, without
65-
worrying about command line argument parsing, usage texts, error messages
66-
and other functions that are usually handled by a framework in any other
67-
programming language.
68-
69-
Bahsly is responsible for:
70-
71-
- Generating a **single, standalone bash script**.
72-
- Generating **usage texts** and help screens, showing your tool's arguments,
73-
flags and commands (works for subcommands also).
74-
- Parsing the user's command line and extracting:
75-
- Optional or required **positional arguments**.
76-
- Optional or required **option flags** (with or without flag arguments).
77-
- **Commands** (and subcommands).
78-
- Standard flags (like **--help** and **--version**).
79-
- Preventing your script from running unless the command line is valid.
80-
- Providing you with a place to input your code for each of the functions
81-
your tool performs, and merging it back to the final script.
82-
- Providing you with additional (optional) framework-style, standard
83-
library functions:
84-
- **Color output**.
85-
- **Config file management** (INI format).
86-
- **YAML parsing**.
87-
- **Bash completions**.
88-
- and more.
89-
90-
91-
## Usage
92-
93-
The `bashly.yml` file can be set up to generate two types of scripts:
94-
95-
1. Script with commands (for example, like `docker` or `git`).
96-
2. Script without commands (for example, like `ls`)
97-
98-
This is detected automatically by the contents of the configuration: If it
99-
contains a `commands` definition, it will generate a script with commands.
100-
101-
In an empty directory, create a sample configuration file by running
102-
103-
```shell
104-
$ bashly init
105-
# or, to generate a simpler configuration:
106-
$ bashly init --minimal
107-
```
108-
109-
This will create a sample `src/bashly.yml` file.
110-
You can edit this file to specify which arguments, flags and commands you
111-
need in your bash script.
112-
113-
Then, generate an initial bash script and function placeholder scripts by
114-
running
115-
116-
```shell
117-
$ bashly generate
118-
```
119-
120-
This will:
121-
122-
1. Create the bash executable script.
123-
2. Create files for you to edit in the `src` folder.
124-
125-
Finally, edit the files in the `src` folder. Each of your script's commands
126-
get their own file. Once you edit, run `bashly generate` again to merge the
127-
content from your functions back into the script.
128-
129-
### Using the input arguments in your code
130-
131-
In order to access the parsed arguments in any of your partial scripts, you
132-
may simply access the `$args` associative array.
133-
134-
For example:
135-
136-
1. Generate a minimal configuration with `bashly init --minimal`
137-
2. Generate the bash script with `bashly generate`
138-
3. Run the script with `./download hello --force`
139-
140-
You will notice that all the arguments of the associative array are printed
141-
on screen. This is done by the `inspect_args` function that was inserted into
142-
the generated partial script `src/root_command.sh`.
143-
144-
You can now access these variables by modifying `sec/root_command.sh` like
145-
this:
146-
147-
148-
```bash
149-
# src/root_command.sh
150-
source_url=${args[source]}
151-
force=${args[--force]}
152-
153-
if [[ $force ]]; then
154-
echo "downloading $source_url with --force"
155-
else
156-
echo "downloading $source_url"
157-
fi
158-
```
159-
160-
After editing the file, run `bashly generate` (or `bashly g` for short) and
161-
run:
162-
163-
```
164-
$ ./download a --force
165-
downloading a with --force
166-
```
167-
168-
169-
## Examples
170-
171-
The [examples folder](examples#readme) contains many detailed and documented
172-
example configuration files, with their output.
173-
174-
175-
## Configuration Reference
176-
177-
The `bashly.yml` configuration file consists of these types:
178-
179-
- [Command](#command-options) - defines the root command as well as any
180-
subcommand.
181-
- [Argument](#argument-options) - defines positional arguments.
182-
- [Flag](#flag-options) - defines option flags.
183-
- [Environment Variable](#environment-variable-options) - defines
184-
environment variables required (or desired) by your script.
185-
186-
### Command options
187-
188-
Unless otherwise specified, these definitions can be used for both the root
189-
command and subcommands (under the `commands` definition).
190-
191-
Option | Description
192-
-----------|-------------
193-
`name` | The name of the script or subcommand.
194-
`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*.
195-
`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.
196-
`version` | The string to display when using `--version`. *Applicable only in the main command*.
197-
`default` | Setting this to `true` on any command, will cause any unrecognized command line to be passed to this command. *Applicable only in subcommands*.
198-
`extensible` | Specify that this command can be [externally extended](#extensible-scripts). *Applicable only in the main command*.
199-
`examples` | Specify an array of examples to show when using `--help`. Each example can have multiple lines.
200-
`environment_variables` | Specify an array of [environment variables](#environment-variable-options) needed by your script.
201-
`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.
202-
`args` | Specify the array of [positional arguments](#argument-options) this script needs.
203-
`flags` | Specify the array of option [flags](#flag-options) this script needs.
204-
`completions` | Specify an array of additional completion suggestions when used in conjunction with `bashly add comp`. See [Bash Completions](#bash-completions).
205-
`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`.
206-
`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.
207-
`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.
208-
`footer` | Add a custom message that will be displayed at the end of the `--help` text.
209-
210-
### Argument options
211-
212-
The argument's value will be available to you as `${args[user]}` in your
213-
bash function.
214-
215-
Option | Description
216-
-----------|-------------
217-
`name` | The name of the argument.
218-
`help` | The message to display when using `--help`. Can have multiple lines.
219-
`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.
220-
`default` | The value to use in case it is not provided by the user. Implies that this argument is optional.
221-
`allowed` | Limit the allowed values by providing an array.
222-
223-
### Flag options
224-
225-
The flag's value will be available to you as `${args[--output]}` in your
226-
bash function (regardless of whether the user provided it with the long or
227-
short form).
228-
229-
Option | Description
230-
-----------|-------------
231-
`long` | The long form of the flag.
232-
`short` | The short form of the flag.
233-
`help` | The text to display when using `--help`. Can have multiple lines.
234-
`arg` | If the flag requires an argument, specify its name here.
235-
`required` | Specify if this flag is required.
236-
`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.
237-
`allowed` | For flags with an argument, you can limit the allowed values by providing an array.
238-
239-
#### Special handling for -v and -h
240-
241-
The `-v` and `-h` flags will be used as the short options for `--version` and
242-
`--help` respectively **only if you are not using them in any of your own
243-
flags**.
244-
245-
### Environment variable options
246-
247-
If an environment variable is defined as required (false by default), the
248-
execution of the script will be halted with a friendly error if it is not
249-
set.
250-
251-
Option | Description
252-
-----------|-------------
253-
`name` | The name of the variable (it will be automatically capitalized).
254-
`help` | The message to display when using --help. Can have multiple lines.
255-
`required` | Specify if this variable is required.
256-
257-
258-
## Extensible Scripts
259-
260-
You may configure your generated bash script to delegate any unknown command
261-
to an external executable, by setting the `extensible` option to either `true`,
262-
or to a different external command.
263-
264-
This is similar to how `git` works. When you execute `git whatever`, the `git`
265-
command will look for a file named `git-whatever` in the path, and execute it.
266-
267-
Note that this option cannot be specified together with the `default` option,
268-
since both specify a handler for unknown commands.
269-
270-
The `extensible` option supports two operation modes:
271-
272-
### Extension Mode (`extensible: true`)
273-
274-
By setting `extensible` to `true`, a specially named executable will be called
275-
when an unknown command is called by the user.
276-
277-
Given this `bashly.yml` configuration:
278-
279-
```yaml
280-
name: myscript
281-
help: Example
282-
version: 0.1.0
283-
extensible: true
284-
285-
commands:
286-
- name: upload
287-
help: Upload a file
288-
```
289-
290-
And this user command:
291-
292-
```
293-
$ myscript something
294-
295-
```
296-
297-
The generated script will look for an executable named `myscript-something`
298-
in the path. If found, it will be called.
299-
300-
See the [extensible example](examples/extensible).
301-
302-
303-
### Delegate Mode (`extensible: <executable name>`)
304-
305-
By setting `extensible` to any string, unknown command calls by the user will
306-
be delegated to the executable with that name.
307-
308-
Given this `bashly.yml` configuration:
309-
310-
```yaml
311-
name: mygit
312-
help: Example
313-
version: 0.1.0
314-
extensible: git
315-
316-
commands:
317-
- name: push
318-
help: Push to my repository
319-
```
320-
321-
And this user command:
322-
323-
```
324-
$ mygit status
325-
326-
```
327-
328-
The generated script will execute `git status`.
329-
330-
See the [extensible-delegate example](examples/extensible-delegate).
331-
332-
333-
## Bash Completions
334-
335-
Bashly comes with built-in bash completions generator, provided by the
336-
[completely][completely] gem.
337-
338-
By running any of the `bashly add comp` commands, you can add this
339-
functionality to your script in one of three ways:
340-
341-
- `bashly add comp function` - creates a function in your `./src/lib` directory
342-
that echoes a completion script. You can then call this function from any
343-
command (for example `yourcli completions`) and your users will be able to
344-
install the completions by running `eval "$(yourcli completions)"`.
345-
- `bashly add comp script` - creates a standalone completion script that can be
346-
sourced or copies to the system's bash completions directory.
347-
- `bashly add comp yaml` - creates the "raw data" YAML file. This is intended
348-
mainly for development purposes.
349-
350-
The bash completions generation is completely automatic, and you will have to
351-
rerun the `bashly add comp *` command whenever you change your `bashly.yml`
352-
file.
353-
354-
In addition to suggesting subcommands and flags, you can instruct bashly to
355-
also suggest files, directories, users, git branches and more. To do this,
356-
add another option in your `bashly.yml` on the command you wish to alter:
357-
358-
```yaml
359-
# bashly.yml
360-
commands:
361-
- name: upload
362-
help: Upload a file
363-
completions:
364-
- <directory>
365-
- <user>
366-
- $(git branch 2> /dev/null)
367-
368-
```
369-
370-
- Anything between `<...>` will be added using the `compgen -A action` flag.
371-
- Anything else, will be appended to the `compgen -W` flag.
372-
373-
For more information about these custom completions, see the documentation for
374-
the [completely][completely] gem.
375-
376-
377-
## Real World Examples
378-
379-
- [Rush][rush] - a Personal Package Manager
380-
- [Alf][alf] - a generator for bash aliases and sub-aliases
381-
- [git-changelog][git-changelog] - a change log generator
20+
Visit the [Bashly Documentation][docs] site.
38221

38322

38423
## Contributing / Support
@@ -389,8 +28,5 @@ to contribute, feel free to [open an issue][issues].
38928

39029

39130
[issues]: https://github.com/DannyBen/bashly/issues
392-
[rush]: https://github.com/DannyBen/rush-cli
393-
[alf]: https://github.com/DannyBen/alf
394-
[git-changelog]: https://github.com/DannyBen/git-changelog
395-
[completely]: https://github.com/DannyBen/completely
396-
[compgen]: https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html
31+
[docs]: https://bashly.dannyb.co/
32+

0 commit comments

Comments
 (0)