package nushell

import (
	
	

	shlex 
	
	
)

func sanitizeName( string) string {
	return strings.ReplaceAll(, "-", "__")
}

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

// SnippetMulti creates a multi-completer nushell completion script.
func ( []string,  string,  string) string {
	return fmt.Sprintf(`%[4]vlet %[1]v_completer = {|place|
    # backwards compatible workaround for positional completer input, see nushell #18791
    let spans = (if ($place | describe) =~ "record" { $place.command } else { $place })
    %[2]v $spans.0 _carapace nushell ...$spans | from json
}

mut current = (($env | default {} config).config | default {} completions)
$current.completions = ($current.completions | default {} external)
$current.completions.external = ($current.completions.external
    | default true enable
    |# backwards compatible workaround for default, see nushell #15654
    | upsert completer { if $in == null { $%[1]v_completer } else { $in } })

$env.config = $current
`, sanitizeName(), shlex.Quote(uid.Executable(), shlex.Nushell), "", )
}

// SnippetSingle creates a single-command nushell completion script.
// When explicitCommand is true, the command name is included in the invocation
// (for multi-completer subcommands) and the full config setup is included.
// When false, only the minimal completer function is generated (standalone mode).
func ( string,  bool) string {

	if  {
		return fmt.Sprintf(`let %[2]v_completer = {|place|
    # backwards compatible workaround for positional completer input, see nushell #18791
    let spans = (if ($place | describe) =~ "record" { $place.command } else { $place })
    %[1]v %[3]v _carapace nushell ...$spans | from json
}

mut current = (($env | default {} config).config | default {} completions)
$current.completions = ($current.completions | default {} external)
$current.completions.external = ($current.completions.external
    | default true enable
    |# backwards compatible workaround for default, see nushell #15654
    | upsert completer { if $in == null { $%[2]v_completer } else { $in } })

$env.config = $current
`, shlex.Quote(uid.Executable(), shlex.Nushell), sanitizeName(), shlex.Quote(, shlex.Nushell))
	}

	return fmt.Sprintf(`let %v_completer = {|place| 
    # backwards compatible workaround for positional completer input, see nushell #18791
    let spans = (if ($place | describe) =~ "record" { $place.command } else { $place })
    %v _carapace nushell ...$spans | from json
}`, sanitizeName(), shlex.Quote(uid.Executable(), shlex.Nushell))
}