From b0635e035c44fb20f9b02265cff1ed8db30aa9d0 Mon Sep 17 00:00:00 2001 From: Spencer Brower Date: Mon, 13 Jul 2026 12:24:06 -0400 Subject: [PATCH] refactor!: Renamed `nushell-completion` command to `completion nushell`. --- TODOS.md | 6 +++++ cli.odin | 11 ++++++--- ...ell_completion.odin => cmd_completion.odin | 24 +++++++++++++++---- ...tion_test.odin => cmd_completion_test.odin | 2 +- main.odin | 4 ++-- 5 files changed, 37 insertions(+), 10 deletions(-) rename cmd_nushell_completion.odin => cmd_completion.odin (77%) rename cmd_nushell_completion_test.odin => cmd_completion_test.odin (98%) diff --git a/TODOS.md b/TODOS.md index 6e69d2d..11ef98a 100644 --- a/TODOS.md +++ b/TODOS.md @@ -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 diff --git a/cli.odin b/cli.odin index 399dcb7..04cba59 100644 --- a/cli.odin +++ b/cli.odin @@ -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 ", + short = "Generate shell completion scripts", + long = `Supported shells: + + nushell`, flags = {.Help}, + args = {{name = "shell", ntype = "string", completion = "shells"}}, }, } diff --git a/cmd_nushell_completion.odin b/cmd_completion.odin similarity index 77% rename from cmd_nushell_completion.odin rename to cmd_completion.odin index 39c4400..20f38e7 100644 --- a/cmd_nushell_completion.odin +++ b/cmd_completion.odin @@ -28,10 +28,25 @@ def output [] { ['auto' 'table' 'json'] } +def shells [] { + ['nushell'] +} + ` -cmd_nushell_completion :: proc(cmd: ^Command) { - fmt.wprint(cmd.out, generate_nushell_completion(), flush = true) +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) } diff --git a/cmd_nushell_completion_test.odin b/cmd_completion_test.odin similarity index 98% rename from cmd_nushell_completion_test.odin rename to cmd_completion_test.odin index 258a5fb..984b9d0 100644 --- a/cmd_nushell_completion_test.odin +++ b/cmd_completion_test.odin @@ -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( diff --git a/main.odin b/main.odin index 0192c89..f2fdd2e 100644 --- a/main.odin +++ b/main.odin @@ -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)