Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
bashopts
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mbedsys
bashopts
Commits
d7b15340
Commit
d7b15340
authored
May 30, 2018
by
Emeric Verschuur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve the help display for big size values
parent
83ec9852
Pipeline
#98
passed with stage
in 13 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
31 deletions
+37
-31
CHANGELOG.md
CHANGELOG.md
+3
-0
VERSION
VERSION
+1
-1
bashopts.sh
bashopts.sh
+32
-29
test.sh
test.sh
+1
-1
No files found.
CHANGELOG.md
View file @
d7b15340
# Changelog
# Changelog
## 2.0.1
*
Improve the help display for big size values
## 2.0.0
## 2.0.0
*
Add version and Changelog
*
Add version and Changelog
*
Add enum type
*
Add enum type
...
...
VERSION
View file @
d7b15340
2.0.
0
2.0.
1
bashopts.sh
View file @
d7b15340
...
@@ -19,7 +19,7 @@
...
@@ -19,7 +19,7 @@
set
-e
set
-e
BASHOPTS_VERSION
=
2.0.
0
BASHOPTS_VERSION
=
2.0.
1
bashopts_exit_handle
()
{
bashopts_exit_handle
()
{
local
err
=
$?
local
err
=
$?
...
@@ -428,20 +428,21 @@ bashopts_dump_value() {
...
@@ -428,20 +428,21 @@ bashopts_dump_value() {
bashopts_diplay_help() {
bashopts_diplay_help() {
local elts optargs_max_len=8 val ncol line
local elts optargs_max_len=8 val ncol line
declare -A optargs
declare -A optargs
ncol=
$(
tput cols
||
true
)
2> /dev/null
ncol=
$(
tput cols 2> /dev/null
||
true
)
ncol=
${
ncol
:-
160
}
local value_max_len=
$((
$ncol
/
4
))
# compute the good arguments comumn size
# compute the good arguments comumn size
for op in "
${
bashopts_optlist
[@]
}
"; do
for op in "
${
bashopts_optlist
[@]
}
"; do
elts=()
elts=()
unset val
unset val
if ! [[
$op
=~ ^__.*__
$
]] && [[ -v
$op
]]; then
if ! [[
$op
=~ ^__.*__
$
]] && [[ -v
$op
]]; then
val="
$(
bashopts_dump_value
$op
)
"
val="
$(
bashopts_dump_value
$op
|
tr
-d
'\n'
)
"
fi
fi
if [[ -v bashopts_optprop_short_opt[
$op
] ]]; then elts+=("
-
${
bashopts_optprop_short_opt
[
$op
]
}
"); fi
if [[ -v bashopts_optprop_short_opt[
$op
] ]]; then elts+=("
-
${
bashopts_optprop_short_opt
[
$op
]
}
"); fi
if [[ -v bashopts_optprop_long_opt[
$op
] ]]; then elts+=("
--
${
bashopts_optprop_long_opt
[
$op
]
}
"); fi
if [[ -v bashopts_optprop_long_opt[
$op
] ]]; then elts+=("
--
${
bashopts_optprop_long_opt
[
$op
]
}
"); fi
optargs[
$op
]="
$(
bashopts_join_by ,
${
elts
[@]
}
)
$
val
"
optargs[
$op
]="
$(
bashopts_join_by ,
${
elts
[@]
}
)
$
{
val
:0:
${
value_max_len
}}
"
optargs_max_len=
$(
bashopts_math_max
$optargs_max_len
${#
optargs
[
$op
]
}
)
optargs_max_len=
$(
bashopts_math_max
$optargs_max_len
${#
optargs
[
$op
]
}
)
done
done
ncol=
${
ncol
:-
160
}
optargs_max_len=
$(
bashopts_math_min
$optargs_max_len
$((
$ncol
/
3
))
)
optargs_max_len=
$(
bashopts_math_min
$optargs_max_len
$((
$ncol
/
3
))
)
# display global info
# display global info
echo
echo
...
@@ -454,32 +455,33 @@ bashopts_diplay_help() {
...
@@ -454,32 +455,33 @@ bashopts_diplay_help() {
echo "
OPTIONS
:
"
echo "
OPTIONS
:
"
for op in "
${
bashopts_optlist
[@]
}
"; do
for op in "
${
bashopts_optlist
[@]
}
"; do
# display arguments, value if available, description, and additional info if available
# display arguments, value if available, description, and additional info if available
printf "
%-
${
optargs_max_len
}
s
%s\n
" "
${
optargs
[
$op
]
}
" "
${
bashopts_optprop_description
[
$op
]
}
$(
printf "
%-
${
optargs_max_len
}
s
${
bashopts_optprop_description
[
$op
]
}
" "
${
optargs
[
$op
]
}
"
if
!
[[
$op
=
~ ^__.
*
__
$
]]
;
then
if ! [[
$op
=~ ^__.*__
$
]]; then
# display additional information the each properties
# display additional information the each properties
# discarding special options like --help
# discarding special options like --help
echo
-n
"- [
\$
$op
] (type:
${
bashopts_optprop_type
[
$op
]
}
"
echo -n "
- [\
$$op
] (type
:
${
bashopts_optprop_type
[
$op
]
}
"
if
[[
-v
bashopts_optprop_expression[
$op
]
]]
;
then
if [[ -v bashopts_optprop_expression[
$op
] ]]; then
echo
-n
", default:
\"
${
bashopts_optprop_expression
[
$op
]//\
"/
\\\"
}
\"
"
printf "
, default
:
\
"%.
${
value_max_len
}
s
\"
"
"
$(
tr
-d
'\n'
<<<
"
${
bashopts_optprop_expression
[
$op
]//\
"/
\\\"
}"
)
"
elif [[ -v bashopts_optprop_default[
$op
] ]]; then
elif [[ -v bashopts_optprop_default[
$op
] ]]; then
if [[
"
${
bashopts_optprop_type
[
$op
]
}
"
=~ ^(string|enumeration)
$
]]; then
if [[ "
${
bashopts_optprop_type
[
$op
]
}
" =~ ^(string|enumeration)
$
]]; then
echo -n
", default:
\"
${
bashopts_optprop_default
[
$op
]//\
"/
\\\"
}
\"
"
printf "
, default
:
\
"%.
${
value_max_len
}
s
\"
"
"
$(
tr
-d
'\n'
<<<
"
${
bashopts_optprop_default
[
$op
]//\
"/
\\\"
}"
)
"
else
echo -n
", default:
${
bashopts_optprop_default
[
$op
]
}
"
fi
else
else
elts=
")"
printf "
, default
:
%.
${
value_max_len
}
s
" "
$(
tr
-d
'\n'
<<<
"
${
bashopts_optprop_default
[
$op
]
}
"
)
"
fi
fi
if [
"
${
bashopts_optprop_type
[
$op
]
}
"
==
"enumeration"
]; then
else
echo -n
", accepted values:
$(
elts="
)
"
while
read
-r
line
;
do
fi
echo
-n
" '
${
line
##*|
}
'"
if [ "
${
bashopts_optprop_type
[
$op
]
}
" == "
enumeration
" ]; then
done
<<<
"
${
bashopts_optprop_enum_values
[
$op
]
}
"
echo -n "
, accepted values
:
$(
)
"
while
read
-r
line
;
do
fi
echo
-n
" '
${
line
##*|
}
'"
echo -n
")"
done
<<<
"
${
bashopts_optprop_enum_values
[
$op
]
}
"
)
"
fi
fi
)
"
echo "
)
"
else
echo ""
fi
done
done
test "
$1
" != "
-e
" || exit
$2
test "
$1
" != "
-e
" || exit
$2
}
}
...
@@ -492,13 +494,14 @@ bashopts_diplay_help_delayed() {
...
@@ -492,13 +494,14 @@ bashopts_diplay_help_delayed() {
# display all otions values and properties
# display all otions values and properties
bashopts_diplay_summary() {
bashopts_diplay_summary() {
local elts desc_max_len=0 val dval
local elts desc_max_len=0 val dval
local value_max_len=
$((
$ncol
/
4
))
declare -A optargs
declare -A optargs
for op in "
${
bashopts_optlist
[@]
}
"; do
for op in "
${
bashopts_optlist
[@]
}
"; do
desc_max_len=
$(
bashopts_math_max
$desc_max_len
${#
bashopts_optprop_description
[
$op
]
}
)
desc_max_len=
$(
bashopts_math_max
$desc_max_len
${#
bashopts_optprop_description
[
$op
]
}
)
done
done
for op in "
${
bashopts_optlist
[@]
}
"; do
for op in "
${
bashopts_optlist
[@]
}
"; do
if ! [[
$op
=~ ^__.*__
$
]]; then
if ! [[
$op
=~ ^__.*__
$
]]; then
printf "
* %-
${
desc_max_len
}
s
:
$(
bashopts_dump_value
$op
)
\n
" "
${
bashopts_optprop_description
[
$op
]
}
"
printf "
* %-
${
desc_max_len
}
.
${
value_max_len
}
s
:
$(
bashopts_dump_value
$op
|
tr
-d
'\n'
)
\n
" "
${
bashopts_optprop_description
[
$op
]
}
"
fi
fi
done
done
}
}
...
...
test.sh
View file @
d7b15340
...
@@ -89,7 +89,7 @@ _test_case_4() {
...
@@ -89,7 +89,7 @@ _test_case_4() {
req_test_eq
"
${
array_value
[1]
}
"
"value 2"
req_test_eq
"
${
array_value
[1]
}
"
"value 2"
req_test_eq
"
${
array_value
[2]
}
"
"value '
\"
'
\$
3"
req_test_eq
"
${
array_value
[2]
}
"
"value '
\"
'
\$
3"
req_test_eq
"
$(
cat
/tmp/bashopts_testrc
)
"
"array_value=([0]=
\"
value1
\"
[1]=
\"
value 2
\"
[2]=
\"
value '
\\\"
'
\\\$
3
\"
)"
req_test_eq
"
$(
cat
/tmp/bashopts_testrc
)
"
"array_value=([0]=
\"
value1
\"
[1]=
\"
value 2
\"
[2]=
\"
value '
\\\"
'
\\\$
3
\"
)"
req_test_eq
"
$(
bashopts_diplay_help |
grep
-E
-o
"^
\\
s+
\-\-
value
\[\"
value1
\"
,
\"
value 2
\"
,
\"
value '
\\\\\"
'
\\\$
3
\"
]
\s
+"
)
"
" --value [
\"
value1
\"
,
\"
value 2
\"
,
\"
value '
\\\"
'
\$
3
\"
]
"
req_test_eq
"
$(
bashopts_diplay_help |
grep
-E
-o
"^
\\
s+
\-\-
value
\[\"
value1
\"
,
\"
value 2
\"
,
\"
value '
\\\\\"
'
\\\$
3
\"
]
\s
+"
)
"
" --value [
\"
value1
\"
,
\"
value 2
\"
,
\"
value '
\\\"
'
\$
3
\"
] "
}
}
_test_case_5
()
{
_test_case_5
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment