package bash_ble

import (
	
	
	

	shlex 
	
	

	
)

// Snippet creates the bash-ble completion script.
func ( *cobra.Command) string {
	return SnippetSingle(.Name(), false)
}

// SnippetMulti creates a multi-completer bash-ble completion script.
func ( []string,  string,  string) string {
	 := bash.SnippetMulti(, , )
	 = regexp.MustCompile(`complete -o noquote -F [^\n]+`).ReplaceAllString(, "")

	 := strings.Join(quoteAll(), " ")

	return fmt.Sprintf(`%v
_%[2]v_completer_ble() {
  if [[ ${BLE_ATTACHED-} ]]; then
    [[ :$comp_type: == *:auto:* ]] && return

    compopt -o ble/no-default
    bleopt complete_menu_style=desc

    local command="${COMP_WORDS[0]}"
    local compline="${COMP_LINE:0:${COMP_POINT}}"
    local IFS=$'\n'
    local c
    mapfile -t c < <(echo "$compline" | sed -e "s/ \$/ ''/" -e 's/"/\"/g' | xargs %[3]v "${command}" _carapace bash-ble)
    [[ "${c[*]}" == "" ]] && c=() # fix for mapfile creating a non-empty array from empty command output

    local cand
    for cand in "${c[@]}"; do
      [ ! -z "$cand" ] && ble/complete/cand/yield mandb "${cand%%$'\t'*}" "${cand##*$'\t'}"
    done
  else
    complete -F _%[2]v_completer %[4]v
  fi
}

complete -F _%[2]v_completer_ble %[4]v
`, , , shlex.Quote(uid.Executable(), shlex.Bash), )
}

// SnippetSingle creates a single-command bash-ble completion script.
// When explicitCommand is true, the command name is included in the invocation
// (for multi-completer subcommands). When false, the executable is invoked
// without an explicit command (standalone mode).
func ( string,  bool) string {

	 := bash.SnippetSingle(, )
	if  {
		 = regexp.MustCompile(`complete -o noquote -F [^\n]+`).ReplaceAllString(, "")
	} else {
		 = regexp.MustCompile(`complete -F [^\n]+`).ReplaceAllString(, "")
	}

	 := fmt.Sprintf("%v _carapace bash-ble", shlex.Quote(uid.Executable(), shlex.Bash))
	if  {
		 = fmt.Sprintf("%v %v _carapace bash-ble", shlex.Quote(uid.Executable(), shlex.Bash), shlex.Quote(, shlex.Bash))
	}

	return fmt.Sprintf(`%v
_%[2]v_completion_ble() {
  if [[ ${BLE_ATTACHED-} ]]; then
    [[ :$comp_type: == *:auto:* ]] && return

    compopt -o ble/no-default
    bleopt complete_menu_style=desc

    local compline="${COMP_LINE:0:${COMP_POINT}}"
    local IFS=$'\n'
    local c
    mapfile -t c < <(echo "$compline" | sed -e "s/ \$/ ''/" -e 's/"/\"/g' | xargs %[3]v)
    [[ "${c[*]}" == "" ]] && c=() # fix for mapfile creating a non-empty array from empty command output

    local cand
    for cand in "${c[@]}"; do
      [ ! -z "$cand" ] && ble/complete/cand/yield mandb "${cand%%$'\t'*}" "${cand##*$'\t'}"
    done
  else
    complete -F _%[2]v_completion %[2]v
  fi
}

complete -F _%[2]v_completion_ble %[2]v
`, , , , shlex.Quote(, shlex.Bash))
}

func quoteAll( []string) []string {
	 := make([]string, len())
	for ,  := range  {
		[] = shlex.Quote(, shlex.Bash)
	}
	return 
}