Skip to content

Commit 51f7ca1

Browse files
committed
add command filename spec and example
1 parent a5065c3 commit 51f7ca1

File tree

12 files changed

+208
-0
lines changed

12 files changed

+208
-0
lines changed

examples/command-filenames/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cli

examples/command-filenames/README.md

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# Command Groups Example
2+
3+
Demonstrates how to visually group commands under their own caption. This is
4+
useful for scripts that contain many commands that provide different sets of
5+
functionality.
6+
7+
This example was generated with:
8+
9+
```bash
10+
$ bashly init
11+
# ... now edit src/bashly.yml to match the example ...
12+
$ bashly generate
13+
```
14+
15+
-----
16+
17+
## `bashly.yml`
18+
19+
```yaml
20+
name: ftp
21+
help: Sample application with command grouping
22+
version: 0.1.0
23+
24+
commands:
25+
- name: download
26+
help: Download a file
27+
28+
# By specifying a group, the `download` comnmand (and all subsequent
29+
# commands until the next `group`) will be printed under this `File`
30+
# caption.
31+
group: File
32+
33+
args:
34+
- name: file
35+
required: true
36+
help: File to download
37+
38+
- name: upload
39+
help: Upload a file
40+
41+
args:
42+
- name: file
43+
required: true
44+
help: File to upload
45+
46+
- name: login
47+
help: Write login credentials to the config file
48+
49+
# The `login` command (and all subsequent commands) will be printed under
50+
# the `Login` caption.
51+
group: Login
52+
53+
- name: logout
54+
help: Delete login credentials to the config file
55+
```
56+
57+
58+
59+
## Generated script output
60+
61+
### `$ ./ftp`
62+
63+
```shell
64+
ftp - Sample application with command grouping
65+
66+
Usage:
67+
ftp [command]
68+
ftp [command] --help | -h
69+
ftp --version | -v
70+
71+
File Commands:
72+
download Download a file
73+
upload Upload a file
74+
75+
Login Commands:
76+
login Write login credentials to the config file
77+
logout Delete login credentials to the config file
78+
79+
80+
81+
```
82+
83+
### `$ ./ftp -h`
84+
85+
```shell
86+
ftp - Sample application with command grouping
87+
88+
Usage:
89+
ftp [command]
90+
ftp [command] --help | -h
91+
ftp --version | -v
92+
93+
File Commands:
94+
download Download a file
95+
upload Upload a file
96+
97+
Login Commands:
98+
login Write login credentials to the config file
99+
logout Delete login credentials to the config file
100+
101+
Options:
102+
--help, -h
103+
Show this help
104+
105+
--version, -v
106+
Show version number
107+
108+
109+
110+
```
111+
112+
### `$ ./ftp login`
113+
114+
```shell
115+
# this file is located in 'src/login_command.sh'
116+
# code for 'ftp login' goes here
117+
# you can edit it freely and regenerate (it will not be overwritten)
118+
args: none
119+
120+
121+
```
122+
123+
124+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: cli
2+
help: Demonstrate custom command filenames
3+
version: 0.1.0
4+
5+
commands:
6+
- name: dir
7+
short: d
8+
help: Directory commands
9+
10+
commands:
11+
- name: list
12+
help: Show files in the directory
13+
14+
# Define a custom filename for this command source.
15+
# This is relative to the `src` directory, and sub-directories will be
16+
# created as needed.
17+
filename: dir_commands/list.sh
18+
19+
- name: remove
20+
help: Remove directory
21+
filename: dir_commands/remove.sh
22+
23+
- name: file
24+
short: f
25+
help: File commands
26+
27+
commands:
28+
- name: show
29+
help: Show file contents
30+
filename: file_commands/show.sh
31+
32+
- name: edit
33+
help: Edit the file
34+
filename: file_commands/edit.sh
35+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
echo "# this file is located in 'src/dir_commands/list.sh'"
2+
echo "# code for 'cli dir list' goes here"
3+
echo "# you can edit it freely and regenerate (it will not be overwritten)"
4+
inspect_args
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
echo "# this file is located in 'src/dir_commands/remove.sh'"
2+
echo "# code for 'cli dir remove' goes here"
3+
echo "# you can edit it freely and regenerate (it will not be overwritten)"
4+
inspect_args
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
echo "# this file is located in 'src/file_commands/edit.sh'"
2+
echo "# code for 'cli file edit' goes here"
3+
echo "# you can edit it freely and regenerate (it will not be overwritten)"
4+
inspect_args
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
echo "# this file is located in 'src/file_commands/show.sh'"
2+
echo "# code for 'cli file show' goes here"
3+
echo "# you can edit it freely and regenerate (it will not be overwritten)"
4+
inspect_args
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## Code here runs inside the initialize() function
2+
## Use it for anything that you need to run before any other function, like
3+
## setting environment vairables:
4+
## CONFIG_FILE=settings.ini
5+
##
6+
## Feel free to empty (but not delete) this file.

examples/command-filenames/test.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
3+
rm -f ./src/*.sh
4+
5+
set -x
6+
7+
bashly generate
8+
9+
### Try Me ###
10+
11+
./cli
12+
./cli -h
13+
./cli dir list

lib/bashly/config_validator.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ def assert_command(key, value)
117117
assert_optional_string "#{key}.help", value['help']
118118
assert_optional_string "#{key}.footer", value['footer']
119119
assert_optional_string "#{key}.group", value['group']
120+
assert_optional_string "#{key}.filename", value['filename']
120121

121122
assert_boolean "#{key}.default", value['default']
122123
assert_version "#{key}.version", value['version']

0 commit comments

Comments
 (0)