Commit 97dd4ff7 authored by Emeric Verschuur's avatar Emeric Verschuur

Fix spaces in string value

parent ff682117
......@@ -67,7 +67,7 @@ bashopts_parse_args <arguments...>
Code example:
```bash
bashopts_parse_args $@
bashopts_parse_args "$@"
```
### Argument processing
......@@ -113,7 +113,7 @@ bashopts_declare -n age -l number -d "Age" -t number
bashopts_declare -n email_list -t string -m add -l email -d "Email adress"
# Parse arguments
bashopts_parse_args $@
bashopts_parse_args "$@"
# Process argument
bashopts_process_args
......@@ -124,7 +124,7 @@ echo "First name: $first_name"
echo "Last name: $last_name"
echo "Display name: $display_name"
echo "Age: $age"
for email in ${email_list[@]}; do
for email in "${email_list[@]}"; do
echo "Email: $email"
done
```
......@@ -143,13 +143,13 @@ USAGE:
[options and commands] [-- [extra args]]
OPTIONS:
-h,--help Display this help
-n,--non-interactive Non interactive mode - boolean bashopts_non_interactive=true (default:false)
-f,--first First name - string first_name="John" (default:"")
-l,--last Last name - string last_name="Smith" (default:"")
--display-name Display name - string display_name="John Smith" (default:"$first_name $last_name")
--number Age - number age=0 (default:0)
--email Email adress - string email_list="" (default:"")
-h,--help Display this help
-n,--non-interactive true Non interactive mode - [$bashopts_non_interactive] (type:boolean, default:false)
-f,--first "John" First name - [$first_name] (type:string, default:"")
-l,--last "Smith" Last name - [$last_name] (type:string, default:"")
--display-name "John Smith" Display name - [$display_name] (type:string, default:"$first_name $last_name")
--number 0 Age - [$age] (type:number, default:0)
--email [""] Email adress - [$email_list] (type:string, default:"")
```
Test with arguments:
......
......@@ -263,19 +263,21 @@ bashopts_dump_value() {
fi
return 0
fi
set -- "${!op[@]}"
eval set -- \"\${${op}[@]}\"
echo -n "["
if [ "${bashopts_optprop_type[$op]}" == "string" ]; then
echo -n "\"${1//\"/\\\"}\""
else
echo -n "${1}"
fi
while shift; do
shift
while [ -n "$1" ]; do
if [ "${bashopts_optprop_type[$op]}" == "string" ]; then
echo -n ", \"${1//\"/\\\"}\""
else
echo -n ", ${1}"
fi
shift
done
echo -n "]"
}
......@@ -374,7 +376,7 @@ bashopts_parse_args() {
break
;;
-*)
val=$1
val="$1"
shift
op=${bashopts_opt2name[$arg]}
case "${bashopts_optprop_type[$op]}" in
......@@ -400,7 +402,7 @@ bashopts_parse_args() {
esac
;;
*)
error "Fatal error: args"
bashopts_error "Fatal error: args"
;;
esac
done
......
......@@ -17,7 +17,7 @@ bashopts_declare -n age -l number -d "Age" -t number
bashopts_declare -n email_list -t string -m add -l email -d "Email adress"
# Parse arguments
bashopts_parse_args $@
bashopts_parse_args "$@"
# Process argument
bashopts_process_args
......@@ -28,6 +28,6 @@ echo "First name: $first_name"
echo "Last name: $last_name"
echo "Display name: $display_name"
echo "Age: $age"
for email in ${email_list[@]}; do
for email in "${email_list[@]}"; do
echo "Email: $email"
done
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment