mirror of
https://github.com/sbrow/envr.git
synced 2026-06-27 10:38:33 -04:00
refactor(odin): Migrated nushell-completion command to go.
This commit is contained in:
2
TODOS.md
2
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?
|
||||
|
||||
1
cli.odin
1
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) {
|
||||
|
||||
9
cmd_nushell_completion.odin
Normal file
9
cmd_nushell_completion.odin
Normal file
@@ -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)
|
||||
}
|
||||
36
cmd_nushell_completion_test.odin
Normal file
36
cmd_nushell_completion_test.odin
Normal file
@@ -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),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
|
||||
71
mod.nu
Normal file
71
mod.nu
Normal file
@@ -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
|
||||
]
|
||||
Reference in New Issue
Block a user