-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtarget.sh
More file actions
executable file
·104 lines (86 loc) · 2.78 KB
/
Copy pathtarget.sh
File metadata and controls
executable file
·104 lines (86 loc) · 2.78 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env bash
set -euo pipefail
# shellcheck source=lib/bash-simple-doc.sh
source "$(dirname "${BASH_SOURCE:-$0}")/lib/bash-simple-doc.sh"
function search_file {
@doc "Run a regex against a file"
@arg "--name|-n" "File to search"
@arg "--regex|-r" "Regex to search"
@arg "--output" "Write results to file"
@flag "--quiet|-q" "Suppress output"
@position "name" "File to search"
@position "regex" "Regex to search"
@example "search_file file.txt 'pattern'"
@example "search_file --name file.txt --regex 'pattern' --output result.txt"
local name='' regex='' output='' quiet='false'
@args "$@" || return $?
if [[ $quiet == true ]]; then
log_debug 'quiet mode'
return 0
fi
log_info 'name=%s regex=%s output=%s quiet=%s\n' "$name" "$regex" "$output" "$quiet"
}
function inspect_path {
@doc "Print normalized path inputs for debugging"
@arg "--path|-p" "Path to inspect"
@flag "--quiet|-q" "Suppress output"
@position "path" "Path to inspect"
@example "inspect_path ./lib"
@example "inspect_path --path ./target.sh"
local path='' quiet='false'
@args "$@" || return $?
if [[ $quiet == true ]]; then
return 0
fi
printf 'path=%s quiet=%s\n' "$path" "$quiet"
}
function profile_args {
@doc "Show required, nullable, default, and optional args"
@arg "required" "--name|-n" "Your name"
@arg "nullable" "--age" "Your age"
@arg "default=185" "--height" "Your height"
@arg "--country" "Country you live"
@example "profile_args --name alice"
@example "profile_args --name alice --age '' --country BR"
local name='' age='' height='' country=''
@args "$@" || return $?
printf 'name=%s age=%s height=%s country=%s\n' "$name" "$age" "$height" "$country"
}
function quoted_metadata {
@doc "Say \"hello\" today"
@arg "--name|-n" "Person \"nickname\""
@flag "--quiet|-q" "Be \"silent\""
@position "target" "Target \"path\""
@example "quoted_metadata --name \"Bob\" file.txt"
local name='' quiet='false' target=''
@args "$@" || return $?
if [[ $quiet == true ]]; then
return 0
fi
printf 'name=%s quiet=%s target=%s\n' "$name" "$quiet" "$target"
}
function internal_metadata {
@doc "Show mixed public and internal metadata"
@arg "--name|-n" "Visible name"
@internal
@arg "--token|-t" "Internal token"
@position "name" "Visible name"
@internal
@position "secret" "Internal secret"
@example "internal_metadata alice"
@internal
@example "internal_metadata --token top-secret alice hidden"
local name='' token='' secret=''
@args "$@" || return $?
printf 'name=%s token=%s secret=%s\n' "$name" "$token" "$secret"
}
function hidden_summary {
@internal
@doc "Internal-only command summary"
@internal
@arg "--token|-t" "Hidden token"
local token=''
@args "$@" || return $?
printf 'token=%s\n' "$token"
}
@main "$@"