client: src: lib_gen: refactor profile variables

Makes clearer their respective roles.
This commit is contained in:
2024-10-08 18:53:34 -07:00
parent b138a9f3dd
commit d965a11b3e

View File

@@ -295,14 +295,17 @@ function lib_gen::__parse_args()
if [[ ! "$_arg_profile" =~ $global_arg_delim_1 ]]; then if [[ ! "$_arg_profile" =~ $global_arg_delim_1 ]]; then
lib_utils::die_usage "$_usage" lib_utils::die_usage "$_usage"
fi fi
declare -gr global_arg_profile="${_arg_profile%${global_arg_delim_1}*}" local -r _parent="${_arg_profile%${global_arg_delim_1}*}"
declare -gr global_arg_subprofile="${_arg_profile##*${global_arg_delim_1}}" local -r _child="${_arg_profile##*${global_arg_delim_1}}"
[[ -z "$_parent" || -z "$_child" ]] && lib_utils::die_usage "$_usage"
declare -gr global_arg_parent_profile="$_parent"
declare -gr global_arg_child_profile="$_child"
fi fi
# Arg: config # Arg: config
if [ ! -z "$_arg_config" ]; then if [ ! -z "$_arg_config" ]; then
# Requires profile type # Requires profile type
if [ -z "$global_arg_profile" ]; then if [ -z "$global_arg_parent_profile" ]; then
lib_utils::die_usage "$_usage" lib_utils::die_usage "$_usage"
fi fi
read -ra _read <<<"$_arg_config" read -ra _read <<<"$_arg_config"
@@ -317,7 +320,7 @@ function lib_gen::__parse_args()
# Arg: account # Arg: account
if [ ! -z "$_arg_account" ]; then if [ ! -z "$_arg_account" ]; then
# Requires profile type # Requires profile type
if [ -z "$global_arg_profile" ]; then if [ -z "$global_arg_parent_profile" ]; then
lib_utils::die_usage "$_usage" lib_utils::die_usage "$_usage"
fi fi
read -ra _read <<<"$_arg_account" read -ra _read <<<"$_arg_account"
@@ -664,9 +667,9 @@ function lib_gen::__gen_profile()
# Profile # Profile
lib_utils::print_custom " \e[32m│ │ │\e[0m\n" lib_utils::print_custom " \e[32m│ │ │\e[0m\n"
lib_utils::print_custom " \e[32m│ │ ├─\e[34m Enter profile name (e.g., family in 'family/alice'): \e[0m" lib_utils::print_custom " \e[32m│ │ ├─\e[34m Enter profile name (e.g., family in 'family/alice'): \e[0m"
if [ ! -z "$global_arg_profile" ]; then if [ ! -z "$global_arg_parent_profile" ]; then
lib_utils::print_custom "\n" lib_utils::print_custom "\n"
_read="$global_arg_profile" _read="$global_arg_parent_profile"
else else
if [ -z "$global_arg_confirm" ]; then if [ -z "$global_arg_confirm" ]; then
lib_utils::print_custom "\n" lib_utils::print_custom "\n"
@@ -681,9 +684,9 @@ function lib_gen::__gen_profile()
# Subprofile # Subprofile
lib_utils::print_custom " \e[32m│ │ │\e[0m\n" lib_utils::print_custom " \e[32m│ │ │\e[0m\n"
lib_utils::print_custom " \e[32m│ │ ├─\e[34m Enter subprofile name (e.g., alice in 'family/alice'): \e[0m" lib_utils::print_custom " \e[32m│ │ ├─\e[34m Enter subprofile name (e.g., alice in 'family/alice'): \e[0m"
if [ ! -z "$global_arg_subprofile" ]; then if [ ! -z "$global_arg_child_profile" ]; then
lib_utils::print_custom "\n" lib_utils::print_custom "\n"
_read="$global_arg_subprofile" _read="$global_arg_child_profile"
else else
if [ -z "$global_arg_confirm" ]; then if [ -z "$global_arg_confirm" ]; then
lib_utils::print_custom "\n" lib_utils::print_custom "\n"
@@ -800,7 +803,7 @@ function lib_gen::__gen_subprofile_flow()
function lib_gen::__gen_subprofile_flow_args_config() function lib_gen::__gen_subprofile_flow_args_config()
{ {
[ -z "$1" ] && lib_utils::die_fatal [ -z "$1" ] && lib_utils::die_fatal
if [[ -z "${global_arg_type[*]}" || ("${global_arg_type[*]}" =~ flow && -z "$global_arg_profile") || ("${global_arg_type[*]}" =~ flow && ! -z "$global_arg_profile" && -z "${global_arg_account[*]}" && -z "${global_arg_config[*]}") || "${global_arg_config[*]}" =~ $1 ]]; then if [[ -z "${global_arg_type[*]}" || ("${global_arg_type[*]}" =~ flow && -z "$global_arg_parent_profile") || ("${global_arg_type[*]}" =~ flow && ! -z "$global_arg_parent_profile" && -z "${global_arg_account[*]}" && -z "${global_arg_config[*]}") || "${global_arg_config[*]}" =~ $1 ]]; then
return 0 return 0
fi fi
return 1 return 1
@@ -808,7 +811,7 @@ function lib_gen::__gen_subprofile_flow_args_config()
function lib_gen::__gen_subprofile_flow_args_account() function lib_gen::__gen_subprofile_flow_args_account()
{ {
if [[ -z "${global_arg_type[*]}" || ("${global_arg_type[*]}" =~ flow && -z "$global_arg_profile") || ("${global_arg_type[*]}" =~ flow && ! -z "$global_arg_profile" && -z "${global_arg_account[*]}" && -z "${global_arg_config[*]}") || ("${global_arg_type[*]}" =~ flow && ! -z "$global_arg_profile" && ! -z "${global_arg_account[*]}") ]]; then if [[ -z "${global_arg_type[*]}" || ("${global_arg_type[*]}" =~ flow && -z "$global_arg_parent_profile") || ("${global_arg_type[*]}" =~ flow && ! -z "$global_arg_parent_profile" && -z "${global_arg_account[*]}" && -z "${global_arg_config[*]}") || ("${global_arg_type[*]}" =~ flow && ! -z "$global_arg_parent_profile" && ! -z "${global_arg_account[*]}") ]]; then
return 0 return 0
fi fi
return 1 return 1