package xonsh

import (
	
	

	shlex 
	
	
)

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

// SnippetMulti creates a multi-completer xonsh completion script.
func ( []string,  string,  string) string {
	 := make([]string, 0, len())
	for ,  := range  {
		 = append(, fmt.Sprintf("'%v'", shlex.Escape(, shlex.Xonsh)))
	}
	return fmt.Sprintf(`%[5]vfrom xonsh.completers.completer import add_one_completer
from xonsh.completers.tools import contextual_command_completer

@contextual_command_completer
def _%[1]v_completer(context):
    """carapace multi-completer"""
    if context.command not in [%[3]v]:
        return

    from json import loads
    from xonsh.completers.tools import sub_proc_get_output, RichCompletion

    def fix_prefix(s):
        """quick fix for partially quoted prefix completion ('prefix',<TAB>)"""
        return s.translate(str.maketrans('', '', '\'"'))

    output, _ = sub_proc_get_output(
        '%[2]v', context.command, '_carapace', 'xonsh', *[a.value for a in context.args], fix_prefix(context.prefix)
    )

    try:
        result = {RichCompletion(c["Value"], display=c["Display"], description=c["Description"], prefix_len=len(context.raw_prefix), append_closing_quote=False, style=c["Style"]) for c in loads(output)}
    except:
        result = {}
    if len(result) == 0:
        raise StopIteration
    return result

add_one_completer('%[1]v', _%[1]v_completer, 'start')
`, strings.ReplaceAll(, "-", "__"), shlex.Escape(uid.Executable(), shlex.Xonsh), strings.Join(, ", "), "", )
}

// SnippetSingle creates a single-command xonsh 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 {

	 := strings.ReplaceAll(, "-", "__")

	 := fmt.Sprintf("'%v', '_carapace', 'xonsh'", shlex.Escape(uid.Executable(), shlex.Xonsh))
	if  {
		 = fmt.Sprintf("'%v', '%v', '_carapace', 'xonsh'", shlex.Escape(uid.Executable(), shlex.Xonsh), shlex.Escape(, shlex.Xonsh))
	}

	return fmt.Sprintf(`from xonsh.completers.completer import add_one_completer
from xonsh.completers.tools import contextual_command_completer

@contextual_command_completer
def _%v_completer(context):
    """carapace completer for %v"""
    if context.completing_command('%v'):
        from json import loads
        from xonsh.completers.tools import sub_proc_get_output, RichCompletion
    
        def fix_prefix(s):
            """quick fix for partially quoted prefix completion ('prefix',<TAB>)"""
            return s.translate(str.maketrans('', '', '\'"'))

        output, _ = sub_proc_get_output(
            %v, *[a.value for a in context.args], fix_prefix(context.prefix)
        )

        try:
            result = {RichCompletion(c["Value"], display=c["Display"], description=c["Description"], prefix_len=len(context.raw_prefix), append_closing_quote=False, style=c["Style"]) for c in loads(output)}
        except:
            result = {}
        if len(result) == 0:
            raise StopIteration
        return result

add_one_completer('%v', _%v_completer, 'start')
`, , , shlex.Escape(, shlex.Xonsh), , , )
}