-xpns_load_arg_options() {
- # Extract flag options only.
- local _pattern=
- xpns_load_flag_options "$(xpns_extract_matched "$1" "^-${XP_FLAG_OPTIONS}+")" > /dev/null
- if [[ "$1" =~ ^-${XP_FLAG_OPTIONS}*I ]]; then
- # Behavior like this.
- # -IAAA -- XP_REPSTR="AAA"
- # -I AAA BBB -- XP_REPSTR="AAA", XP_ARGS=("BBB")
- # -I"AAA BBB" -- XP_REPSTR="AAA BBB"
- # -IAAA BBB -- XP_REPSTR="AAA", XP_ARGS=("BBB")
- # -I -d ... -- XP_REPSTR=""
- _pattern="^-${XP_FLAG_OPTIONS}*I(.+)"
- if [[ "$1" =~ $_pattern ]]; then
- XP_REPSTR="${BASH_REMATCH[1]}"
- return 0
- elif ! [[ "$2" =~ ^-.* ]]; then
- XP_REPSTR="$2"
- return 0
- else
- xpns_msg_error "invalid argument '$2' for -I option"
- exit ${XP_EINVAL}
- fi
- elif [[ "$1" =~ ^-${XP_FLAG_OPTIONS}*l ]]; then
- _pattern="^-${XP_FLAG_OPTIONS}*l(.+)"
- if [[ "$1" =~ $_pattern ]]; then
- XP_OPT_USE_PRESET_LAYOUT=1
- XP_LAYOUT="$(cat <<<"${BASH_REMATCH[1]}" | xpns_layout_short2long)"
- xpns_is_valid_layout "${XP_LAYOUT}"
- return 0
- elif ! [[ "$2" =~ ^-.* ]]; then
- XP_OPT_USE_PRESET_LAYOUT=1
- XP_LAYOUT="$(cat <<<"$2" | xpns_layout_short2long )"
- xpns_is_valid_layout "${XP_LAYOUT}"
- return 0
- else
- xpns_msg_error "invalid argument '$2' for -l option"
- exit ${XP_EINVAL}
- fi
- elif [[ "$1" =~ ^-${XP_FLAG_OPTIONS}*c ]]; then
- _pattern="^-${XP_FLAG_OPTIONS}*c(.+)"
- if [[ "$1" =~ $_pattern ]]; then
- XP_CMD_UTILITY="${BASH_REMATCH[1]}"
- XP_OPT_CMD_UTILITY=1
- return 0
- elif ! [[ "$2" =~ ^-.* ]]; then
- XP_CMD_UTILITY="$2"
- XP_OPT_CMD_UTILITY=1
- return 0
- else
- xpns_msg_error "invalid argument '$2' for -c option"
- exit ${XP_EINVAL}
- fi
- elif [[ "$1" =~ ^-${XP_FLAG_OPTIONS}*n ]]; then
- _pattern="^-${XP_FLAG_OPTIONS}*n([0-9]+)"
- if [[ "$1" =~ $_pattern ]]; then
- XP_MAX_PANE_ARGS="${BASH_REMATCH[1]}"
- return 0
- elif [[ "$2" =~ ^[0-9]+$ ]]; then
- XP_MAX_PANE_ARGS="$2"
- return 0
- else
- xpns_msg_error "invalid argument '$2' for -n option"
- exit ${XP_EINVAL}
- fi
- elif [[ "$1" =~ ^-${XP_FLAG_OPTIONS}*S ]]; then
- _pattern="^-${XP_FLAG_OPTIONS}*S(.+)"
- if [[ "$1" =~ $_pattern ]]; then
- XP_SOCKET_PATH="${BASH_REMATCH[1]}"
- return 0
- elif ! [[ "$2" =~ ^-.* ]]; then
- XP_SOCKET_PATH="$2"
- return 0
- else
- xpns_msg_error "invalid argument '$2' for -S option"
- exit ${XP_EINVAL}
- fi
- elif [[ "$1" =~ ^-${XP_FLAG_OPTIONS}*C ]]; then
- _pattern="^-${XP_FLAG_OPTIONS}*C([0-9]+)"
- if [[ "$1" =~ $_pattern ]]; then
- XP_OPT_CUSTOM_SIZE_COLS="${BASH_REMATCH[1]}"
- return 0
- elif [[ "$2" =~ ^[0-9]+$ ]];then
- XP_OPT_CUSTOM_SIZE_COLS="$2"
- return 0
- else
- xpns_msg_error "invalid argument '$2' for -C option"
- exit ${XP_EINVAL}
- fi
- elif [[ "$1" =~ ^-${XP_FLAG_OPTIONS}*R ]]; then
- _pattern="^-${XP_FLAG_OPTIONS}*R([0-9]+)"
- if [[ "$1" =~ $_pattern ]]; then
- XP_OPT_CUSTOM_SIZE_ROWS="${BASH_REMATCH[1]}"
- return 0
- elif [[ "$2" =~ ^[0-9]+$ ]];then
- XP_OPT_CUSTOM_SIZE_ROWS="$2"
- return 0
- else
- xpns_msg_error "invalid argument '$2' for -R option"
- exit ${XP_EINVAL}
- fi
- elif [[ "$1" =~ ^-${XP_FLAG_OPTIONS}*B ]]; then
- _pattern="^-${XP_FLAG_OPTIONS}*B(.+)"
- if [[ "$1" =~ $_pattern ]]; then
- XP_BEGIN_ARGS+=("${BASH_REMATCH[1]}")
- return 0
- else
- XP_BEGIN_ARGS+=("$2")
- return 0
- fi