1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-10-30 03:36:16 +00:00
mycorrhiza/flag.go

47 lines
831 B
Go
Raw Normal View History

2020-10-25 15:06:51 +00:00
package main
import (
_ "embed"
2020-10-25 15:06:51 +00:00
"flag"
2021-03-09 14:27:14 +00:00
"fmt"
2020-10-25 15:06:51 +00:00
"log"
2021-03-09 14:27:14 +00:00
"os"
2020-10-25 15:06:51 +00:00
"path/filepath"
2021-06-19 11:38:13 +00:00
"github.com/bouncepaw/mycorrhiza/cfg"
2020-10-25 15:06:51 +00:00
)
2021-05-11 08:33:00 +00:00
// CLI options are read and parsed here.
2020-10-25 15:06:51 +00:00
func init() {
flag.StringVar(&cfg.HTTPPort, "port", "", "Listen on another port. This option also updates the config file for your convenience.")
2021-05-11 08:33:00 +00:00
flag.Usage = printHelp
}
// printHelp prints the help message.
2021-05-11 08:33:00 +00:00
func printHelp() {
2021-06-19 11:38:13 +00:00
fmt.Fprintf(
2021-05-11 08:33:00 +00:00
flag.CommandLine.Output(),
2021-06-19 11:38:13 +00:00
"Usage: %s WIKI_PATH\n",
2021-05-11 08:33:00 +00:00
os.Args[0],
)
flag.PrintDefaults()
2020-10-25 15:06:51 +00:00
}
2021-05-11 08:33:00 +00:00
// parseCliArgs parses CLI options and sets several important global variables. Call it early.
2020-10-25 15:06:51 +00:00
func parseCliArgs() {
flag.Parse()
args := flag.Args()
if len(args) == 0 {
log.Fatal("Error: pass a wiki directory")
}
wikiDir, err := filepath.Abs(args[0])
2020-10-25 15:06:51 +00:00
if err != nil {
log.Fatal(err)
}
2021-06-19 04:51:10 +00:00
cfg.WikiDir = wikiDir
2020-10-25 15:06:51 +00:00
}