mirror of
https://github.com/sbrow/envr.git
synced 2026-06-27 10:38:33 -04:00
refactor: Fixed cli command.
This commit is contained in:
15
cli.odin
15
cli.odin
@@ -46,23 +46,24 @@ COMMANDS := []CommandInfo {
|
|||||||
},
|
},
|
||||||
{"version", "envr version", "Show envr's version", "", {}},
|
{"version", "envr version", "Show envr's version", "", {}},
|
||||||
{"edit-config", "envr edit-config", "Edit your config with your default editor", "", {}},
|
{"edit-config", "envr edit-config", "Edit your config with your default editor", "", {}},
|
||||||
{"nushell-completion", "envr nushell-completion", "Generate custom completions for nushell", "", {}},
|
{
|
||||||
|
"nushell-completion",
|
||||||
|
"envr nushell-completion",
|
||||||
|
"Generate custom completions for nushell",
|
||||||
|
"",
|
||||||
|
{},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
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 || args[1] == "--help" || args[1] == "-h" {
|
||||||
print_usage()
|
print_usage()
|
||||||
return Command{}, false
|
return Command{}, false
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.name = args[1]
|
cmd.name = args[1]
|
||||||
|
|
||||||
if cmd.name == "--help" || cmd.name == "-h" {
|
|
||||||
print_usage()
|
|
||||||
return Command{}, false
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd.args = make([dynamic]string)
|
cmd.args = make([dynamic]string)
|
||||||
cmd.flags = make(map[string]string)
|
cmd.flags = make(map[string]string)
|
||||||
cmd.bool_set = make(map[string]bool)
|
cmd.bool_set = make(map[string]bool)
|
||||||
|
|||||||
@@ -17,18 +17,22 @@ cmd_backup :: proc(cmd: ^Command) {
|
|||||||
|
|
||||||
file, ok := new_env_file(path)
|
file, ok := new_env_file(path)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
// TODO: log a message
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
db, db_ok := db_open()
|
db, db_ok := db_open()
|
||||||
if !db_ok {
|
if !db_ok {
|
||||||
|
// TODO: log a message
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer db_close(&db)
|
defer db_close(&db)
|
||||||
|
|
||||||
if !db_insert(&db, file) {
|
if !db_insert(&db, file) {
|
||||||
|
// TODO: log a message
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.printf("Saved %s into the database\n", path)
|
fmt.printf("Saved %s into the database\n", path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user