Repository navigation
Expand file tree
/
Copy pathgenapp__help.sh
More file actions
258 lines (200 loc) · 5.35 KB
/
Copy pathgenapp__help.sh
File metadata and controls
258 lines (200 loc) · 5.35 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
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#!/bin/bash
###############################################################################
#
# Genapp tool
#
# Copyright (c) 2026 Michel Mehl. All rights reserved.
#
# ------------------------------------------------------------------------------
#
# This file contains the definition of all man and help functions.
#
# ------------------------------------------------------------------------------
#
# Report bugs to michel.mehl@slashetc.fr
#
###############################################################################
Genapp__version() {
local verfile="${GENAPP__VARS["MYDIR"]}/VERSION.txt"
local revfile="${GENAPP__VARS["MYDIR"]}/REVISION.txt"
local copyright="${GENAPP__VARS["MYDIR"]}/COPYRIGHT.txt"
# Version info
# Version file contains one line giving the version x.y.z
echo -n "${__SHELL_CURRENT_APPNAME__} "
if [ -f "${verfile}" ] ; then
cat "${verfile}"
else
echo "?.?.?"
fi
# Revision info if any
# Revision file contains 2 lines
# Line 1: the revision number in the configuration management system
# Line 2: a signature like a hash code computed over the source files
if [ -f "${revfile}" ] ; then
echo -n "Revision "
local line
local cnt=0
while IFS='' read -r line
do
if [ $cnt -eq 0 ] ; then
echo -n "$line"
elif [ $cnt -eq 1 ] ; then
echo -n " signed $line"
fi
cnt=$(($cnt + 1))
done < <(cat "${revfile}")
if [ $cnt -eq 1 ] ; then
echo -n " (unsigned)"
fi
echo
fi
# Copyright
# The trailing line from 4th line are displayed
if [ -f "${copyright}" ] ; then
echo
local content="$(cat "${copyright}")"
echo "${content}"|tail -n+3
fi
# Author
# Author fullname is retrieved from passwd
local fnUser=""
User__getFullUserName fnUser
cat<<EOF
Written by ${fnUser}
EOF
}
Genapp__hash() {
local revfile="${GENAPP__VARS["MYDIR"]}/REVISION.txt"
# Revision info if any
if [ -f "${revfile}" ] ; then
local line
local __lcnt=0
local hashcode=""
while IFS='' read -r line
do
if [ ${__lcnt} -eq 1 ] ; then
hashcode="$line"
break
fi
__lcnt=$((${__lcnt} + 1))
done < <(cat "${revfile}")
if [ -z "$hashcode" ] ; then
echo "?"
else
echo "$hashcode"
fi
else
echo "?"
fi
}
Genapp__versionnum() {
local vfile="${GENAPP__VARS["MYDIR"]}/VERSION.txt"
if [ -f "$vfile" ] ; then
cat << EOF
$(cat "$vfile")
EOF
else
echo "?"
fi
}
Genapp__revision() {
local revfile="${GENAPP__VARS["MYDIR"]}/REVISION.txt"
# Revision info if any
if [ -f "${revfile}" ] ; then
local line
local __lcnt=0
local revisionnum=""
while IFS='' read -r line
do
if [ ${__lcnt} -eq 0 ] ; then
revisionnum="$line"
break
fi
__lcnt=$((${__lcnt} + 1))
done < <(cat "${revfile}")
if [ -z "$revisionnum" ] ; then
echo "?"
else
echo "$revisionnum"
fi
else
echo "?"
fi
}
:<<'EOF'
Help display callback (-h) for usage
EOF
Genapp__help() {
echo
Genapp__usage
}
:<<'EOF'
Short usage display callback without the option details
EOF
Genapp__susage_without_options() {
local __cmdbasename="$(basename $0)"
cat << EOF
Usage: ${__cmdbasename} OPTIONS <application name>
EOF
#or: ${__cmdbasename} OPTIONS [<sample arg 2>]
}
:<<'EOF'
Usage display callback
EOF
Genapp__susage() {
local ctrlFlag=""
if [ $# -gt 0 ] ; then
ctrlFlag="$1"
fi
cat << EOF
$(Genapp__susage_without_options)
OPTIONS:
$(_soptions GENAPP__OPTION_LIST_DESC GENAPP__OPTION_LIST_SDESC GENAPP__OPTION_LIST_ARGS GENAPP__OPTION_LIST_ARGS_TYPE GENAPP__OPTION_LIST_INTERN "" $ctrlFlag)
EOF
}
Genapp__usage_args() {
cat << EOF
Arguments:
<application name> a word identifying the app, starting with an uppercase (will be enforced)
EOF
}
:<<'EOF'
Usage display callback
EOF
Genapp__usage() {
cat << EOF
$(Genapp__susage)
$(Genapp__usage_args)
EOF
}
Genapp__examples() {
local exampleFile="${GENAPP__VARS["MYDIR"]}/EXAMPLES.txt"
if [ -f "${exampleFile}" ] ; then
cat "${exampleFile}"
fi
}
Genapp__man() {
cat << EOF | less
*SYNOPSIS*
$(Genapp__susage_without_options)
$(Genapp__usage_args)
OPTIONS:
$(_soptions GENAPP__OPTION_LIST_DESC GENAPP__OPTION_LIST_SDESC GENAPP__OPTION_LIST_ARGS GENAPP__OPTION_LIST_ARGS_TYPE GENAPP__OPTION_LIST_INTERN "" "man")
*DESCRIPTION*
Genapp tool generates shell script app skeletons that build upon the shell-api library. The generated skeletons are immediately operational and ready for the app implementation. It will generate the following files:
- COPYRIGHT.txt : copyright notice
- LICENSE.txt: MIT by default, to be replaced if necessary
- CHANGELOG.txt: to be filled out as versions are released
- EXAMPLES.txt: List of examples. Indentation matters for manpage.
- <yourapp>__options.sh: file for managing options. For default ones, see doc.
- <yourapp>__help.h: file providing help functions.
- <yourapp>__vars.h: file containing the app-specific global variables
- <yourapp>: application skeleton
- pack/debian/control : for packaging with dpkg
$(_optionsN GENAPP__OPTION_LIST_DESC GENAPP__OPTION_LIST_ARGS GENAPP__OPTION_LIST_ARGS_TYPE GENAPP__OPTION_LIST_INTERN 0)
$(_optionsN GENAPP__OPTION_LIST_DESC GENAPP__OPTION_LIST_ARGS GENAPP__OPTION_LIST_ARGS_TYPE GENAPP__OPTION_LIST_INTERN 1)
*EXAMPLES*
$(Genapp__examples)
Report bugs to <michel.mehl@slashetc.fr>
EOF
}