package multi

import (
	
	
	

	shlex 
	
	
	
	
	
	
	
	
	
	
	
	
)

// Snippet generates a multi-completer shell snippet that registers all
// command completers at once.
func ( string,  []string,  string,  map[string][]string) (string, error) {
	if  == "" {
		 = ps.DetermineShell()
	}

	if !shlex.IsBareWord(, shlex.Format()) {
		log.LOG.Printf("skipped invalid completer name %q", )
		 = ""
	}
	 := make([]string, 0, len())
	for ,  := range  {
		if !shlex.IsBareWord(, shlex.Format()) {
			log.LOG.Printf("skipped invalid completer name %q", )
			continue
		}
		 = append(, )
	}
	 = 

	 := snippetFuncsForShell(, )
	switch  {
	case "bash":
		return bash.SnippetMulti(, , ), nil
	case "bash-ble":
		return bash_ble.SnippetMulti(, , ), nil
	case "zsh":
		return zsh.SnippetMulti(, , ), nil
	case "fish":
		return fish.SnippetMulti(, , ), nil
	case "elvish":
		return elvish.SnippetMulti(, , ), nil
	case "nushell":
		return nushell.SnippetMulti(, , ), nil
	case "powershell":
		return powershell.SnippetMulti(, , ), nil
	case "xonsh":
		return xonsh.SnippetMulti(, , ), nil
	case "oil":
		return oil.SnippetMulti(, , ), nil
	case "tcsh":
		return tcsh.SnippetMulti(, , ), nil
	case "export":
		return "", nil
	case "cmd-clink":
		return "", fmt.Errorf("unsupported shell for multi-completer: '%v'", )
	default:
		 := []string{"bash", "bash-ble", "elvish", "fish", "nushell", "oil", "powershell", "tcsh", "xonsh", "zsh"}
		sort.Strings()
		return "", fmt.Errorf("unsupported shell: '%v' [expected one of '%v']", , strings.Join(, "', '"))
	}
}

// SnippetOrEmpty is like Snippet but returns the snippet string on success
// or the error message on failure (for use in os.Exit flows).
func ( string,  []string,  string,  map[string][]string) string {
	,  := Snippet(, , , )
	if  != nil {
		return .Error()
	}
	return 
}

// SingleSnippet generates a shell snippet that registers completion for
// a single command (e.g. `binary identify _carapace bash`).
func ( string,  string,  []string,  string,  map[string][]string) (string, error) {
	if  == "" {
		 = ps.DetermineShell()
	}
	if !shlex.IsBareWord(, shlex.Format()) {
		log.LOG.Printf("skipped invalid completer name %q", )
		return "", nil
	}
	switch  {
	case "bash":
		return bash.SnippetSingle(, true), nil
	case "bash-ble":
		return bash_ble.SnippetSingle(, true), nil
	case "zsh":
		return zsh.SnippetSingle(, true), nil
	case "fish":
		return fish.SnippetSingle(, true), nil
	case "elvish":
		return elvish.SnippetSingle(, true), nil
	case "nushell":
		return nushell.SnippetSingle(, true), nil
	case "powershell":
		return powershell.SnippetSingle(, true), nil
	case "xonsh":
		return xonsh.SnippetSingle(, true), nil
	case "oil":
		return oil.SnippetSingle(, true), nil
	case "tcsh":
		return tcsh.SnippetSingle(, true), nil
	case "export":
		return "", nil
	case "cmd-clink":
		return "", fmt.Errorf("unsupported shell for multi-completer: '%v'", )
	default:
		 := []string{"bash", "bash-ble", "elvish", "fish", "nushell", "oil", "powershell", "tcsh", "xonsh", "zsh"}
		sort.Strings()
		return "", fmt.Errorf("unsupported shell: '%v' [expected one of '%v']", , strings.Join(, "', '"))
	}
}

// SingleSnippetOrEmpty is like SingleSnippet but returns the snippet string
// on success or the error message on failure.
func ( string,  string,  []string,  string,  map[string][]string) string {
	,  := SingleSnippet(, , , , )
	if  != nil {
		return .Error()
	}
	return 
}

// snippetFuncsForShell joins the snippet funcs for a given shell.
func snippetFuncsForShell( string,  map[string][]string) string {
	if  == nil {
		return ""
	}
	 := []
	if len() == 0 {
		return ""
	}
	return strings.Join(, "\n") + "\n"
}