mirror of
https://github.com/sbrow/envr.git
synced 2026-06-27 10:38:33 -04:00
refactor: Got rid of go fallback code.
This commit is contained in:
24
cli.odin
24
cli.odin
@@ -35,21 +35,6 @@ COMMANDS := []CommandInfo{
|
|||||||
{"edit-config", "envr edit-config", "Edit your config with your default editor", ""},
|
{"edit-config", "envr edit-config", "Edit your config with your default editor", ""},
|
||||||
}
|
}
|
||||||
|
|
||||||
IMPLEMENTED_COMMANDS := []string{
|
|
||||||
"init",
|
|
||||||
"version",
|
|
||||||
"deps",
|
|
||||||
"list",
|
|
||||||
"backup",
|
|
||||||
"add",
|
|
||||||
"remove",
|
|
||||||
"restore",
|
|
||||||
"edit-config",
|
|
||||||
"check",
|
|
||||||
"scan",
|
|
||||||
"sync",
|
|
||||||
}
|
|
||||||
|
|
||||||
parse_args :: proc() -> (cmd: Command, ok: bool) {
|
parse_args :: proc() -> (cmd: Command, ok: bool) {
|
||||||
args := os.args
|
args := os.args
|
||||||
if len(args) < 2 {
|
if len(args) < 2 {
|
||||||
@@ -103,15 +88,6 @@ parse_args :: proc() -> (cmd: Command, ok: bool) {
|
|||||||
return cmd, true
|
return cmd, true
|
||||||
}
|
}
|
||||||
|
|
||||||
is_implemented :: proc(name: string) -> bool {
|
|
||||||
for c in IMPLEMENTED_COMMANDS {
|
|
||||||
if c == name {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
has_flag :: proc(cmd: ^Command, name: string) -> bool {
|
has_flag :: proc(cmd: ^Command, name: string) -> bool {
|
||||||
_, ok := cmd.flags[name]
|
_, ok := cmd.flags[name]
|
||||||
if ok {
|
if ok {
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ new_config :: proc(private_key_paths: []string) -> Config {
|
|||||||
|
|
||||||
exclude := make([dynamic]string, 0, 4)
|
exclude := make([dynamic]string, 0, 4)
|
||||||
append(&exclude, "*\\.envrc")
|
append(&exclude, "*\\.envrc")
|
||||||
append(&exclude, "\\.local")
|
append(&exclude, "\\.local/")
|
||||||
append(&exclude, "node_modules")
|
append(&exclude, "node_modules")
|
||||||
append(&exclude, "vendor")
|
append(&exclude, "vendor")
|
||||||
|
|
||||||
@@ -148,7 +148,7 @@ save_config :: proc(cfg: Config, force: bool = false) -> bool {
|
|||||||
|
|
||||||
config_path, _ := filepath.join([]string{config_dir, "config.json"})
|
config_path, _ := filepath.join([]string{config_dir, "config.json"})
|
||||||
|
|
||||||
if !force && os.exists(config_path) {
|
if os.exists(config_path) && !force {
|
||||||
info, stat_err := os.stat(config_path, context.allocator)
|
info, stat_err := os.stat(config_path, context.allocator)
|
||||||
if stat_err == nil {
|
if stat_err == nil {
|
||||||
defer os.file_info_delete(info, context.allocator)
|
defer os.file_info_delete(info, context.allocator)
|
||||||
|
|||||||
34
main.odin
34
main.odin
@@ -3,19 +3,12 @@ package main
|
|||||||
import "core:fmt"
|
import "core:fmt"
|
||||||
import "core:os"
|
import "core:os"
|
||||||
|
|
||||||
GO_BINARY :: "./envr-go"
|
|
||||||
|
|
||||||
main :: proc() {
|
main :: proc() {
|
||||||
cmd, ok := parse_args()
|
cmd, ok := parse_args()
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !is_implemented(cmd.name) {
|
|
||||||
fallback_to_go()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
switch cmd.name {
|
switch cmd.name {
|
||||||
case "init":
|
case "init":
|
||||||
cmd_init(&cmd)
|
cmd_init(&cmd)
|
||||||
@@ -46,31 +39,4 @@ main :: proc() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fallback_to_go :: proc() {
|
|
||||||
args := make([dynamic]string)
|
|
||||||
append(&args, "./envr-go")
|
|
||||||
for i in 1..<len(os.args) {
|
|
||||||
append(&args, os.args[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
desc := os.Process_Desc{
|
|
||||||
command = args[:],
|
|
||||||
stdin = os.stdin,
|
|
||||||
stdout = os.stdout,
|
|
||||||
stderr = os.stderr,
|
|
||||||
}
|
|
||||||
|
|
||||||
p, err1 := os.process_start(desc)
|
|
||||||
if err1 != nil {
|
|
||||||
fmt.printf("Error: failed to run envr-go: %v\n", err1)
|
|
||||||
os.exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
state, err2 := os.process_wait(p)
|
|
||||||
if err2 != nil {
|
|
||||||
fmt.printf("Error waiting for envr-go: %v\n", err2)
|
|
||||||
os.exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
os.exit(int(state.exit_code))
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
package main
|
|
||||||
Reference in New Issue
Block a user