Skip to content

Commit ce9e2cf

Browse files
committed
Merge branch 'master' into add/yaml-compose
2 parents 64bbb30 + cf0dd58 commit ce9e2cf

File tree

8 files changed

+258
-1
lines changed

8 files changed

+258
-1
lines changed

examples/command-private/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
src/connect_ftp_command.sh
2+
src/connect_ssh_command.sh
3+
src/download_command.sh
4+
src/initialize.sh
5+
src/upload_command.sh
6+
cli

examples/command-private/README.md

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# Private Command Example
2+
3+
Demonstrates how to hide a command from the commands list.
4+
5+
This example was generated with:
6+
7+
```bash
8+
$ bashly init
9+
# ... now edit src/bashly.yml to match the example ...
10+
$ bashly generate
11+
```
12+
13+
<!-- include: src/connect_command.sh -->
14+
15+
-----
16+
17+
## `bashly.yml`
18+
19+
```yaml
20+
name: cli
21+
help: Sample application with private commands
22+
version: 0.1.0
23+
24+
commands:
25+
- name: connect
26+
short: c
27+
help: Connect to the metaverse
28+
29+
args:
30+
- name: protocol
31+
required: true
32+
allowed: [ftp, ssh]
33+
help: Protocol to use for connection
34+
35+
# These two commands will be hidden from the commands list, but still executable
36+
# and visible when running 'cli connect-ftp --help' or 'cli connect-ssh --help'
37+
- name: connect-ftp
38+
help: Connect via FTP
39+
private: true
40+
41+
- name: connect-ssh
42+
help: Connect via SSH
43+
private: true
44+
```
45+
46+
## `src/connect_command.sh`
47+
48+
```bash
49+
# Execute a subsequent (private) command based on the PROTOCOL argument
50+
protocol=${args[protocol]}
51+
cmd="./cli connect-$protocol"
52+
echo "=== Calling $cmd"
53+
$cmd
54+
```
55+
56+
57+
## Generated script output
58+
59+
### `$ ./cli`
60+
61+
```shell
62+
cli - Sample application with private commands
63+
64+
Usage:
65+
cli [command]
66+
cli [command] --help | -h
67+
cli --version | -v
68+
69+
Commands:
70+
connect Connect to the metaverse
71+
72+
73+
74+
```
75+
76+
### `$ ./cli -h`
77+
78+
```shell
79+
cli - Sample application with private commands
80+
81+
Usage:
82+
cli [command]
83+
cli [command] --help | -h
84+
cli --version | -v
85+
86+
Commands:
87+
connect Connect to the metaverse
88+
89+
Options:
90+
--help, -h
91+
Show this help
92+
93+
--version, -v
94+
Show version number
95+
96+
97+
98+
```
99+
100+
### `$ ./cli connect ftp`
101+
102+
```shell
103+
=== Calling ./cli connect-ftp
104+
# this file is located in 'src/connect_ftp_command.sh'
105+
# code for 'cli connect-ftp' goes here
106+
# you can edit it freely and regenerate (it will not be overwritten)
107+
args: none
108+
109+
110+
```
111+
112+
### `$ ./cli connect-ssh`
113+
114+
```shell
115+
# this file is located in 'src/connect_ssh_command.sh'
116+
# code for 'cli connect-ssh' goes here
117+
# you can edit it freely and regenerate (it will not be overwritten)
118+
args: none
119+
120+
121+
```
122+
123+
### `$ ./cli connect-ftp --help`
124+
125+
```shell
126+
cli connect-ftp - Connect via FTP
127+
128+
Usage:
129+
cli connect-ftp
130+
cli connect-ftp --help | -h
131+
132+
Options:
133+
--help, -h
134+
Show this help
135+
136+
137+
138+
```
139+
140+
141+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: cli
2+
help: Sample application with private commands
3+
version: 0.1.0
4+
5+
commands:
6+
- name: connect
7+
short: c
8+
help: Connect to the metaverse
9+
10+
args:
11+
- name: protocol
12+
required: true
13+
allowed: [ftp, ssh]
14+
help: Protocol to use for connection
15+
16+
# These two commands will be hidden from the commands list, but still executable
17+
# and visible when running 'cli connect-ftp --help' or 'cli connect-ssh --help'
18+
- name: connect-ftp
19+
help: Connect via FTP
20+
private: true
21+
22+
- name: connect-ssh
23+
help: Connect via SSH
24+
private: true
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Execute a subsequent (private) command based on the PROTOCOL argument
2+
protocol=${args[protocol]}
3+
cmd="./cli connect-$protocol"
4+
echo "=== Calling $cmd"
5+
$cmd

examples/command-private/test.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
3+
# Cleanup before testing
4+
rm -f "src/connect_ftp_command.sh"
5+
rm -f "src/connect_ssh_command.sh"
6+
rm -f "src/download_command.sh"
7+
rm -f "src/initialize.sh"
8+
rm -f "src/upload_command.sh"
9+
10+
set -x
11+
12+
bashly generate
13+
14+
### Try Me ###
15+
16+
./cli
17+
./cli -h
18+
./cli connect ftp
19+
./cli connect-ssh
20+
./cli connect-ftp --help
21+

lib/bashly/script/base.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class Base
2323
long
2424
name
2525
parent_name
26+
private
2627
required
2728
short
2829
validate

lib/bashly/views/command/usage_commands.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
printf "<%= strings[:commands] %>\n"
44
% end
55
% maxlen = command_names.map(&:size).max
6-
% commands.each do |command|
6+
% commands.reject(&:private).each do |command|
77
% summary = command.summary
88
% summary = strings[:default_command_summary] % { summary: summary } if command.default
99
% if command.group
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
+ bashly generate
2+
creating user files in src
3+
created src/initialize.sh
4+
skipped src/connect_command.sh (exists)
5+
created src/connect_ftp_command.sh
6+
created src/connect_ssh_command.sh
7+
created ./cli
8+
run ./cli --help to test your bash script
9+
+ ./cli
10+
cli - Sample application with private commands
11+
12+
Usage:
13+
cli [command]
14+
cli [command] --help | -h
15+
cli --version | -v
16+
17+
Commands:
18+
connect Connect to the metaverse
19+
20+
+ ./cli -h
21+
cli - Sample application with private commands
22+
23+
Usage:
24+
cli [command]
25+
cli [command] --help | -h
26+
cli --version | -v
27+
28+
Commands:
29+
connect Connect to the metaverse
30+
31+
Options:
32+
--help, -h
33+
Show this help
34+
35+
--version, -v
36+
Show version number
37+
38+
+ ./cli connect ftp
39+
=== Calling ./cli connect-ftp
40+
# this file is located in 'src/connect_ftp_command.sh'
41+
# code for 'cli connect-ftp' goes here
42+
# you can edit it freely and regenerate (it will not be overwritten)
43+
args: none
44+
+ ./cli connect-ssh
45+
# this file is located in 'src/connect_ssh_command.sh'
46+
# code for 'cli connect-ssh' goes here
47+
# you can edit it freely and regenerate (it will not be overwritten)
48+
args: none
49+
+ ./cli connect-ftp --help
50+
cli connect-ftp - Connect via FTP
51+
52+
Usage:
53+
cli connect-ftp
54+
cli connect-ftp --help | -h
55+
56+
Options:
57+
--help, -h
58+
Show this help
59+

0 commit comments

Comments
 (0)