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. 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 ## Double-check AI output
+8 -3
View File
@@ -49,6 +49,7 @@ Color_Mode :: enum {
Positional_Arg :: struct { Positional_Arg :: struct {
name: string, name: string,
ntype: string, // nushell type: "path", "string". "" defaults to "path"
completion: string, completion: string,
optional: bool, optional: bool,
} }
@@ -132,10 +133,14 @@ key somewhere, otherwise your data could be lost forever.`,
flags = GLOBAL_FLAGS, flags = GLOBAL_FLAGS,
}, },
{ {
name = "nushell-completion", name = "completion",
usage = "envr nushell-completion", usage = "envr completion <shell>",
short = "Generate custom completions for nushell", short = "Generate shell completion scripts",
long = `Supported shells:
nushell`,
flags = {.Help}, flags = {.Help},
args = {{name = "shell", ntype = "string", completion = "shells"}},
}, },
} }
@@ -28,10 +28,25 @@ def output [] {
['auto' 'table' 'json'] ['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) 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 { generate_nushell_completion :: proc() -> string {
@@ -91,9 +106,10 @@ nushell_positional_line :: proc(arg: Positional_Arg) -> string {
if arg.optional { if arg.optional {
name = fmt.tprintf("%s?", name) name = fmt.tprintf("%s?", name)
} }
ntype := len(arg.ntype) > 0 ? arg.ntype : "path"
if len(arg.completion) > 0 { 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 scan",
"envr sync", "envr sync",
"envr version", "envr version",
"envr nushell-completion", "envr completion",
} }
for ext in expected { for ext in expected {
testing.expect( testing.expect(
+2 -2
View File
@@ -77,8 +77,8 @@ main :: proc() {
cmd_scan(&cmd) cmd_scan(&cmd)
case "sync": case "sync":
cmd_sync(&cmd) cmd_sync(&cmd)
case "nushell-completion": case "completion":
cmd_nushell_completion(&cmd) cmd_completion(&cmd)
case: case:
fmt.wprintf(cmd.err, "Unknown command: %s\n", cmd.name) fmt.wprintf(cmd.err, "Unknown command: %s\n", cmd.name)
write_usage(cmd.out) write_usage(cmd.out)