Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mbedsys
bashopts
Commits
432c576d
Commit
432c576d
authored
Apr 07, 2017
by
Emeric Verschuur
Browse files
Fix default value check for the add method
parent
38268010
Pipeline
#55
passed with stage
in 21 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
bashopts.sh
View file @
432c576d
...
...
@@ -271,13 +271,13 @@ bashopts_declare() {
if
!
[[
-v
options[check]
]]
;
then
options[check]
=
"bashopts_check_
${
options
[type]
}
"
fi
# Check the default value format
options[default]
=
"
$(
${
options
[check]
}
"
${
options
[default]
}
"
)
"
||
exit
1
# format the option method
case
"
${
options
[method]
}
"
in
''
|
s|set
)
# default: simple value - override
options[method]
=
"set"
# Check the default value format
options[default]
=
"
$(
${
options
[check]
}
"
${
options
[default]
}
"
)
"
||
exit
1
;;
a|add
)
# array value - add
...
...
@@ -401,15 +401,16 @@ bashopts_diplay_help() {
# display additional information the each properties
# discarding special options like --help
if [[ -v bashopts_optprop_expression[
$op
] ]]; then
dval="
\
"
${
bashopts_optprop_expression
[
$op
]//\
"/
\\\"
}
\"
"
fi
if [
"
${
bashopts_optprop_type
[
$op
]
}
"
==
"string"
]; then
dval=
${
dval
:-
"
\"
${
bashopts_optprop_default
[
$op
]//\
"/
\\\"
}
\"
"
}
elts="
- [\
$$op
] (type
:
${
bashopts_optprop_type
[
$op
]
}
, default
:
\
"
${
bashopts_optprop_expression
[
$op
]//\
"/
\\\"
}
\"
)"
elif [[ -v bashopts_optprop_default[
$op
] ]]; then
if [
"
${
bashopts_optprop_type
[
$op
]
}
"
==
"string"
]; then
elts=
"- [
\$
$op
] (type:
${
bashopts_optprop_type
[
$op
]
}
, default:
\"
${
bashopts_optprop_default
[
$op
]//\
"/
\\\"
}
\"
)"
else
elts=
"- [
\$
$op
] (type:
${
bashopts_optprop_type
[
$op
]
}
, default:
${
bashopts_optprop_default
[
$op
]
}
)"
fi
else
dval=
${
dval
:-
${
bashopts_optprop_
default
[
$op
]
}
}
elts=
"- [
\$
$op
] (type:
${
bashopts_optprop_
type
[
$op
]
}
)"
fi
# add type and default value info
elts="
- [\
$$op
] (type
:
${
bashopts_optprop_type
[
$op
]
}
, default
:
$dval
)
"
fi
# display arguments, value if available, description, and additional info if available
printf
" %-
${
optargs_max_len
}
s %s
\n
"
"
${
optargs
[
$op
]
}
"
"
${
bashopts_optprop_description
[
$op
]
}
$elts
"
...
...
test.sh
View file @
432c576d
...
...
@@ -339,6 +339,15 @@ _test_case_22() {
bashopts_process_option
-n
value
-k
is_eq_to_null
-r
}
_test_case_23
()
{
bashopts_setup
-n
"
$0
"
-d
"Test case
$0
"
bashopts_declare
-n
value
-l
value
-m
add
-d
"A str value"
-t
string
-k
is_eq_to_null
bashopts_parse_args
bashopts_process_opts
}
_test
()
{
bashopts_setup
-n
"
$0
"
-d
"Test case
$0
"
...
...
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