mirror of
https://github.com/sbrow/envr.git
synced 2026-06-27 10:38:33 -04:00
refactor(odin): ported edit-config command.
This commit is contained in:
1
cli.odin
1
cli.odin
@@ -43,6 +43,7 @@ IMPLEMENTED_COMMANDS := []string{
|
|||||||
"add",
|
"add",
|
||||||
"remove",
|
"remove",
|
||||||
"restore",
|
"restore",
|
||||||
|
"edit-config",
|
||||||
}
|
}
|
||||||
|
|
||||||
parse_args :: proc() -> (cmd: Command, ok: bool) {
|
parse_args :: proc() -> (cmd: Command, ok: bool) {
|
||||||
|
|||||||
49
cmd_edit_config.odin
Normal file
49
cmd_edit_config.odin
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "core:fmt"
|
||||||
|
import "core:os"
|
||||||
|
import "core:path/filepath"
|
||||||
|
import "core:strings"
|
||||||
|
|
||||||
|
cmd_edit_config :: proc(cmd: ^Command) {
|
||||||
|
editor := os.get_env("EDITOR", context.allocator)
|
||||||
|
if len(editor) == 0 {
|
||||||
|
fmt.println("Error: $EDITOR environment variable is not set")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
config_path, join_err := filepath.join([]string{envr_dir(), "config.json"})
|
||||||
|
if join_err != nil {
|
||||||
|
fmt.printf("Error building config path: %v\n", join_err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
_, stat_err := os.stat(config_path, context.allocator)
|
||||||
|
if stat_err != nil {
|
||||||
|
fmt.printf("Config file does not exist at %s. Run 'envr init' first.\n", config_path)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
args := []string{editor, config_path}
|
||||||
|
desc := os.Process_Desc{
|
||||||
|
command = args,
|
||||||
|
stdin = os.stdin,
|
||||||
|
stdout = os.stdout,
|
||||||
|
stderr = os.stderr,
|
||||||
|
}
|
||||||
|
|
||||||
|
p, start_err := os.process_start(desc)
|
||||||
|
if start_err != nil {
|
||||||
|
fmt.printf("Error running editor: %v\n", start_err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
state, wait_err := os.process_wait(p)
|
||||||
|
if wait_err != nil {
|
||||||
|
fmt.printf("Error waiting for editor: %v\n", wait_err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if state.exit_code != 0 {
|
||||||
|
os.exit(int(state.exit_code))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,6 +29,8 @@ main :: proc() {
|
|||||||
cmd_remove(&cmd)
|
cmd_remove(&cmd)
|
||||||
case "restore":
|
case "restore":
|
||||||
cmd_restore(&cmd)
|
cmd_restore(&cmd)
|
||||||
|
case "edit-config":
|
||||||
|
cmd_edit_config(&cmd)
|
||||||
case:
|
case:
|
||||||
fmt.printf("Unknown command: %s\n", cmd.name)
|
fmt.printf("Unknown command: %s\n", cmd.name)
|
||||||
print_usage()
|
print_usage()
|
||||||
|
|||||||
@@ -17,7 +17,3 @@ cmd_sync :: proc(cmd: ^Command) {
|
|||||||
cmd_check :: proc(cmd: ^Command) {
|
cmd_check :: proc(cmd: ^Command) {
|
||||||
fmt.println("TODO: check")
|
fmt.println("TODO: check")
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd_edit_config :: proc(cmd: ^Command) {
|
|
||||||
fmt.println("TODO: edit-config")
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user