diff --git a/TODOS.md b/TODOS.md index ccf64f8..ba11a68 100644 --- a/TODOS.md +++ b/TODOS.md @@ -75,5 +75,3 @@ Note: These todos can wait until all the subcommands have been ported. 27. version --long Odin only prints version; Go also prints commit hash and build date 28. 2 scan tests silently skip Low When fd isn't installed, tests pass without actually testing anything. These should use #assert to be sure that fd is in path. - -29. nushell completions? diff --git a/cli.odin b/cli.odin index d86b265..23f63c0 100644 --- a/cli.odin +++ b/cli.odin @@ -46,6 +46,7 @@ COMMANDS := []CommandInfo { }, {"version", "envr version", "Show envr's version", "", {}}, {"edit-config", "envr edit-config", "Edit your config with your default editor", "", {}}, + {"nushell-completion", "envr nushell-completion", "Generate custom completions for nushell", "", {}}, } parse_args :: proc() -> (cmd: Command, ok: bool) { diff --git a/cmd_nushell_completion.odin b/cmd_nushell_completion.odin new file mode 100644 index 0000000..a3ffcd0 --- /dev/null +++ b/cmd_nushell_completion.odin @@ -0,0 +1,9 @@ +package main + +import "core:fmt" + +COMPLETION_SCRIPT: string : string(#load("mod.nu")) + +cmd_nushell_completion :: proc(cmd: ^Command) { + fmt.print(COMPLETION_SCRIPT) +} diff --git a/cmd_nushell_completion_test.odin b/cmd_nushell_completion_test.odin new file mode 100644 index 0000000..e97830d --- /dev/null +++ b/cmd_nushell_completion_test.odin @@ -0,0 +1,36 @@ +package main + +import "core:fmt" +import "core:strings" +import "core:testing" + +@(test) +test_nushell_completion_nonempty :: proc(t: ^testing.T) { + testing.expect(t, len(COMPLETION_SCRIPT) > 0, "completion script should not be empty") +} + +@(test) +test_nushell_completion_contains_externs :: proc(t: ^testing.T) { + expected := []string{ + "tracked-paths", + "untracked-paths", + "envr backup", + "envr check", + "envr edit-config", + "envr help", + "envr init", + "envr list", + "envr remove", + "envr restore", + "envr scan", + "envr sync", + "envr nushell-completion", + } + for ext in expected { + testing.expect( + t, + strings.contains(COMPLETION_SCRIPT, ext), + fmt.tprintf("expected script to contain %q", ext), + ) + } +} diff --git a/main.odin b/main.odin index 5bc5719..afdfbcb 100644 --- a/main.odin +++ b/main.odin @@ -32,6 +32,8 @@ main :: proc() { cmd_scan(&cmd) case "sync": cmd_sync(&cmd) + case "nushell-completion": + cmd_nushell_completion(&cmd) case: fmt.printf("Unknown command: %s\n", cmd.name) print_usage() diff --git a/mod.nu b/mod.nu new file mode 100644 index 0000000..c16b57f --- /dev/null +++ b/mod.nu @@ -0,0 +1,71 @@ +# envr command extern definitions for Nushell +# A tool for managing environment files and backups + +export def tracked-paths [] { + ( + ^envr list + | from json + | each { + [$in.directory $in.path] | path join + } + ) +} + +export def untracked-paths [] { + ( + ^envr scan + | from json + ) +} + +export extern envr [ + ...args: any + --help(-h) # Show help information +] + +export extern "envr backup" [ + --help(-h) # Show help for backup command + path: path@untracked-paths # Path to .env file to backup +] + +export extern "envr check" [ + --help(-h) # Show help for check command +] + +export extern "envr edit-config" [ + --help(-h) # Show help for edit-config command +] + +export extern "envr help" [ + command?: string # Show help for specific command +] + +export extern "envr init" [ + --help(-h) # Show help for init command +] + +export extern "envr list" [ + --help(-h) # Show help for list command +] + +export extern "envr remove" [ + --help(-h) # Show help for remove command + path: path@tracked-paths +] + +export extern "envr restore" [ + --help(-h) # Show help for restore command + path: path@tracked-paths +] + +export extern "envr scan" [ + --help(-h) # Show help for scan command +] + +export extern "envr sync" [ + --help(-h) # Show help for sync command +] + +export extern "envr nushell-completion" [ + --help(-h) # Show help for nushell-completion command +]