Skip to content

Commit a8cb0e2

Browse files
committed
update command filename example
1 parent 51f7ca1 commit a8cb0e2

File tree

6 files changed

+106
-71
lines changed

6 files changed

+106
-71
lines changed

examples/command-filenames/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
src/*.sh
2+
src/dir_commands
3+
src/file_commands
14
cli

examples/command-filenames/README.md

Lines changed: 56 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
# Command Groups Example
1+
# Command Filenames Example
22

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.
3+
Demonstrates how to specify custom filenames for command source files.
4+
This is useful for scripts with many commands, in case you wish to organize
5+
your source files in sub-folders.
6+
7+
Note that the specified path is relative to the `sec` folder.
68

79
This example was generated with:
810

@@ -17,86 +19,77 @@ $ bashly generate
1719
## `bashly.yml`
1820

1921
```yaml
20-
name: ftp
21-
help: Sample application with command grouping
22+
name: cli
23+
help: Demonstrate custom command filenames
2224
version: 0.1.0
2325

2426
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
27+
- name: dir
28+
short: d
29+
help: Directory commands
30+
31+
commands:
32+
- name: list
33+
help: Show files in the directory
34+
35+
# Define a custom filename for this command source.
36+
# This is relative to the `src` directory, and sub-directories will be
37+
# created as needed.
38+
filename: dir_commands/list.sh
39+
40+
- name: remove
41+
help: Remove directory
42+
filename: dir_commands/remove.sh
43+
44+
- name: file
45+
short: f
46+
help: File commands
47+
48+
commands:
49+
- name: show
50+
help: Show file contents
51+
filename: file_commands/show.sh
52+
53+
- name: edit
54+
help: Edit the file
55+
filename: file_commands/edit.sh
5556
```
5657
5758
5859
5960
## Generated script output
6061
61-
### `$ ./ftp`
62+
### `$ ./cli`
6263

6364
```shell
64-
ftp - Sample application with command grouping
65+
cli - Demonstrate custom command filenames
6566
6667
Usage:
67-
ftp [command]
68-
ftp [command] --help | -h
69-
ftp --version | -v
68+
cli [command]
69+
cli [command] --help | -h
70+
cli --version | -v
7071
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
72+
Commands:
73+
dir Directory commands
74+
file File commands
7875
7976
8077
8178
```
8279

83-
### `$ ./ftp -h`
80+
### `$ ./cli -h`
8481

8582
```shell
86-
ftp - Sample application with command grouping
83+
cli - Demonstrate custom command filenames
8784
8885
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
86+
cli [command]
87+
cli [command] --help | -h
88+
cli --version | -v
9689
97-
Login Commands:
98-
login Write login credentials to the config file
99-
logout Delete login credentials to the config file
90+
Commands:
91+
dir Directory commands
92+
file File commands
10093
10194
Options:
10295
--help, -h
@@ -109,11 +102,11 @@ Options:
109102
110103
```
111104

112-
### `$ ./ftp login`
105+
### `$ ./cli dir list`
113106

114107
```shell
115-
# this file is located in 'src/login_command.sh'
116-
# code for 'ftp login' goes here
108+
# this file is located in 'src/dir_commands/list.sh'
109+
# code for 'cli dir list' goes here
117110
# you can edit it freely and regenerate (it will not be overwritten)
118111
args: none
119112

examples/command-filenames/test.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env bash
22

33
rm -f ./src/*.sh
4+
rm -rf ./src/dir_commands
5+
rm -rf ./src/file_commands
46

57
set -x
68

examples/stdin/test.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
rm -f "src/initialize.sh"
44

5-
set -x
6-
75
bashly generate
86

97
### Try Me ###
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
+ bashly generate
2+
creating user files in src
3+
created src/initialize.sh
4+
created src/dir_commands/list.sh
5+
created src/dir_commands/remove.sh
6+
created src/file_commands/show.sh
7+
created src/file_commands/edit.sh
8+
created ./cli
9+
run ./cli --help to test your bash script
10+
+ ./cli
11+
cli - Demonstrate custom command filenames
12+
13+
Usage:
14+
cli [command]
15+
cli [command] --help | -h
16+
cli --version | -v
17+
18+
Commands:
19+
dir Directory commands
20+
file File commands
21+
22+
+ ./cli -h
23+
cli - Demonstrate custom command filenames
24+
25+
Usage:
26+
cli [command]
27+
cli [command] --help | -h
28+
cli --version | -v
29+
30+
Commands:
31+
dir Directory commands
32+
file File commands
33+
34+
Options:
35+
--help, -h
36+
Show this help
37+
38+
--version, -v
39+
Show version number
40+
41+
+ ./cli dir list
42+
# this file is located in 'src/dir_commands/list.sh'
43+
# code for 'cli dir list' goes here
44+
# you can edit it freely and regenerate (it will not be overwritten)
45+
args: none

spec/approvals/examples/stdin

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
1-
+ bashly generate
21
creating user files in src
32
created src/initialize.sh
43
skipped src/root_command.sh (exists)
54
created ./cli
65
run ./cli --help to test your bash script
7-
+ ./cli some-file
86
args:
97
- ${args[--file]} = -
108
- ${args[path]} = some-file
119
some file with some content
12-
+ cat some-file
13-
+ ./cli
1410
args:
1511
- ${args[--file]} = -
1612
- ${args[path]} = -
1713
some file with some content
18-
+ cat some-file
19-
+ ./cli -
2014
args:
2115
- ${args[--file]} = -
2216
- ${args[path]} = -

0 commit comments

Comments
 (0)