Fix version flag and display
This commit is contained in:
@@ -3,12 +3,13 @@ package base
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
"github.com/safing/portbase/modules/subsystems"
|
|
||||||
|
|
||||||
"github.com/safing/portbase/api"
|
"github.com/safing/portbase/api"
|
||||||
"github.com/safing/portbase/dataroot"
|
"github.com/safing/portbase/dataroot"
|
||||||
|
"github.com/safing/portbase/info"
|
||||||
"github.com/safing/portbase/modules"
|
"github.com/safing/portbase/modules"
|
||||||
|
"github.com/safing/portbase/modules/subsystems"
|
||||||
"github.com/safing/portbase/notifications"
|
"github.com/safing/portbase/notifications"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -18,16 +19,31 @@ var (
|
|||||||
|
|
||||||
dataDir string
|
dataDir string
|
||||||
databaseDir string
|
databaseDir string
|
||||||
|
showVersion bool
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
flag.StringVar(&dataDir, "data", "", "set data directory")
|
flag.StringVar(&dataDir, "data", "", "set data directory")
|
||||||
flag.StringVar(&databaseDir, "db", "", "alias to --data (deprecated)")
|
flag.StringVar(&databaseDir, "db", "", "alias to --data (deprecated)")
|
||||||
|
flag.BoolVar(&showVersion, "version", false, "show version and exit")
|
||||||
|
|
||||||
modules.SetGlobalPrepFn(globalPrep)
|
modules.SetGlobalPrepFn(globalPrep)
|
||||||
}
|
}
|
||||||
|
|
||||||
func globalPrep() error {
|
func globalPrep() error {
|
||||||
|
// check if meta info is ok
|
||||||
|
err := info.CheckVersion()
|
||||||
|
if err != nil {
|
||||||
|
return errors.New("compile error: please compile using the provided build script")
|
||||||
|
}
|
||||||
|
|
||||||
|
// print version
|
||||||
|
if showVersion {
|
||||||
|
fmt.Println(info.FullVersion())
|
||||||
|
return modules.ErrCleanExit
|
||||||
|
}
|
||||||
|
|
||||||
|
// check data root
|
||||||
if dataroot.Root() == nil {
|
if dataroot.Root() == nil {
|
||||||
// initialize data dir
|
// initialize data dir
|
||||||
|
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ func init() {
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// set meta info
|
// set meta info
|
||||||
info.Set("Portmaster Control", "0.3.3", "AGPLv3", true)
|
info.Set("Portmaster Control", "0.3.3", "AGPLv3", false)
|
||||||
|
|
||||||
// for debugging
|
// for debugging
|
||||||
// log.Start()
|
// log.Start()
|
||||||
|
|||||||
Reference in New Issue
Block a user