flounder

A simple gemini site builder
Log | Files | Refs | README | LICENSE

commit 9c65105f28892d9a74734bb8d8d8b3fbbbe7846e
parent 609d53702630916ee1b04f69e19fb67ca820bdbc
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Mon,  9 Nov 2020 17:50:26 -0800

Fix command line interface

Diffstat:
MREADME.md | 6+++---
Madmin.go | 14++++++++------
Mmain.go | 17++++++++++-------
3 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/README.md b/README.md @@ -10,7 +10,7 @@ Requires go 1.15 and sqlite3 development libraries. 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 @@ This will determine how you set the values in flounder.toml ## 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. diff --git a/admin.go b/admin.go @@ -7,6 +7,7 @@ package main // Run some scripts to setup your instance import ( + "flag" "fmt" "io/ioutil" "log" @@ -17,22 +18,23 @@ import ( // 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) } diff --git a/main.go b/main.go @@ -178,11 +178,12 @@ func generateCookieKeyIfDNE() []byte { 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 @@ func main() { 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 @@ func main() { cookie := generateCookieKeyIfDNE() SessionStore = sessions.NewCookieStore(cookie) - switch os.Args[1] { + switch args[0] { case "serve": wg := new(sync.WaitGroup) wg.Add(2)