package xonshimport (shlex)// Snippet creates the xonsh completion script.func ( *cobra.Command) string {returnSnippetSingle(.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))) }returnfmt.Sprintf(`%[5]vfrom xonsh.completers.completer import add_one_completerfrom xonsh.completers.tools import contextual_command_completer@contextual_command_completerdef _%[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 resultadd_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)) }returnfmt.Sprintf(`from xonsh.completers.completer import add_one_completerfrom xonsh.completers.tools import contextual_command_completer@contextual_command_completerdef _%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 resultadd_one_completer('%v', _%v_completer, 'start')`, , , shlex.Escape(, shlex.Xonsh), , , )}
The pages are generated with Goldsv0.8.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.