add -version flag
This commit is contained in:
@@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
@@ -20,14 +21,13 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
log.Println("starting gonic")
|
|
||||||
log.Printf("version %q\n", version.VERSION)
|
|
||||||
set := flag.NewFlagSet(programName, flag.ExitOnError)
|
set := flag.NewFlagSet(programName, flag.ExitOnError)
|
||||||
listenAddr := set.String("listen-addr", "0.0.0.0:4747", "listen address (optional)")
|
listenAddr := set.String("listen-addr", "0.0.0.0:4747", "listen address (optional)")
|
||||||
musicPath := set.String("music-path", "", "path to music")
|
musicPath := set.String("music-path", "", "path to music")
|
||||||
dbPath := set.String("db-path", "gonic.db", "path to database (optional)")
|
dbPath := set.String("db-path", "gonic.db", "path to database (optional)")
|
||||||
scanInterval := set.Int("scan-interval", 0, "interval (in minutes) to automatically scan music (optional)")
|
scanInterval := set.Int("scan-interval", 0, "interval (in minutes) to automatically scan music (optional)")
|
||||||
_ = set.String("config-path", "", "path to config (optional)")
|
_ = set.String("config-path", "", "path to config (optional)")
|
||||||
|
showVersion := set.Bool("version", false, "show gonic version")
|
||||||
if err := ff.Parse(set, os.Args[1:],
|
if err := ff.Parse(set, os.Args[1:],
|
||||||
ff.WithConfigFileFlag("config-path"),
|
ff.WithConfigFileFlag("config-path"),
|
||||||
ff.WithConfigFileParser(ff.PlainParser),
|
ff.WithConfigFileParser(ff.PlainParser),
|
||||||
@@ -35,6 +35,10 @@ func main() {
|
|||||||
); err != nil {
|
); err != nil {
|
||||||
log.Fatalf("error parsing args: %v\n", err)
|
log.Fatalf("error parsing args: %v\n", err)
|
||||||
}
|
}
|
||||||
|
if *showVersion {
|
||||||
|
fmt.Println(version.VERSION)
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
if _, err := os.Stat(*musicPath); os.IsNotExist(err) {
|
if _, err := os.Stat(*musicPath); os.IsNotExist(err) {
|
||||||
log.Fatal("please provide a valid music directory")
|
log.Fatal("please provide a valid music directory")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user