Skip to content

Commit 6469ee1

Browse files
authored
Merge pull request #543 from DannyBen/add/flag-needs
Add support for needy flags: `flag.needs`
2 parents 3fd3aab + a7fb1d6 commit 6469ee1

File tree

32 files changed

+430
-15
lines changed

32 files changed

+430
-15
lines changed

examples/command-default-force/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ args: none
9393
tester all - Run all tests
9494

9595
Usage:
96-
tester all
96+
tester [all]
9797
tester all --help | -h
9898

9999
Options:

examples/command-default/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,38 @@ args:
102102
- ${args[source]} = something
103103

104104

105+
````
106+
107+
### `$ ./ftp upload`
108+
109+
````shell
110+
missing required argument: SOURCE
111+
usage: ftp [upload] SOURCE
112+
113+
114+
````
115+
116+
### `$ ./ftp upload -h`
117+
118+
````shell
119+
ftp upload - Upload a file
120+
121+
Alias: u
122+
123+
Usage:
124+
ftp [upload] SOURCE
125+
ftp upload --help | -h
126+
127+
Options:
128+
--help, -h
129+
Show this help
130+
131+
Arguments:
132+
SOURCE
133+
File to upload
134+
135+
136+
105137
````
106138

107139
### `$ ./ftp upload something`

examples/conflicts/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,15 @@ Usage:
5151
Options:
5252
--cache
5353
Enable cache
54+
Conflicts: --no-cache
5455

5556
--no-cache
5657
Disable cache
58+
Conflicts: --cache, --fast
5759

5860
--fast
5961
Run faster
62+
Conflicts: --no-cache
6063

6164
--help, -h
6265
Show this help

examples/needs/.gitignore

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

examples/needs/README.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# Needy Flags Example
2+
3+
Demonstrates the use of needy flags that must be executed together.
4+
5+
This example was generated with:
6+
7+
```bash
8+
$ bashly init --minimal
9+
# ... now edit src/bashly.yml to match the example ...
10+
$ bashly generate
11+
```
12+
13+
-----
14+
15+
## `bashly.yml`
16+
17+
````yaml
18+
name: cli
19+
help: Sample application to demonstrate the use of needy flags
20+
version: 0.1.0
21+
22+
flags:
23+
- long: --add
24+
short: -a
25+
arg: alias
26+
help: Alias to add
27+
# When using --add, --command and --target must also be provided
28+
needs: [--command, --target]
29+
30+
- long: --command
31+
short: -c
32+
arg: command
33+
help: Command for the alias
34+
# Note that this relationship is marked on both sides
35+
needs: [--add]
36+
37+
- long: --target
38+
short: -t
39+
arg: target
40+
help: Where to add the alias
41+
needs: [--add]
42+
allowed: [global, local]
43+
````
44+
45+
46+
47+
## Output
48+
49+
### `$ ./cli -h`
50+
51+
````shell
52+
cli - Sample application to demonstrate the use of needy flags
53+
54+
Usage:
55+
cli [OPTIONS]
56+
cli --help | -h
57+
cli --version | -v
58+
59+
Options:
60+
--add, -a ALIAS
61+
Alias to add
62+
Needs: --command, --target
63+
64+
--command, -c COMMAND
65+
Command for the alias
66+
Needs: --add
67+
68+
--target, -t TARGET
69+
Where to add the alias
70+
Allowed: global, local
71+
Needs: --add
72+
73+
--help, -h
74+
Show this help
75+
76+
--version, -v
77+
Show version number
78+
79+
80+
81+
````
82+
83+
### `$ ./cli --add deploy`
84+
85+
````shell
86+
--add requires --command
87+
88+
89+
````
90+
91+
### `$ ./cli --add deploy --command 'git push'`
92+
93+
````shell
94+
--add requires --target
95+
96+
97+
````
98+
99+
### `$ ./cli --add deploy --command 'git push' --target local`
100+
101+
````shell
102+
# this file is located in 'src/root_command.sh'
103+
# you can edit it freely and regenerate (it will not be overwritten)
104+
args:
105+
- ${args[--add]} = deploy
106+
- ${args[--command]} = git push
107+
- ${args[--target]} = local
108+
109+
110+
````
111+
112+
113+

examples/needs/src/bashly.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: cli
2+
help: Sample application to demonstrate the use of needy flags
3+
version: 0.1.0
4+
5+
flags:
6+
- long: --add
7+
short: -a
8+
arg: alias
9+
help: Alias to add
10+
# When using --add, --command and --target must also be provided
11+
needs: [--command, --target]
12+
13+
- long: --command
14+
short: -c
15+
arg: command
16+
help: Command for the alias
17+
# Note that this relationship is marked on both sides
18+
needs: [--add]
19+
20+
- long: --target
21+
short: -t
22+
arg: target
23+
help: Where to add the alias
24+
needs: [--add]
25+
allowed: [global, local]
26+

examples/needs/src/root_command.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
echo "# this file is located in 'src/root_command.sh'"
2+
echo "# you can edit it freely and regenerate (it will not be overwritten)"
3+
inspect_args

examples/needs/test.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
3+
set -x
4+
5+
bashly generate
6+
7+
### Try Me ###
8+
9+
./cli -h
10+
./cli --add deploy
11+
./cli --add deploy --command 'git push'
12+
./cli --add deploy --command 'git push' --target local

examples/render-mandoc/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ ISSUE TRACKER
102102
AUTHORS
103103
Lana Lang.
104104

105-
Version 0.1.0 July 2024 download(1)
105+
Version 0.1.0 August 2024 download(1)
106106

107107

108108
````

examples/render-mandoc/docs/download.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.\" Automatically generated by Pandoc 3.2
22
.\"
3-
.TH "download" "1" "July 2024" "Version 0.1.0" "Sample application"
3+
.TH "download" "1" "August 2024" "Version 0.1.0" "Sample application"
44
.SH NAME
55
\f[B]download\f[R] \- Sample application
66
.SH SYNOPSIS

0 commit comments

Comments
 (0)