mirror of
https://gitlab.com/psuapp/psu.git
synced 2024-08-30 18:12:34 +00:00
Extract actions table transform to transform_actions_table function
This commit is contained in:
parent
566fdfa657
commit
2bc1f20cba
57
psu
57
psu
@ -98,30 +98,9 @@ main() {
|
|||||||
["actions:list"]="actions"
|
["actions:list"]="actions"
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO: move this stuff in a function
|
transform_actions_table
|
||||||
# Set the ACTIONS variable
|
# Decode $ACTIONS_ASSOC associative array
|
||||||
# and the ACTIONS_ASSOC variable
|
eval $ACTIONS_ASSOC_ENCODED
|
||||||
declare -A ACTIONS_ASSOC
|
|
||||||
local action_table
|
|
||||||
local action_name
|
|
||||||
local action_description
|
|
||||||
local required_options
|
|
||||||
local optional_options
|
|
||||||
for action in "${ACTIONS_TABLE[@]}"; do
|
|
||||||
IFS=';' read -ra action_table <<< "$action"
|
|
||||||
action_name="${action_table[0]}"
|
|
||||||
action_description="${action_table[1]}"
|
|
||||||
required_options="${action_table[2]}"
|
|
||||||
optional_options="${action_table[3]}"
|
|
||||||
ACTIONS_ASSOC["$action_name"]="$action_description;$required_options;$optional_options"
|
|
||||||
if [ -n "$action_description" ]; then
|
|
||||||
if [ -n "$ACTIONS" ]; then
|
|
||||||
ACTIONS+=" $action_name"
|
|
||||||
else
|
|
||||||
ACTIONS="$action_name"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
transform_options_table
|
transform_options_table
|
||||||
# Decode $OPTIONS_ASSOC associative array
|
# Decode $OPTIONS_ASSOC associative array
|
||||||
@ -1269,6 +1248,36 @@ lint() {
|
|||||||
fi || true
|
fi || true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Set the ACTIONS variable who's a list of all psu actions
|
||||||
|
# Set the ACTIONS_ASSOC variable who's an associative array of all psu actions
|
||||||
|
transform_actions_table() {
|
||||||
|
declare -A ACTIONS_ASSOC
|
||||||
|
local action_table
|
||||||
|
local action_name
|
||||||
|
local action_description
|
||||||
|
local required_options
|
||||||
|
local optional_options
|
||||||
|
for action in "${ACTIONS_TABLE[@]}"; do
|
||||||
|
IFS=';' read -ra action_table <<< "$action"
|
||||||
|
action_name="${action_table[0]}"
|
||||||
|
action_description="${action_table[1]}"
|
||||||
|
required_options="${action_table[2]}"
|
||||||
|
optional_options="${action_table[3]}"
|
||||||
|
ACTIONS_ASSOC["$action_name"]="$action_description;$required_options;$optional_options"
|
||||||
|
if [ -n "$action_description" ]; then
|
||||||
|
if [ -n "$ACTIONS" ]; then
|
||||||
|
ACTIONS+=" $action_name"
|
||||||
|
else
|
||||||
|
ACTIONS="$action_name"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Bash array variable can't be exported
|
||||||
|
# See: https://stackoverflow.com/questions/5564418/exporting-an-array-in-bash-script
|
||||||
|
ACTIONS_ASSOC_ENCODED=$(declare -p ACTIONS_ASSOC)
|
||||||
|
}
|
||||||
|
|
||||||
# Set the OPTIONS variable who's a list of all psu options
|
# Set the OPTIONS variable who's a list of all psu options
|
||||||
# Set the OPTIONS_ASSOC variable who's an associative array of all psu options
|
# Set the OPTIONS_ASSOC variable who's an associative array of all psu options
|
||||||
transform_options_table() {
|
transform_options_table() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user