refactor!: Renamed nushell-completion command to completion nushell.

This commit is contained in:
2026-07-13 12:24:06 -04:00
parent 997f11b257
commit b0635e035c
5 changed files with 37 additions and 10 deletions
+6
View File
@@ -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
+8 -3
View File
@@ -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(
+2 -2
View File
@@ -77,8 +77,8 @@ main :: proc() {
cmd_scan(&cmd)
case "sync":
cmd_sync(&cmd)
case "nushell-completion":
cmd_nushell_completion(&cmd)
case "completion":
cmd_completion(&cmd)
case:
fmt.wprintf(cmd.err, "Unknown command: %s\n", cmd.name)
write_usage(cmd.out)