-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtarget-posix.sh
More file actions
executable file
·67 lines (54 loc) · 2.06 KB
/
Copy pathtarget-posix.sh
File metadata and controls
executable file
·67 lines (54 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/sh
# shellcheck disable=SC2119,SC2154 # Metadata calls intentionally omit command arguments.
set -eu
BASH_COMMAND_CORE_DIR=${BASH_COMMAND_CORE_DIR:-.}
# shellcheck source=lib/posix-simple-doc.sh
. "$BASH_COMMAND_CORE_DIR/lib/posix-simple-doc.sh"
psd_command_search_file() {
psd_doc 'Run a regex against a file'
psd_arg '--regex|-r' 'Regex to search'
psd_flag '--quiet|-q' 'Suppress matching lines'
psd_pos file 'File to search'
psd_example 'search_file --regex pattern file.txt' 'search_file -r pattern file.txt'
psd_parse "$@" || return $?
if [ "$quiet" = true ]; then grep -q -e "$regex" "$file"; else grep -e "$regex" "$file"; fi
}
psd_command_greet() {
psd_doc 'Greet a person' \
'Use --name to choose who receives the greeting.' \
'Use --loud for an uppercase greeting.' \
'The name is required.'
psd_arg required '--name|-n' 'Person to greet'
psd_flag '--loud|-l' 'Use an enthusiastic greeting'
psd_example 'greet --name Gabriel' 'greet -n Gabriel --loud'
psd_parse "$@" || return $?
if [ "$loud" = true ]; then printf 'HELLO, %s!\n' "$name"; else printf 'Hello, %s.\n' "$name"; fi
}
psd_command_inspect_path() {
psd_doc 'Inspect a path'
psd_arg nullable '--path|-p|input_path' 'Path to inspect'
psd_pos 'path|input_path' 'Path to inspect'
psd_internal
psd_arg '--token' 'Internal token'
psd_internal
psd_example 'inspect_path --path ./lib'
psd_parse "$@" || return $?
log_debug 'path=%s token=%s' "$input_path" "$token"
printf 'path=%s\n' "$input_path"
}
psd_command_with_default() {
psd_doc 'Example with default value'
psd_arg default=185 '--height' 'Your height'
psd_arg required '--name' 'Your name'
psd_pos name 'Your name'
psd_parse "$@" || return $?
printf 'name=%s height=%s\n' "$name" "$height"
}
psd_command_internal_status() {
psd_internal
psd_doc 'Internal diagnostic command'
psd_parse "$@" || return $?
printf '%s\n' 'internal'
}
psd_register search_file greet inspect_path with_default internal_status
psd_main "$@"