-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathincludehelp
executable file
·153 lines (136 loc) · 3.94 KB
/
includehelp
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/env sh
### Script: includehelp
##
## コマンドのヘルプをコメントに追加する。
##
## Metadata:
##
## id - 377d59eb-09df-4db7-8afa-e6eeaffc928c
## author - <qq542vev at https://purl.org/meta/me/>
## version - 0.1.1
## date - 2022-09-28
## since - 2022-09-13
## copyright - Copyright (C) 2022-2022 qq542vev. Some rights reserved.
## license - <CC-BY at https://creativecommons.org/licenses/by/4.0/>
## package - w3mplus
##
## See Also:
##
## * <Project homepage at https://github.com/qq542vev/w3mplus>
## * <Bug report at https://github.com/qq542vev/w3mplus/issues>
##
## Help Output:
##
## ------ Text ------
## Usage:
## includehelp [OPTION]... [FILE]...
##
## Options:
## -i, --{no-}in-place FILE を更新して保存する
## -h, --help このヘルプを表示して終了する
## -v, --version バージョン情報を表示して終了する
##
## Exit Status:
## 0 - successful termination
## 64 - command line usage error
## 65 - data format error
## 66 - cannot open input
## 67 - addressee unknown
## 68 - host name unknown
## 69 - service unavailable
## 70 - internal software error
## 71 - system error (e.g., can't fork)
## 72 - critical OS file missing
## 73 - can't create (user) output file
## 74 - input/output error
## 75 - temp failure; user is invited to retry
## 76 - remote error in protocol
## 77 - permission denied
## 78 - configuration error
## 129 - received SIGHUP
## 130 - received SIGINT
## 131 - received SIGQUIT
## 143 - received SIGTERM
## ------------------
readonly 'VERSION=includehelp 0.1.1'
. 'initialize.sh'
. 'option_error.sh'
# @getoptions
parser_definition() {
setup REST abbr:true error:optuon_error plus:true no:0 help:usage \
-- 'Usage:' " ${2##*/} [OPTION]... [FILE]..." \
'' 'Options:'
flag placeFlag -i --{no-}in-place init:@no -- 'FILE を更新して保存する'
disp :usage -h --help -- 'このヘルプを表示して終了する'
disp VERSION -v --version -- 'バージョン情報を表示して終了する'
msg -- '' 'Exit Status:' \
' 0 - successful termination' \
' 64 - command line usage error' \
' 65 - data format error' \
' 66 - cannot open input' \
' 67 - addressee unknown' \
' 68 - host name unknown' \
' 69 - service unavailable' \
' 70 - internal software error' \
" 71 - system error (e.g., can't fork)" \
' 72 - critical OS file missing' \
" 73 - can't create (user) output file" \
' 74 - input/output error' \
' 75 - temp failure; user is invited to retry' \
' 76 - remote error in protocol' \
' 77 - permission denied' \
' 78 - configuration error' \
' 129 - received SIGHUP' \
' 130 - received SIGINT' \
' 131 - received SIGQUIT' \
' 143 - received SIGTERM'
}
# @end
# @gengetoptions parser -i parser_definition parse "${1}"
# @end
eval "$(getoptions parser_definition parse "${0}")"
parse ${@+"${@}"}
eval "set -- ${REST}"
tmpDir=$(mktemp -d)
tmpFile="${tmpDir}/file"
awkScript=$(
cat <<-'__EOF__'
$0 == "## Help Output:", $0 == "" {
if($0 == "## ------ Text ------" && FILENAME != "-") {
printf("%s\n", $0)
command = sprintf("'%s' --help", (index(FILENAME, "/") ? "" : "./") FILENAME)
while(0 < (command | getline recode)) {
if(recode == "") {
printf("##\n")
} else {
printf("## %s\n", recode)
}
}
close(command)
while(0 < getline) {
if($0 == "## ------------------") {
printf("%s\n", $0)
break
}
}
next
}
}
{
printf("%s\n", $0)
}
__EOF__
)
case "${placeFlag}" in
'0') awk -- "${awkScript}" ${@+"${@}"};;
*)
for file in ${@+"${@}"}; do
case "${file}" in '-')
printf "%s: '-i', '--in-place' オプションでは標準入力は使用できません。無視します。\\n" "${0##*/}" >&2
continue
esac
awk -- "${awkScript}" "${file}" >"${tmpFile}"
cat -- "${tmpFile}" >"${file}"
done
;;
esac