Skip to content

Commit 13da8fd

Browse files
committed
updated readme to clarify #57
1 parent 9385e1e commit 13da8fd

File tree

1 file changed

+66
-18
lines changed

1 file changed

+66
-18
lines changed

README.md

Lines changed: 66 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<div align='center'>
22
<img src='logo.svg' width=280>
33

4-
Bashly - Bash CLI Framework and Generator
5-
==================================================
4+
# Bashly - Bash CLI Framework and Generator
65

76
Create beautiful bash scripts from simple YAML configuration
87

@@ -16,10 +15,28 @@ Create beautiful bash scripts from simple YAML configuration
1615

1716
</div>
1817

18+
## Table of Contents
19+
20+
- [Table of Contents](#table-of-contents)
21+
- [Installation](#installation)
22+
- [Prerequisites](#prerequisites)
23+
- [What is Bashly](#what-is-bashly)
24+
- [Usage](#usage)
25+
- [Using the input arguemnts in your code](#using-the-input-arguemnts-in-your-code)
26+
- [Examples](#examples)
27+
- [Sample configuraiton for a script without commands](#sample-configuraiton-for-a-script-without-commands)
28+
- [Sample configuraiton for a script with commands](#sample-configuraiton-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+
- [Real World Examples](#real-world-examples)
35+
- [Contributing / Support](#contributing--support)
36+
1937
---
2038

21-
Installation
22-
--------------------------------------------------
39+
## Installation
2340

2441
```shell
2542
$ gem install bashly
@@ -31,15 +48,13 @@ or with Docker:
3148
$ alias bashly='docker run --rm -it --volume "$PWD:/app" dannyben/bashly'
3249
```
3350

34-
Prerequisites
35-
--------------------------------------------------
51+
## Prerequisites
3652

3753
The bash scripts generated by bashly require bash 4 or higher due to heavy
3854
use of associative arrays.
3955

4056

41-
What is Bashly
42-
--------------------------------------------------
57+
## What is Bashly
4358

4459
Bashly is a command line application (written in Ruby) that lets you generate
4560
feature-rich bash command line tools.
@@ -68,8 +83,7 @@ Bahsly is responsible for:
6883
- **YAML parsing**.
6984
- and more.
7085

71-
Usage
72-
--------------------------------------------------
86+
## Usage
7387

7488
In an empty directory, create a sample configuration file by running
7589

@@ -99,9 +113,46 @@ Finally, edit the files in the `src` folder. Each of your script's commands
99113
get their own file. Once you edit, run `bashly generate` again to merge the
100114
content from your functions back into the script.
101115

116+
### Using the input arguemnts in your code
117+
118+
In order to access the parsed arguments in any of your partial scripts, you
119+
may simply access the `$args` associative array.
120+
121+
For example:
122+
123+
1. Generate a minimal configuration with `bashly init --minimal`
124+
2. Generate the bash script with `bashly generate`
125+
3. Run the script with `./download hello --force`
126+
127+
You will notice that all the arguments of the associative array are printed
128+
on screen. This is done by the `inspect_args` function that was inserted into
129+
the generated partial script `src/root_command.sh`.
130+
131+
You can now access these variables by modifying `sec/root_command.sh` like
132+
this:
133+
134+
135+
```bash
136+
# src/root_command.sh
137+
source_url=${args[source]}
138+
force=${args[--force]}
139+
140+
if [[ $force ]]; then
141+
echo "downloading $source_url with --force"
142+
else
143+
echo "downloading $source_url"
144+
fi
145+
```
146+
147+
After editing the file, run `bashly generate` (or `bashly g` for short) and
148+
run:
149+
150+
```
151+
$ ./download a --force
152+
downloading a with --force
153+
```
102154

103-
Examples
104-
--------------------------------------------------
155+
## Examples
105156

106157
The `bashly.yml` file can be set up to generate two types of scripts:
107158

@@ -129,8 +180,7 @@ See the [examples](examples) folder for more examples.
129180

130181

131182

132-
Configuration Reference
133-
--------------------------------------------------
183+
## Configuration Reference
134184

135185
The `bashly.yml` configuration file consists of these types:
136186

@@ -210,16 +260,14 @@ set.
210260
`required` | Specify if this variable is required.
211261

212262

213-
Real World Examples
214-
--------------------------------------------------
263+
## Real World Examples
215264

216265
- [Rush][rush] - a Personal Package Manager
217266
- [Alf][alf] - a generator for bash aliases and sub-aliases
218267
- [git-changelog][git-changelog] - a change log generator
219268

220269

221-
Contributing / Support
222-
--------------------------------------------------
270+
## Contributing / Support
223271

224272
If you experience any issue, have a question or a suggestion, or if you wish
225273
to contribute, feel free to [open an issue][issues].

0 commit comments

Comments
 (0)