Skip to content

Commit c9a239b

Browse files
committed
add example for private commands
1 parent e3c3217 commit c9a239b

File tree

6 files changed

+130
-0
lines changed

6 files changed

+130
-0
lines changed
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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
-----
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+
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)