mirror of
https://github.com/sbrow/envr.git
synced 2026-08-26 09:53:32 -04:00
refactor!: Renamed nushell-completion command to completion nushell.
This commit is contained in:
@@ -14,6 +14,12 @@
|
||||
|
||||
7. Add tests for untested commands.
|
||||
|
||||
8. Add uninstall command.
|
||||
|
||||
9. Add purge command?
|
||||
|
||||
10. Ensure updates to db don't break hardlinks.
|
||||
|
||||
|
||||
## Double-check AI output
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ Color_Mode :: enum {
|
||||
|
||||
Positional_Arg :: struct {
|
||||
name: string,
|
||||
ntype: string, // nushell type: "path", "string". "" defaults to "path"
|
||||
completion: string,
|
||||
optional: bool,
|
||||
}
|
||||
@@ -132,10 +133,14 @@ key somewhere, otherwise your data could be lost forever.`,
|
||||
flags = GLOBAL_FLAGS,
|
||||
},
|
||||
{
|
||||
name = "nushell-completion",
|
||||
usage = "envr nushell-completion",
|
||||
short = "Generate custom completions for nushell",
|
||||
name = "completion",
|
||||
usage = "envr completion <shell>",
|
||||
short = "Generate shell completion scripts",
|
||||
long = `Supported shells:
|
||||
|
||||
nushell`,
|
||||
flags = {.Help},
|
||||
args = {{name = "shell", ntype = "string", completion = "shells"}},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -28,10 +28,25 @@ def output [] {
|
||||
['auto' 'table' 'json']
|
||||
}
|
||||
|
||||
def shells [] {
|
||||
['nushell']
|
||||
}
|
||||
|
||||
`
|
||||
|
||||
cmd_nushell_completion :: proc(cmd: ^Command) {
|
||||
cmd_completion :: proc(cmd: ^Command) {
|
||||
if len(cmd.args) == 0 {
|
||||
print_command_help(cmd)
|
||||
return
|
||||
}
|
||||
|
||||
switch cmd.args[0] {
|
||||
case "nushell":
|
||||
fmt.wprint(cmd.out, generate_nushell_completion(), flush = true)
|
||||
case:
|
||||
fmt.wprintf(cmd.err, "Unsupported shell: %s\n", cmd.args[0])
|
||||
fmt.wprintln(cmd.err, "Supported shells: nushell")
|
||||
}
|
||||
}
|
||||
|
||||
generate_nushell_completion :: proc() -> string {
|
||||
@@ -91,9 +106,10 @@ nushell_positional_line :: proc(arg: Positional_Arg) -> string {
|
||||
if arg.optional {
|
||||
name = fmt.tprintf("%s?", name)
|
||||
}
|
||||
ntype := len(arg.ntype) > 0 ? arg.ntype : "path"
|
||||
if len(arg.completion) > 0 {
|
||||
return fmt.tprintf("%s: path@%s", name, arg.completion)
|
||||
return fmt.tprintf("%s: %s@%s", name, ntype, arg.completion)
|
||||
}
|
||||
return fmt.tprintf("%s: path", name)
|
||||
return fmt.tprintf("%s: %s", name, ntype)
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ test_nushell_completion_contains_commands :: proc(t: ^testing.T) {
|
||||
"envr scan",
|
||||
"envr sync",
|
||||
"envr version",
|
||||
"envr nushell-completion",
|
||||
"envr completion",
|
||||
}
|
||||
for ext in expected {
|
||||
testing.expect(
|
||||
Reference in New Issue
Block a user