mirror of
https://github.com/sbrow/envr.git
synced 2026-06-27 18:48:33 -04:00
feat(odin): Added long text and --help flags.
This commit is contained in:
79
cli.odin
79
cli.odin
@@ -11,6 +11,30 @@ Command :: struct {
|
|||||||
bool_set: map[string]bool,
|
bool_set: map[string]bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CommandInfo :: struct {
|
||||||
|
name: string,
|
||||||
|
usage: string,
|
||||||
|
short: string,
|
||||||
|
long: string,
|
||||||
|
}
|
||||||
|
|
||||||
|
COMMANDS := []CommandInfo{
|
||||||
|
{"init", "envr init", "Set up envr",
|
||||||
|
"The init command generates your initial config and saves it to\n~/.envr/config in JSON format.\n\nDuring setup, you will be prompted to select one or more ssh keys with which to\nencrypt your databse. **Make 100% sure** that you have **a remote copy** of this\nkey somewhere, otherwise your data could be lost forever."},
|
||||||
|
{"scan", "envr scan", "Find and select .env files for backup", ""},
|
||||||
|
{"sync", "envr sync", "Update or restore your env backups", ""},
|
||||||
|
{"backup", "envr backup <path>", "Import a .env file into envr", ""},
|
||||||
|
{"add", "envr add <path>", "Import a .env file into envr", ""},
|
||||||
|
{"restore", "envr restore <path>", "Restore a .env file from the database", ""},
|
||||||
|
{"list", "envr list", "View your tracked files", ""},
|
||||||
|
{"remove", "envr remove <path>", "Remove a .env file from your database", ""},
|
||||||
|
{"check", "envr check [path]", "Check if files are backed up", ""},
|
||||||
|
{"deps", "envr deps", "Check for missing binaries",
|
||||||
|
"envr relies on external binaries for certain functionality.\n\nThe check command reports on which binaries are available and which are not."},
|
||||||
|
{"version", "envr version", "Show envr's version", ""},
|
||||||
|
{"edit-config", "envr edit-config", "Edit your config with your default editor", ""},
|
||||||
|
}
|
||||||
|
|
||||||
IMPLEMENTED_COMMANDS := []string{
|
IMPLEMENTED_COMMANDS := []string{
|
||||||
"version",
|
"version",
|
||||||
"deps",
|
"deps",
|
||||||
@@ -27,6 +51,12 @@ parse_args :: proc() -> (cmd: Command, ok: bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
@@ -58,6 +88,11 @@ parse_args :: proc() -> (cmd: Command, ok: bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if has_flag(&cmd, "help") {
|
||||||
|
print_command_help(cmd.name)
|
||||||
|
return Command{}, false
|
||||||
|
}
|
||||||
|
|
||||||
return cmd, true
|
return cmd, true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,9 +114,53 @@ has_flag :: proc(cmd: ^Command, name: string) -> bool {
|
|||||||
return ok2
|
return ok2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
find_command :: proc(name: string) -> (CommandInfo, bool) {
|
||||||
|
for c in COMMANDS {
|
||||||
|
if c.name == name {
|
||||||
|
return c, true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return CommandInfo{}, false
|
||||||
|
}
|
||||||
|
|
||||||
|
print_command_help :: proc(name: string) {
|
||||||
|
info, found := find_command(name)
|
||||||
|
if !found {
|
||||||
|
fmt.printf("Unknown command: %s\n", name)
|
||||||
|
print_usage()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.printf("Usage: %s\n\n%s\n", info.usage, info.short)
|
||||||
|
if len(info.long) > 0 {
|
||||||
|
fmt.printf("\n%s\n", info.long)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
print_usage :: proc() {
|
print_usage :: proc() {
|
||||||
fmt.println("envr - Manage your .env files.")
|
fmt.println("envr - Manage your .env files.")
|
||||||
fmt.println("")
|
fmt.println("")
|
||||||
|
fmt.println("envr keeps your .env synced to a local, age encrypted database.")
|
||||||
|
fmt.println("Is a safe and easy way to gather all your .env files in one place where they can")
|
||||||
|
fmt.println("easily be backed by another tool such as restic or git.")
|
||||||
|
fmt.println("")
|
||||||
|
fmt.println("All your data is stored in ~/data.age")
|
||||||
|
fmt.println("")
|
||||||
|
fmt.println("Getting started is easy:")
|
||||||
|
fmt.println("")
|
||||||
|
fmt.println("1. Create your configuration file and set up encrypted storage:")
|
||||||
|
fmt.println("")
|
||||||
|
fmt.println("> envr init")
|
||||||
|
fmt.println("")
|
||||||
|
fmt.println("2. Scan for existing .env files:")
|
||||||
|
fmt.println("")
|
||||||
|
fmt.println("> envr scan")
|
||||||
|
fmt.println("")
|
||||||
|
fmt.println("Select the files you want to back up from the interactive list.")
|
||||||
|
fmt.println("")
|
||||||
|
fmt.println("3. Verify that it worked:")
|
||||||
|
fmt.println("")
|
||||||
|
fmt.println("> envr list")
|
||||||
|
fmt.println("")
|
||||||
fmt.println("Usage: envr <command> [args]")
|
fmt.println("Usage: envr <command> [args]")
|
||||||
fmt.println("")
|
fmt.println("")
|
||||||
fmt.println("Commands:")
|
fmt.println("Commands:")
|
||||||
|
|||||||
Reference in New Issue
Block a user