File tree Expand file tree Collapse file tree 4 files changed +25
-12
lines changed Expand file tree Collapse file tree 4 files changed +25
-12
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,8 @@ $ bashly init
11
11
$ bashly generate
12
12
```
13
13
14
+ <!-- include: src/root_command.sh -->
15
+
14
16
-----
15
17
16
18
## ` bashly.yml `
@@ -39,6 +41,29 @@ examples:
39
41
- cat file* | cli - --format csv
40
42
` ` `
41
43
44
+ ## ` src/root_command.sh`
45
+
46
+ ` ` ` bash
47
+ inspect_args
48
+
49
+ # Read contents of the provided file(s)
50
+ content=""
51
+ for file in "${other_args[@]}"; do
52
+ content+="$(cat "$file")"
53
+ content+=$'\n '
54
+ done
55
+
56
+ # Read stdin if file(s) not provided as arguments
57
+ if [[ -z "$content" ]]; then
58
+ content="$(cat -)"
59
+ fi
60
+
61
+ echo
62
+ echo "collected file contents:"
63
+ echo "$content"
64
+ echo
65
+
66
+ ` ` `
42
67
43
68
44
69
# # Generated script output
Original file line number Diff line number Diff line change 16
16
echo " collected file contents:"
17
17
echo " $content "
18
18
echo
19
-
20
-
Original file line number Diff line number Diff line change 1
1
#! /usr/bin/env bash
2
2
3
- set -x
4
-
5
3
bashly generate
6
4
7
5
# ## Try Me ###
Original file line number Diff line number Diff line change 1
- + bashly generate
2
1
creating user files in src
3
2
skipped src/initialize.sh (exists)
4
3
skipped src/root_command.sh (exists)
5
4
created ./cli
6
5
run ./cli --help to test your bash script
7
- + ./cli -h
8
6
cli - Sample application
9
7
10
8
Usage:
@@ -34,7 +32,6 @@ Examples:
34
32
cat file1 | cli --format csv
35
33
cat file* | cli - --format csv
36
34
37
- + ./cli file1 file2 --format csv
38
35
args:
39
36
- ${args[--format]} = csv
40
37
@@ -48,7 +45,6 @@ file1 content
48
45
file2 content
49
46
50
47
51
- + ./cli -f=csv file1 file2
52
48
args:
53
49
- ${args[--format]} = csv
54
50
@@ -62,16 +58,12 @@ file1 content
62
58
file2 content
63
59
64
60
65
- + cat file1
66
- + ./cli --format csv
67
61
args:
68
62
- ${args[--format]} = csv
69
63
70
64
collected file contents:
71
65
file1 content
72
66
73
- + ./cli -
74
- + cat file1 file2
75
67
args:
76
68
- ${args[--format]} = json
77
69
You can’t perform that action at this time.
0 commit comments