Skip to content

Commit ee76065

Browse files
authored
Merge pull request #171 from DannyBen/add/custom-command-path
Allow specifying filenames for command partials
2 parents ed88258 + a8cb0e2 commit ee76065

File tree

19 files changed

+256
-13
lines changed

19 files changed

+256
-13
lines changed

examples/command-filenames/.gitignore

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

examples/command-filenames/README.md

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# Command Filenames Example
2+
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.
8+
9+
This example was generated with:
10+
11+
```bash
12+
$ bashly init
13+
# ... now edit src/bashly.yml to match the example ...
14+
$ bashly generate
15+
```
16+
17+
-----
18+
19+
## `bashly.yml`
20+
21+
```yaml
22+
name: cli
23+
help: Demonstrate custom command filenames
24+
version: 0.1.0
25+
26+
commands:
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
56+
```
57+
58+
59+
60+
## Generated script output
61+
62+
### `$ ./cli`
63+
64+
```shell
65+
cli - Demonstrate custom command filenames
66+
67+
Usage:
68+
cli [command]
69+
cli [command] --help | -h
70+
cli --version | -v
71+
72+
Commands:
73+
dir Directory commands
74+
file File commands
75+
76+
77+
78+
```
79+
80+
### `$ ./cli -h`
81+
82+
```shell
83+
cli - Demonstrate custom command filenames
84+
85+
Usage:
86+
cli [command]
87+
cli [command] --help | -h
88+
cli --version | -v
89+
90+
Commands:
91+
dir Directory commands
92+
file File commands
93+
94+
Options:
95+
--help, -h
96+
Show this help
97+
98+
--version, -v
99+
Show version number
100+
101+
102+
103+
```
104+
105+
### `$ ./cli dir list`
106+
107+
```shell
108+
# this file is located in 'src/dir_commands/list.sh'
109+
# code for 'cli dir list' goes here
110+
# you can edit it freely and regenerate (it will not be overwritten)
111+
args: none
112+
113+
114+
```
115+
116+
117+
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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bash
2+
3+
rm -f ./src/*.sh
4+
rm -rf ./src/dir_commands
5+
rm -rf ./src/file_commands
6+
7+
set -x
8+
9+
bashly generate
10+
11+
### Try Me ###
12+
13+
./cli
14+
./cli -h
15+
./cli dir list

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 ###

0 commit comments

Comments
 (0)