# bash completion for sttr                                 -*- shell-script -*-

__sttr_debug()
{
    if [[ -n ${BASH_COMP_DEBUG_FILE:-} ]]; then
        echo "$*" >> "${BASH_COMP_DEBUG_FILE}"
    fi
}

# Homebrew on Macs have version 1.3 of bash-completion which doesn't include
# _init_completion. This is a very minimal version of that function.
__sttr_init_completion()
{
    COMPREPLY=()
    _get_comp_words_by_ref "$@" cur prev words cword
}

__sttr_index_of_word()
{
    local w word=$1
    shift
    index=0
    for w in "$@"; do
        [[ $w = "$word" ]] && return
        index=$((index+1))
    done
    index=-1
}

__sttr_contains_word()
{
    local w word=$1; shift
    for w in "$@"; do
        [[ $w = "$word" ]] && return
    done
    return 1
}

__sttr_handle_go_custom_completion()
{
    __sttr_debug "${FUNCNAME[0]}: cur is ${cur}, words[*] is ${words[*]}, #words[@] is ${#words[@]}"

    local shellCompDirectiveError=1
    local shellCompDirectiveNoSpace=2
    local shellCompDirectiveNoFileComp=4
    local shellCompDirectiveFilterFileExt=8
    local shellCompDirectiveFilterDirs=16

    local out requestComp lastParam lastChar comp directive args

    # Prepare the command to request completions for the program.
    # Calling ${words[0]} instead of directly sttr allows handling aliases
    args=("${words[@]:1}")
    # Disable ActiveHelp which is not supported for bash completion v1
    requestComp="STTR_ACTIVE_HELP=0 ${words[0]} __completeNoDesc ${args[*]}"

    lastParam=${words[$((${#words[@]}-1))]}
    lastChar=${lastParam:$((${#lastParam}-1)):1}
    __sttr_debug "${FUNCNAME[0]}: lastParam ${lastParam}, lastChar ${lastChar}"

    if [ -z "${cur}" ] && [ "${lastChar}" != "=" ]; then
        # If the last parameter is complete (there is a space following it)
        # We add an extra empty parameter so we can indicate this to the go method.
        __sttr_debug "${FUNCNAME[0]}: Adding extra empty parameter"
        requestComp="${requestComp} \"\""
    fi

    __sttr_debug "${FUNCNAME[0]}: calling ${requestComp}"
    # Use eval to handle any environment variables and such
    out=$(eval "${requestComp}" 2>/dev/null)

    # Extract the directive integer at the very end of the output following a colon (:)
    directive=${out##*:}
    # Remove the directive
    out=${out%:*}
    if [ "${directive}" = "${out}" ]; then
        # There is not directive specified
        directive=0
    fi
    __sttr_debug "${FUNCNAME[0]}: the completion directive is: ${directive}"
    __sttr_debug "${FUNCNAME[0]}: the completions are: ${out}"

    if [ $((directive & shellCompDirectiveError)) -ne 0 ]; then
        # Error code.  No completion.
        __sttr_debug "${FUNCNAME[0]}: received error from custom completion go code"
        return
    else
        if [ $((directive & shellCompDirectiveNoSpace)) -ne 0 ]; then
            if [[ $(type -t compopt) = "builtin" ]]; then
                __sttr_debug "${FUNCNAME[0]}: activating no space"
                compopt -o nospace
            fi
        fi
        if [ $((directive & shellCompDirectiveNoFileComp)) -ne 0 ]; then
            if [[ $(type -t compopt) = "builtin" ]]; then
                __sttr_debug "${FUNCNAME[0]}: activating no file completion"
                compopt +o default
            fi
        fi
    fi

    if [ $((directive & shellCompDirectiveFilterFileExt)) -ne 0 ]; then
        # File extension filtering
        local fullFilter filter filteringCmd
        # Do not use quotes around the $out variable or else newline
        # characters will be kept.
        for filter in ${out}; do
            fullFilter+="$filter|"
        done

        filteringCmd="_filedir $fullFilter"
        __sttr_debug "File filtering command: $filteringCmd"
        $filteringCmd
    elif [ $((directive & shellCompDirectiveFilterDirs)) -ne 0 ]; then
        # File completion for directories only
        local subdir
        # Use printf to strip any trailing newline
        subdir=$(printf "%s" "${out}")
        if [ -n "$subdir" ]; then
            __sttr_debug "Listing directories in $subdir"
            __sttr_handle_subdirs_in_dir_flag "$subdir"
        else
            __sttr_debug "Listing directories in ."
            _filedir -d
        fi
    else
        while IFS='' read -r comp; do
            COMPREPLY+=("$comp")
        done < <(compgen -W "${out}" -- "$cur")
    fi
}

__sttr_handle_reply()
{
    __sttr_debug "${FUNCNAME[0]}"
    local comp
    case $cur in
        -*)
            if [[ $(type -t compopt) = "builtin" ]]; then
                compopt -o nospace
            fi
            local allflags
            if [ ${#must_have_one_flag[@]} -ne 0 ]; then
                allflags=("${must_have_one_flag[@]}")
            else
                allflags=("${flags[*]} ${two_word_flags[*]}")
            fi
            while IFS='' read -r comp; do
                COMPREPLY+=("$comp")
            done < <(compgen -W "${allflags[*]}" -- "$cur")
            if [[ $(type -t compopt) = "builtin" ]]; then
                [[ "${COMPREPLY[0]}" == *= ]] || compopt +o nospace
            fi

            # complete after --flag=abc
            if [[ $cur == *=* ]]; then
                if [[ $(type -t compopt) = "builtin" ]]; then
                    compopt +o nospace
                fi

                local index flag
                flag="${cur%=*}"
                __sttr_index_of_word "${flag}" "${flags_with_completion[@]}"
                COMPREPLY=()
                if [[ ${index} -ge 0 ]]; then
                    PREFIX=""
                    cur="${cur#*=}"
                    ${flags_completion[${index}]}
                    if [ -n "${ZSH_VERSION:-}" ]; then
                        # zsh completion needs --flag= prefix
                        eval "COMPREPLY=( \"\${COMPREPLY[@]/#/${flag}=}\" )"
                    fi
                fi
            fi

            if [[ -z "${flag_parsing_disabled}" ]]; then
                # If flag parsing is enabled, we have completed the flags and can return.
                # If flag parsing is disabled, we may not know all (or any) of the flags, so we fallthrough
                # to possibly call handle_go_custom_completion.
                return 0;
            fi
            ;;
    esac

    # check if we are handling a flag with special work handling
    local index
    __sttr_index_of_word "${prev}" "${flags_with_completion[@]}"
    if [[ ${index} -ge 0 ]]; then
        ${flags_completion[${index}]}
        return
    fi

    # we are parsing a flag and don't have a special handler, no completion
    if [[ ${cur} != "${words[cword]}" ]]; then
        return
    fi

    local completions
    completions=("${commands[@]}")
    if [[ ${#must_have_one_noun[@]} -ne 0 ]]; then
        completions+=("${must_have_one_noun[@]}")
    elif [[ -n "${has_completion_function}" ]]; then
        # if a go completion function is provided, defer to that function
        __sttr_handle_go_custom_completion
    fi
    if [[ ${#must_have_one_flag[@]} -ne 0 ]]; then
        completions+=("${must_have_one_flag[@]}")
    fi
    while IFS='' read -r comp; do
        COMPREPLY+=("$comp")
    done < <(compgen -W "${completions[*]}" -- "$cur")

    if [[ ${#COMPREPLY[@]} -eq 0 && ${#noun_aliases[@]} -gt 0 && ${#must_have_one_noun[@]} -ne 0 ]]; then
        while IFS='' read -r comp; do
            COMPREPLY+=("$comp")
        done < <(compgen -W "${noun_aliases[*]}" -- "$cur")
    fi

    if [[ ${#COMPREPLY[@]} -eq 0 ]]; then
        if declare -F __sttr_custom_func >/dev/null; then
            # try command name qualified custom func
            __sttr_custom_func
        else
            # otherwise fall back to unqualified for compatibility
            declare -F __custom_func >/dev/null && __custom_func
        fi
    fi

    # available in bash-completion >= 2, not always present on macOS
    if declare -F __ltrim_colon_completions >/dev/null; then
        __ltrim_colon_completions "$cur"
    fi

    # If there is only 1 completion and it is a flag with an = it will be completed
    # but we don't want a space after the =
    if [[ "${#COMPREPLY[@]}" -eq "1" ]] && [[ $(type -t compopt) = "builtin" ]] && [[ "${COMPREPLY[0]}" == --*= ]]; then
       compopt -o nospace
    fi
}

# The arguments should be in the form "ext1|ext2|extn"
__sttr_handle_filename_extension_flag()
{
    local ext="$1"
    _filedir "@(${ext})"
}

__sttr_handle_subdirs_in_dir_flag()
{
    local dir="$1"
    pushd "${dir}" >/dev/null 2>&1 && _filedir -d && popd >/dev/null 2>&1 || return
}

__sttr_handle_flag()
{
    __sttr_debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}"

    # if a command required a flag, and we found it, unset must_have_one_flag()
    local flagname=${words[c]}
    local flagvalue=""
    # if the word contained an =
    if [[ ${words[c]} == *"="* ]]; then
        flagvalue=${flagname#*=} # take in as flagvalue after the =
        flagname=${flagname%=*} # strip everything after the =
        flagname="${flagname}=" # but put the = back
    fi
    __sttr_debug "${FUNCNAME[0]}: looking for ${flagname}"
    if __sttr_contains_word "${flagname}" "${must_have_one_flag[@]}"; then
        must_have_one_flag=()
    fi

    # if you set a flag which only applies to this command, don't show subcommands
    if __sttr_contains_word "${flagname}" "${local_nonpersistent_flags[@]}"; then
      commands=()
    fi

    # keep flag value with flagname as flaghash
    # flaghash variable is an associative array which is only supported in bash > 3.
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        if [ -n "${flagvalue}" ] ; then
            flaghash[${flagname}]=${flagvalue}
        elif [ -n "${words[ $((c+1)) ]}" ] ; then
            flaghash[${flagname}]=${words[ $((c+1)) ]}
        else
            flaghash[${flagname}]="true" # pad "true" for bool flag
        fi
    fi

    # skip the argument to a two word flag
    if [[ ${words[c]} != *"="* ]] && __sttr_contains_word "${words[c]}" "${two_word_flags[@]}"; then
        __sttr_debug "${FUNCNAME[0]}: found a flag ${words[c]}, skip the next argument"
        c=$((c+1))
        # if we are looking for a flags value, don't show commands
        if [[ $c -eq $cword ]]; then
            commands=()
        fi
    fi

    c=$((c+1))

}

__sttr_handle_noun()
{
    __sttr_debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}"

    if __sttr_contains_word "${words[c]}" "${must_have_one_noun[@]}"; then
        must_have_one_noun=()
    elif __sttr_contains_word "${words[c]}" "${noun_aliases[@]}"; then
        must_have_one_noun=()
    fi

    nouns+=("${words[c]}")
    c=$((c+1))
}

__sttr_handle_command()
{
    __sttr_debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}"

    local next_command
    if [[ -n ${last_command} ]]; then
        next_command="_${last_command}_${words[c]//:/__}"
    else
        if [[ $c -eq 0 ]]; then
            next_command="_sttr_root_command"
        else
            next_command="_${words[c]//:/__}"
        fi
    fi
    c=$((c+1))
    __sttr_debug "${FUNCNAME[0]}: looking for ${next_command}"
    declare -F "$next_command" >/dev/null && $next_command
}

__sttr_handle_word()
{
    if [[ $c -ge $cword ]]; then
        __sttr_handle_reply
        return
    fi
    __sttr_debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}"
    if [[ "${words[c]}" == -* ]]; then
        __sttr_handle_flag
    elif __sttr_contains_word "${words[c]}" "${commands[@]}"; then
        __sttr_handle_command
    elif [[ $c -eq 0 ]]; then
        __sttr_handle_command
    elif __sttr_contains_word "${words[c]}" "${command_aliases[@]}"; then
        # aliashash variable is an associative array which is only supported in bash > 3.
        if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
            words[c]=${aliashash[${words[c]}]}
            __sttr_handle_command
        else
            __sttr_handle_noun
        fi
    else
        __sttr_handle_noun
    fi
    __sttr_handle_word
}

_sttr_adler32()
{
    last_command="sttr_adler32"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_ascii85-decode()
{
    last_command="sttr_ascii85-decode"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_ascii85-encode()
{
    last_command="sttr_ascii85-encode"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_base32-decode()
{
    last_command="sttr_base32-decode"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_base32-encode()
{
    last_command="sttr_base32-encode"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_base58-decode()
{
    last_command="sttr_base58-decode"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()

    flags+=("--check")
    flags+=("-c")
    local_nonpersistent_flags+=("--check")
    local_nonpersistent_flags+=("-c")

    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_base58-encode()
{
    last_command="sttr_base58-encode"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()

    flags+=("--check")
    flags+=("-c")
    local_nonpersistent_flags+=("--check")
    local_nonpersistent_flags+=("-c")

    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_base62-decode()
{
    last_command="sttr_base62-decode"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_base62-encode()
{
    last_command="sttr_base62-encode"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()

    flags+=("--prefix=")
    two_word_flags+=("--prefix")
    two_word_flags+=("-p")
    local_nonpersistent_flags+=("--prefix")
    local_nonpersistent_flags+=("--prefix=")
    local_nonpersistent_flags+=("-p")

    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_base64-decode()
{
    last_command="sttr_base64-decode"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()

    flags+=("--raw")
    flags+=("-r")
    local_nonpersistent_flags+=("--raw")
    local_nonpersistent_flags+=("-r")

    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_base64-encode()
{
    last_command="sttr_base64-encode"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()

    flags+=("--raw")
    flags+=("-r")
    local_nonpersistent_flags+=("--raw")
    local_nonpersistent_flags+=("-r")

    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_base64url-decode()
{
    last_command="sttr_base64url-decode"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()

    flags+=("--raw")
    flags+=("-r")
    local_nonpersistent_flags+=("--raw")
    local_nonpersistent_flags+=("-r")

    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_base64url-encode()
{
    last_command="sttr_base64url-encode"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()

    flags+=("--raw")
    flags+=("-r")
    local_nonpersistent_flags+=("--raw")
    local_nonpersistent_flags+=("-r")

    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_bcrypt()
{
    last_command="sttr_bcrypt"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()

    flags+=("--number-of-rounds=")
    two_word_flags+=("--number-of-rounds")
    two_word_flags+=("-r")
    local_nonpersistent_flags+=("--number-of-rounds")
    local_nonpersistent_flags+=("--number-of-rounds=")
    local_nonpersistent_flags+=("-r")

    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_blake2b()
{
    last_command="sttr_blake2b"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()

    flags+=("--size=")
    two_word_flags+=("--size")
    two_word_flags+=("-s")
    local_nonpersistent_flags+=("--size")
    local_nonpersistent_flags+=("--size=")
    local_nonpersistent_flags+=("-s")

    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_blake2s()
{
    last_command="sttr_blake2s"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_camel()
{
    last_command="sttr_camel"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_completion()
{
    last_command="sttr_completion"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()

    flags+=("--help")
    flags+=("-h")
    local_nonpersistent_flags+=("--help")
    local_nonpersistent_flags+=("-h")

    must_have_one_flag=()
    must_have_one_noun=()
    must_have_one_noun+=("bash")
    must_have_one_noun+=("fish")
    must_have_one_noun+=("powershell")
    must_have_one_noun+=("zsh")
    noun_aliases=()
}

_sttr_count-chars()
{
    last_command="sttr_count-chars"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_count-lines()
{
    last_command="sttr_count-lines"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_count-words()
{
    last_command="sttr_count-words"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_crc32()
{
    last_command="sttr_crc32"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()

    flags+=("--polynomial=")
    two_word_flags+=("--polynomial")
    two_word_flags+=("-p")
    local_nonpersistent_flags+=("--polynomial")
    local_nonpersistent_flags+=("--polynomial=")
    local_nonpersistent_flags+=("-p")

    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_crockford-base32-decode()
{
    last_command="sttr_crockford-base32-decode"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()

    flags+=("--verify")
    flags+=("-v")
    local_nonpersistent_flags+=("--verify")
    local_nonpersistent_flags+=("-v")

    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_crockford-base32-encode()
{
    last_command="sttr_crockford-base32-encode"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()

    flags+=("--checksum")
    flags+=("-c")
    local_nonpersistent_flags+=("--checksum")
    local_nonpersistent_flags+=("-c")

    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_escape-quotes()
{
    last_command="sttr_escape-quotes"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()

    flags+=("--double-quote")
    flags+=("-d")
    local_nonpersistent_flags+=("--double-quote")
    local_nonpersistent_flags+=("-d")
    flags+=("--single-quote")
    flags+=("-s")
    local_nonpersistent_flags+=("--single-quote")
    local_nonpersistent_flags+=("-s")

    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_extract-emails()
{
    last_command="sttr_extract-emails"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()

    flags+=("--separator=")
    two_word_flags+=("--separator")
    two_word_flags+=("-s")
    local_nonpersistent_flags+=("--separator")
    local_nonpersistent_flags+=("--separator=")
    local_nonpersistent_flags+=("-s")

    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_extract-ip()
{
    last_command="sttr_extract-ip"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_extract-url()
{
    last_command="sttr_extract-url"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_help()
{
    last_command="sttr_help"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    has_completion_function=1
    noun_aliases=()
}

_sttr_hex-decode()
{
    last_command="sttr_hex-decode"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_hex-encode()
{
    last_command="sttr_hex-encode"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_hex-rgb()
{
    last_command="sttr_hex-rgb"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_html-decode()
{
    last_command="sttr_html-decode"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_html-encode()
{
    last_command="sttr_html-encode"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_interactive()
{
    last_command="sttr_interactive"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_json()
{
    last_command="sttr_json"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()

    flags+=("--indent")
    flags+=("-i")
    local_nonpersistent_flags+=("--indent")
    local_nonpersistent_flags+=("-i")

    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_json-escape()
{
    last_command="sttr_json-escape"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_json-msgpack()
{
    last_command="sttr_json-msgpack"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_json-unescape()
{
    last_command="sttr_json-unescape"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()

    flags+=("--indent")
    flags+=("-i")
    local_nonpersistent_flags+=("--indent")
    local_nonpersistent_flags+=("-i")

    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_json-yaml()
{
    last_command="sttr_json-yaml"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_kebab()
{
    last_command="sttr_kebab"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_lower()
{
    last_command="sttr_lower"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_markdown-html()
{
    last_command="sttr_markdown-html"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_md5()
{
    last_command="sttr_md5"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_morse-decode()
{
    last_command="sttr_morse-decode"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()

    flags+=("--lang=")
    two_word_flags+=("--lang")
    two_word_flags+=("-l")
    local_nonpersistent_flags+=("--lang")
    local_nonpersistent_flags+=("--lang=")
    local_nonpersistent_flags+=("-l")

    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_morse-encode()
{
    last_command="sttr_morse-encode"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_msgpack-json()
{
    last_command="sttr_msgpack-json"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_number-lines()
{
    last_command="sttr_number-lines"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_pascal()
{
    last_command="sttr_pascal"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_qr()
{
    last_command="sttr_qr"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()

    flags+=("--full")
    flags+=("-f")
    local_nonpersistent_flags+=("--full")
    local_nonpersistent_flags+=("-f")
    flags+=("--level=")
    two_word_flags+=("--level")
    two_word_flags+=("-l")
    local_nonpersistent_flags+=("--level")
    local_nonpersistent_flags+=("--level=")
    local_nonpersistent_flags+=("-l")
    flags+=("--size=")
    two_word_flags+=("--size")
    two_word_flags+=("-s")
    local_nonpersistent_flags+=("--size")
    local_nonpersistent_flags+=("--size=")
    local_nonpersistent_flags+=("-s")

    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_remove-newlines()
{
    last_command="sttr_remove-newlines"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()

    flags+=("--separator=")
    two_word_flags+=("--separator")
    two_word_flags+=("-s")
    local_nonpersistent_flags+=("--separator")
    local_nonpersistent_flags+=("--separator=")
    local_nonpersistent_flags+=("-s")

    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_remove-spaces()
{
    last_command="sttr_remove-spaces"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()

    flags+=("--separator=")
    two_word_flags+=("--separator")
    two_word_flags+=("-s")
    local_nonpersistent_flags+=("--separator")
    local_nonpersistent_flags+=("--separator=")
    local_nonpersistent_flags+=("-s")

    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_reverse()
{
    last_command="sttr_reverse"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_reverse-lines()
{
    last_command="sttr_reverse-lines"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_rot13()
{
    last_command="sttr_rot13"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_sha1()
{
    last_command="sttr_sha1"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_sha224()
{
    last_command="sttr_sha224"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_sha256()
{
    last_command="sttr_sha256"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_sha384()
{
    last_command="sttr_sha384"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_sha512()
{
    last_command="sttr_sha512"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_shuffle-lines()
{
    last_command="sttr_shuffle-lines"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_slug()
{
    last_command="sttr_slug"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_snake()
{
    last_command="sttr_snake"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_sort-lines()
{
    last_command="sttr_sort-lines"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_title()
{
    last_command="sttr_title"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_unique-lines()
{
    last_command="sttr_unique-lines"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_upper()
{
    last_command="sttr_upper"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_url-decode()
{
    last_command="sttr_url-decode"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_url-encode()
{
    last_command="sttr_url-encode"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_version()
{
    last_command="sttr_version"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_xxh-128()
{
    last_command="sttr_xxh-128"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_xxh-32()
{
    last_command="sttr_xxh-32"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_xxh-64()
{
    last_command="sttr_xxh-64"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_yaml-json()
{
    last_command="sttr_yaml-json"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()

    flags+=("--indent")
    flags+=("-i")
    local_nonpersistent_flags+=("--indent")
    local_nonpersistent_flags+=("-i")

    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_zeropad()
{
    last_command="sttr_zeropad"

    command_aliases=()

    commands=()

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()

    flags+=("--number-of-zeros=")
    two_word_flags+=("--number-of-zeros")
    two_word_flags+=("-n")
    local_nonpersistent_flags+=("--number-of-zeros")
    local_nonpersistent_flags+=("--number-of-zeros=")
    local_nonpersistent_flags+=("-n")
    flags+=("--prefix=")
    two_word_flags+=("--prefix")
    two_word_flags+=("-p")
    local_nonpersistent_flags+=("--prefix")
    local_nonpersistent_flags+=("--prefix=")
    local_nonpersistent_flags+=("-p")

    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

_sttr_root_command()
{
    last_command="sttr"

    command_aliases=()

    commands=()
    commands+=("adler32")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("adler32-checksum")
        aliashash["adler32-checksum"]="adler32"
        command_aliases+=("adler32-sum")
        aliashash["adler32-sum"]="adler32"
    fi
    commands+=("ascii85-decode")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("ascii85-decoding")
        aliashash["ascii85-decoding"]="ascii85-decode"
        command_aliases+=("b85-decode")
        aliashash["b85-decode"]="ascii85-decode"
        command_aliases+=("base85-decode")
        aliashash["base85-decode"]="ascii85-decode"
    fi
    commands+=("ascii85-encode")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("ascii85-encoding")
        aliashash["ascii85-encoding"]="ascii85-encode"
        command_aliases+=("b85-encode")
        aliashash["b85-encode"]="ascii85-encode"
        command_aliases+=("base85-encode")
        aliashash["base85-encode"]="ascii85-encode"
    fi
    commands+=("base32-decode")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("b32-dec")
        aliashash["b32-dec"]="base32-decode"
        command_aliases+=("b32-decode")
        aliashash["b32-decode"]="base32-decode"
    fi
    commands+=("base32-encode")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("b32-enc")
        aliashash["b32-enc"]="base32-encode"
        command_aliases+=("b32-encode")
        aliashash["b32-encode"]="base32-encode"
    fi
    commands+=("base58-decode")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("b58-dec")
        aliashash["b58-dec"]="base58-decode"
        command_aliases+=("b58-decode")
        aliashash["b58-decode"]="base58-decode"
    fi
    commands+=("base58-encode")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("b58-enc")
        aliashash["b58-enc"]="base58-encode"
        command_aliases+=("b58-encode")
        aliashash["b58-encode"]="base58-encode"
    fi
    commands+=("base62-decode")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("b62-dec")
        aliashash["b62-dec"]="base62-decode"
        command_aliases+=("b62-decode")
        aliashash["b62-decode"]="base62-decode"
    fi
    commands+=("base62-encode")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("b62-enc")
        aliashash["b62-enc"]="base62-encode"
        command_aliases+=("b62-encode")
        aliashash["b62-encode"]="base62-encode"
    fi
    commands+=("base64-decode")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("b64-dec")
        aliashash["b64-dec"]="base64-decode"
        command_aliases+=("b64-decode")
        aliashash["b64-decode"]="base64-decode"
    fi
    commands+=("base64-encode")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("b64-enc")
        aliashash["b64-enc"]="base64-encode"
        command_aliases+=("b64-encode")
        aliashash["b64-encode"]="base64-encode"
    fi
    commands+=("base64url-decode")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("b64url-dec")
        aliashash["b64url-dec"]="base64url-decode"
        command_aliases+=("b64url-decode")
        aliashash["b64url-decode"]="base64url-decode"
    fi
    commands+=("base64url-encode")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("b64url-enc")
        aliashash["b64url-enc"]="base64url-encode"
        command_aliases+=("b64url-encode")
        aliashash["b64url-encode"]="base64url-encode"
    fi
    commands+=("bcrypt")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("bcrypt-hash")
        aliashash["bcrypt-hash"]="bcrypt"
    fi
    commands+=("blake2b")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("blake2b-hash")
        aliashash["blake2b-hash"]="blake2b"
        command_aliases+=("blake2b-sum")
        aliashash["blake2b-sum"]="blake2b"
    fi
    commands+=("blake2s")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("blake2s-hash")
        aliashash["blake2s-hash"]="blake2s"
        command_aliases+=("blake2s-sum")
        aliashash["blake2s-sum"]="blake2s"
    fi
    commands+=("camel")
    commands+=("completion")
    commands+=("count-chars")
    commands+=("count-lines")
    commands+=("count-words")
    commands+=("crc32")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("crc32-checksum")
        aliashash["crc32-checksum"]="crc32"
        command_aliases+=("crc32-sum")
        aliashash["crc32-sum"]="crc32"
    fi
    commands+=("crockford-base32-decode")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("cb32-decode")
        aliashash["cb32-decode"]="crockford-base32-decode"
        command_aliases+=("crockford-b32-dec")
        aliashash["crockford-b32-dec"]="crockford-base32-decode"
    fi
    commands+=("crockford-base32-encode")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("cb32-encode")
        aliashash["cb32-encode"]="crockford-base32-encode"
        command_aliases+=("crockford-b32-enc")
        aliashash["crockford-b32-enc"]="crockford-base32-encode"
    fi
    commands+=("escape-quotes")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("esc-quotes")
        aliashash["esc-quotes"]="escape-quotes"
        command_aliases+=("escape-quotes")
        aliashash["escape-quotes"]="escape-quotes"
    fi
    commands+=("extract-emails")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("extract-email")
        aliashash["extract-email"]="extract-emails"
        command_aliases+=("find-email")
        aliashash["find-email"]="extract-emails"
        command_aliases+=("find-emails")
        aliashash["find-emails"]="extract-emails"
    fi
    commands+=("extract-ip")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("extract-ips")
        aliashash["extract-ips"]="extract-ip"
        command_aliases+=("find-ip")
        aliashash["find-ip"]="extract-ip"
        command_aliases+=("find-ips")
        aliashash["find-ips"]="extract-ip"
    fi
    commands+=("extract-url")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("ext-url")
        aliashash["ext-url"]="extract-url"
        command_aliases+=("extract-urls")
        aliashash["extract-urls"]="extract-url"
        command_aliases+=("url-ext")
        aliashash["url-ext"]="extract-url"
    fi
    commands+=("help")
    commands+=("hex-decode")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("hex-dec")
        aliashash["hex-dec"]="hex-decode"
        command_aliases+=("hexadecimal-decode")
        aliashash["hexadecimal-decode"]="hex-decode"
    fi
    commands+=("hex-encode")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("hex-enc")
        aliashash["hex-enc"]="hex-encode"
        command_aliases+=("hexadecimal-encode")
        aliashash["hexadecimal-encode"]="hex-encode"
    fi
    commands+=("hex-rgb")
    commands+=("html-decode")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("html-dec")
        aliashash["html-dec"]="html-decode"
        command_aliases+=("html-unescape")
        aliashash["html-unescape"]="html-decode"
    fi
    commands+=("html-encode")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("html-enc")
        aliashash["html-enc"]="html-encode"
        command_aliases+=("html-escape")
        aliashash["html-escape"]="html-encode"
    fi
    commands+=("interactive")
    commands+=("json")
    commands+=("json-escape")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("json-esc")
        aliashash["json-esc"]="json-escape"
    fi
    commands+=("json-msgpack")
    commands+=("json-unescape")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("json-unesc")
        aliashash["json-unesc"]="json-unescape"
    fi
    commands+=("json-yaml")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("json-yml")
        aliashash["json-yml"]="json-yaml"
    fi
    commands+=("kebab")
    commands+=("lower")
    commands+=("markdown-html")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("md-html")
        aliashash["md-html"]="markdown-html"
    fi
    commands+=("md5")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("md5-sum")
        aliashash["md5-sum"]="md5"
    fi
    commands+=("morse-decode")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("morse-code-dec")
        aliashash["morse-code-dec"]="morse-decode"
        command_aliases+=("morse-code-decode")
        aliashash["morse-code-decode"]="morse-decode"
        command_aliases+=("morse-dec")
        aliashash["morse-dec"]="morse-decode"
        command_aliases+=("morse-decode")
        aliashash["morse-decode"]="morse-decode"
    fi
    commands+=("morse-encode")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("morse-code-enc")
        aliashash["morse-code-enc"]="morse-encode"
        command_aliases+=("morse-code-encode")
        aliashash["morse-code-encode"]="morse-encode"
        command_aliases+=("morse-enc")
        aliashash["morse-enc"]="morse-encode"
        command_aliases+=("morse-encode")
        aliashash["morse-encode"]="morse-encode"
    fi
    commands+=("msgpack-json")
    commands+=("number-lines")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("line-number")
        aliashash["line-number"]="number-lines"
        command_aliases+=("line-numbers")
        aliashash["line-numbers"]="number-lines"
        command_aliases+=("nl")
        aliashash["nl"]="number-lines"
        command_aliases+=("number-line")
        aliashash["number-line"]="number-lines"
        command_aliases+=("numberline")
        aliashash["numberline"]="number-lines"
        command_aliases+=("numberlines")
        aliashash["numberlines"]="number-lines"
    fi
    commands+=("pascal")
    commands+=("qr")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("qr-code")
        aliashash["qr-code"]="qr"
        command_aliases+=("qrcode")
        aliashash["qrcode"]="qr"
    fi
    commands+=("remove-newlines")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("remove-new-lines")
        aliashash["remove-new-lines"]="remove-newlines"
        command_aliases+=("trim-new-lines")
        aliashash["trim-new-lines"]="remove-newlines"
        command_aliases+=("trim-newlines")
        aliashash["trim-newlines"]="remove-newlines"
    fi
    commands+=("remove-spaces")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("remove-space")
        aliashash["remove-space"]="remove-spaces"
        command_aliases+=("trim-space")
        aliashash["trim-space"]="remove-spaces"
        command_aliases+=("trim-spaces")
        aliashash["trim-spaces"]="remove-spaces"
    fi
    commands+=("reverse")
    commands+=("reverse-lines")
    commands+=("rot13")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("rot13-enc")
        aliashash["rot13-enc"]="rot13"
        command_aliases+=("rot13-encode")
        aliashash["rot13-encode"]="rot13"
    fi
    commands+=("sha1")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("sha1-sum")
        aliashash["sha1-sum"]="sha1"
    fi
    commands+=("sha224")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("sha224-sum")
        aliashash["sha224-sum"]="sha224"
    fi
    commands+=("sha256")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("sha256-sum")
        aliashash["sha256-sum"]="sha256"
    fi
    commands+=("sha384")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("sha384-sum")
        aliashash["sha384-sum"]="sha384"
    fi
    commands+=("sha512")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("sha512-sum")
        aliashash["sha512-sum"]="sha512"
    fi
    commands+=("shuffle-lines")
    commands+=("slug")
    commands+=("snake")
    commands+=("sort-lines")
    commands+=("title")
    commands+=("unique-lines")
    commands+=("upper")
    commands+=("url-decode")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("url-dec")
        aliashash["url-dec"]="url-decode"
    fi
    commands+=("url-encode")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("url-enc")
        aliashash["url-enc"]="url-encode"
    fi
    commands+=("version")
    commands+=("xxh-128")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("xxh128")
        aliashash["xxh128"]="xxh-128"
        command_aliases+=("xxhash-128")
        aliashash["xxhash-128"]="xxh-128"
        command_aliases+=("xxhash128")
        aliashash["xxhash128"]="xxh-128"
    fi
    commands+=("xxh-32")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("xxh32")
        aliashash["xxh32"]="xxh-32"
        command_aliases+=("xxhash-32")
        aliashash["xxhash-32"]="xxh-32"
        command_aliases+=("xxhash32")
        aliashash["xxhash32"]="xxh-32"
    fi
    commands+=("xxh-64")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("xxh64")
        aliashash["xxh64"]="xxh-64"
        command_aliases+=("xxhash-64")
        aliashash["xxhash-64"]="xxh-64"
        command_aliases+=("xxhash64")
        aliashash["xxhash64"]="xxh-64"
    fi
    commands+=("yaml-json")
    if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
        command_aliases+=("yml-json")
        aliashash["yml-json"]="yaml-json"
    fi
    commands+=("zeropad")

    flags=()
    two_word_flags=()
    local_nonpersistent_flags=()
    flags_with_completion=()
    flags_completion=()


    must_have_one_flag=()
    must_have_one_noun=()
    noun_aliases=()
}

__start_sttr()
{
    local cur prev words cword split
    declare -A flaghash 2>/dev/null || :
    declare -A aliashash 2>/dev/null || :
    if declare -F _init_completion >/dev/null 2>&1; then
        _init_completion -s || return
    else
        __sttr_init_completion -n "=" || return
    fi

    local c=0
    local flag_parsing_disabled=
    local flags=()
    local two_word_flags=()
    local local_nonpersistent_flags=()
    local flags_with_completion=()
    local flags_completion=()
    local commands=("sttr")
    local command_aliases=()
    local must_have_one_flag=()
    local must_have_one_noun=()
    local has_completion_function=""
    local last_command=""
    local nouns=()
    local noun_aliases=()

    __sttr_handle_word
}

if [[ $(type -t compopt) = "builtin" ]]; then
    complete -o default -F __start_sttr sttr
else
    complete -o default -o nospace -F __start_sttr sttr
fi

# ex: ts=4 sw=4 et filetype=sh
