File tree Expand file tree Collapse file tree 8 files changed +160
-1
lines changed Expand file tree Collapse file tree 8 files changed +160
-1
lines changed Original file line number Diff line number Diff line change
1
+ src /initialize.sh
2
+ cli
Original file line number Diff line number Diff line change
1
+ # STDIN Example
2
+
3
+ Demonstrates how to read from STDIN.
4
+
5
+ This example was generated with:
6
+
7
+ ``` bash
8
+ $ bashly init --minimal
9
+ # ... now edit bashly.yml to match ...
10
+ $ bashly generate
11
+ # ... now edit *.sh to match ...
12
+ $ bashly generate
13
+ ```
14
+
15
+ <!-- include: src/root_command.sh -->
16
+
17
+ -----
18
+
19
+ ## ` bashly.yml `
20
+
21
+ ``` yaml
22
+ name : cli
23
+ help : STDIN Example
24
+ version : 0.1.0
25
+
26
+ args :
27
+ - name : path
28
+
29
+ # Set the default path value to -, which is the standard operator for stdin.
30
+ default : " -"
31
+ help : Path to file (reads from stdin if empty)
32
+
33
+ flags :
34
+ - long : --file
35
+ short : -f
36
+ arg : path
37
+
38
+ # This is also supported in flags
39
+ # Note that in both cases, your script needs to handle the value '-' as there
40
+ # is no special treatment in bashly, other than allowing '-' as argument.
41
+ default : " -"
42
+ help : Another path to file
43
+ ` ` `
44
+
45
+ ## ` src/root_command.sh`
46
+
47
+ ` ` ` bash
48
+ inspect_args
49
+
50
+ # Since cat knows how to handle '-' as a value, it will work with both a file
51
+ # path and '-' argument.
52
+ cat "${args[path]}"
53
+
54
+ ` ` `
55
+
56
+
57
+ # # Generated script output
58
+
59
+ # ## `$ ./cli some-file`
60
+
61
+ ` ` ` shell
62
+ args:
63
+ - ${args[--file]} = -
64
+ - ${args[path]} = some-file
65
+ some file with some content
66
+
67
+
68
+ ` ` `
69
+
70
+ # ## `$ cat some-file | ./cli`
71
+
72
+ ` ` ` shell
73
+ args:
74
+ - ${args[--file]} = -
75
+ - ${args[path]} = -
76
+ some file with some content
77
+
78
+
79
+ ` ` `
80
+
81
+ # ## `$ cat some-file | ./cli -`
82
+
83
+ ` ` ` shell
84
+ args:
85
+ - ${args[--file]} = -
86
+ - ${args[path]} = -
87
+ some file with some content
88
+
89
+
90
+ ` ` `
91
+
92
+
93
+
Original file line number Diff line number Diff line change
1
+ some file with some content
Original file line number Diff line number Diff line change
1
+ name : cli
2
+ help : STDIN Example
3
+ version : 0.1.0
4
+
5
+ args :
6
+ - name : path
7
+
8
+ # Set the default path value to -, which is the standard operator for stdin.
9
+ default : " -"
10
+ help : Path to file (reads from stdin if empty)
11
+
12
+ flags :
13
+ - long : --file
14
+ short : -f
15
+ arg : path
16
+
17
+ # This is also supported in flags
18
+ # Note that in both cases, your script needs to handle the value '-' as there
19
+ # is no special treatment in bashly, other than allowing '-' as argument.
20
+ default : " -"
21
+ help : Another path to file
22
+
Original file line number Diff line number Diff line change
1
+ inspect_args
2
+
3
+ # Since cat knows how to handle '-' as a value, it will work with both a file
4
+ # path and '-' argument.
5
+ cat " ${args[path]} "
Original file line number Diff line number Diff line change
1
+ #! /usr/bin/env bash
2
+
3
+ rm -f " src/initialize.sh"
4
+
5
+ set -x
6
+
7
+ bashly generate
8
+
9
+ # ## Try Me ###
10
+
11
+ ./cli some-file
12
+ cat some-file | ./cli
13
+ cat some-file | ./cli -
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ while [[ $# -gt 0 ]]; do
7
7
8
8
% end
9
9
10
- -* )
10
+ -? * )
11
11
% if catch_all
12
12
other_args+=("$1")
13
13
shift
Original file line number Diff line number Diff line change
1
+ + bashly generate
2
+ creating user files in src
3
+ created src/initialize.sh
4
+ skipped src/root_command.sh (exists)
5
+ created ./cli
6
+ run ./cli --help to test your bash script
7
+ + ./cli some-file
8
+ args:
9
+ - ${args[--file]} = -
10
+ - ${args[path]} = some-file
11
+ some file with some content
12
+ + cat some-file
13
+ + ./cli
14
+ args:
15
+ - ${args[--file]} = -
16
+ - ${args[path]} = -
17
+ some file with some content
18
+ + cat some-file
19
+ + ./cli -
20
+ args:
21
+ - ${args[--file]} = -
22
+ - ${args[path]} = -
23
+ some file with some content
You can’t perform that action at this time.
0 commit comments