diff options
author | sinanmohd <sinan@sinanmohd.com> | 2024-03-13 06:47:19 +0530 |
---|---|---|
committer | sinanmohd <sinan@sinanmohd.com> | 2024-03-15 22:20:15 +0530 |
commit | 3dd390c0cb56ffb5a7c1f94afaed0b80ad12cbe1 (patch) | |
tree | d14983bb19b66f3a8c69e8d9ca8dbea296a80df0 /cmd |
repo: init
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/redq/main.go | 17 | ||||
-rw-r--r-- | cmd/redqctl/main.go | 74 |
2 files changed, 91 insertions, 0 deletions
diff --git a/cmd/redq/main.go b/cmd/redq/main.go new file mode 100644 index 0000000..1f153d3 --- /dev/null +++ b/cmd/redq/main.go @@ -0,0 +1,17 @@ +package main + +import ( + "log" + + redqapi "sinanmohd.com/redq/api" + redqdb "sinanmohd.com/redq/db" +) + +func main() { + db, err := redqdb.NewSafeDB() + if err != nil { + log.Fatal(err) + } + + redqapi.Run(db) +} diff --git a/cmd/redqctl/main.go b/cmd/redqctl/main.go new file mode 100644 index 0000000..f6f9e9e --- /dev/null +++ b/cmd/redqctl/main.go @@ -0,0 +1,74 @@ +package main + +import ( + "flag" + "fmt" + "log" + "os" + + redqdb "sinanmohd.com/redq/db" +) + +func help() { + const helpString string = +`redqctl is a tool for managing redq. + +Usage: + + redqctl <command> [arguments] + +The commands are: + + create create a redq account + help show this help cruft + +` + + fmt.Print(helpString) +} + +func create(args []string, db *redqdb.SafeDB) { + f := flag.NewFlagSet("create", flag.ExitOnError) + ac := &redqdb.Account{} + ac.Info = &redqdb.Login{} + + f.StringVar(&ac.Email, "email", "", + "The email to associate with the account") + f.StringVar(&ac.Info.FirstName, "fname", "", + "The first name to associate with the account") + f.StringVar(&ac.Info.LastName, "lname", "", + "The last name to associate with the account") + f.StringVar(&ac.PassHash, "pass", "", + "The password to associate with the account") + f.UintVar(&ac.Info.Level, "level", 0, + "The level to associate with the account") + f.Parse(args) + + err := ac.CreateAccount(db) + if err != nil { + log.Fatal(err) + } +} + +func main() { + args := os.Args[1:] + if len(args) == 0 { + help() + os.Exit(2) + } + + db, err := redqdb.NewSafeDB() + if err != nil { + log.Fatal(err) + } + + switch args[0] { + case "help": + help() + case "create": + create(args[1:], db) + default: + help() + os.Exit(2) + } +} |