#!/bin/bash

_help_command_description="Check for stage3 updates and sync the portage container"

# ARG_OPTIONAL_BOOLEAN([no-sync],[n],[Do not sync portage container, just check for stage3 updates])
# ARG_HELP([])
# ARGBASH_WRAP([opt-global])
# ARGBASH_SET_INDENT([    ])
# ARGBASH_GO()
# needed because of Argbash --> m4_ignore([
### START OF CODE GENERATED BY Argbash v2.3.0 one line above ###
# Argbash is a bash code generator used to get arguments parsing right.
# Argbash is FREE SOFTWARE, see https://argbash.io for more info

# THE DEFAULTS INITIALIZATION - OPTIONALS
_arg_no_sync=off
_arg_working_dir=
_arg_debug=off

print_help ()
{
    printf 'Usage: %s update [--no-sync] [-w|--working-dir <arg>] [--debug]\n' "${_KUBLER_BIN}"
    printf "\t%s\n" "-n,--no-sync: Do not sync portage container, just check for stage3 updates"
    printf "\t%s\n" "-h,--help: Prints help"
    printf "\t%s\n" "-w,--working-dir: Where to look for namespaces or images, default: current directory"
}

# THE PARSING ITSELF
while test $# -gt 0
do
    _key="$1"
    case "$_key" in
        -n*|--no-no-sync|--no-sync)
            _arg_no_sync="on"
            _next="${_key##-n}"
            test -n "$_next" && test "$_next" != "$_key" && shift && set -- "-n" "-${_next}" "$@"
            test "${1:0:5}" = "--no-" && _arg_no_sync="off"
            ;;
        -h*|--help)
            print_help
            exit 0
            ;;
        -w*|--working-dir|--working-dir=*)
            _val="${_key##--working-dir=}"
            _val2="${_key##-w}"
            if test "$_val" = "$_key"
            then
                test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
                _val="$2"
                shift
            elif test "$_val2" != "$_key" -a -n "$_val2"
            then
                _val="$_val2"
            fi
            _arg_working_dir="$_val"
            _args_opt_global_opt+=("${_key%%=*}" "$_arg_working_dir")
            ;;
        --no-debug|--debug)
            _arg_debug="on"
            _args_opt_global_opt+=("${_key%%=*}")
            test "${1:0:5}" = "--no-" && _arg_debug="off"
            ;;
        *)
            _PRINT_HELP=yes die "FATAL ERROR: Got an unexpected argument '$1'" 1
            ;;
    esac
    shift
done

# OTHER STUFF GENERATED BY Argbash
_args_opt_global=("${_args_opt_global_opt[@]}" "${_args_opt_global_pos[@]}")

### END OF CODE GENERATED BY Argbash (sortof) ### ])
