Fix command line interface
alex wennerberg alex@alexwennerberg.com
Mon, 09 Nov 2020 17:50:26 -0800
M
README.md
→
README.md
@@ -10,7 +10,7 @@ `go build`
To run locally, you can use the example-config.toml to start a test server. Easy! -`./flounder serve` +`./flounder -c example-config.toml serve` ## Deploying@@ -25,10 +25,10 @@
## Admin -To make yourself an admin, create a user through the web browser, then run `./flounder make-admin [your user]` -- this gives you access to admin tools to manage users. +To make yourself an admin, create a user through the web browser, then run `./flounder -c [config_path] make-admin [your user]` -- this gives you access to admin tools to manage users. Backup your users' data regularly! The admin deletion commands are irreversible. -Flounder comes with an admin panel acessible to users with the admin db flag set. +Flounder comes with an admin panel accessible to users with the admin db flag set. You can also manage users directly through the sqlite database.
M
admin.go
→
admin.go
@@ -7,6 +7,7 @@
// Run some scripts to setup your instance import ( + "flag" "fmt" "io/ioutil" "log"@@ -17,22 +18,23 @@ )
// TODO improve cli func runAdminCommand() { - if len(os.Args) < 4 { - fmt.Println("expected subcommand with parameter") + args := flag.Args() // again? + if len(args) < 3 { + fmt.Println("Expected subcommand with parameter activate-user|delete-user|make-admin") os.Exit(1) } - switch os.Args[2] { + switch args[0] { case "activate-user": - username := os.Args[3] + username := args[1] err := activateUser(username) log.Fatal(err) case "delete-user": - username := os.Args[3] + username := args[1] // TODO add confirmation err := deleteUser(username) log.Fatal(err) case "make-admin": - username := os.Args[3] + username := args[1] err := makeAdmin(username) log.Fatal(err) }
M
main.go
→
main.go
@@ -178,11 +178,12 @@ }
func main() { configPath := flag.String("c", "flounder.toml", "path to config file") // doesnt work atm - if len(os.Args) < 2 { + flag.Parse() + args := flag.Args() + if len(args) < 1 { fmt.Println("expected 'admin' or 'serve' subcommand") os.Exit(1) } - flag.Parse() var err error c, err = getConfig(*configPath)@@ -196,10 +197,12 @@ }
mw := io.MultiWriter(os.Stdout, logFile) log.SetOutput(mw) - _, err1 := os.Stat(c.TLSCertFile) - _, err2 := os.Stat(c.TLSKeyFile) - if os.IsNotExist(err1) || os.IsNotExist(err2) { - log.Println("Keyfile or certfile does not exist.") + if c.HttpsEnabled { + _, err1 := os.Stat(c.TLSCertFile) + _, err2 := os.Stat(c.TLSKeyFile) + if os.IsNotExist(err1) || os.IsNotExist(err2) { + log.Fatal("Keyfile or certfile does not exist.") + } } // Generate session cookie key if does not exist@@ -212,7 +215,7 @@ createTablesIfDNE()
cookie := generateCookieKeyIfDNE() SessionStore = sessions.NewCookieStore(cookie) - switch os.Args[1] { + switch args[0] { case "serve": wg := new(sync.WaitGroup) wg.Add(2)