Merge pull request #59 from safing/fix/version-info
Fix version flag and display
This commit is contained in:
@@ -3,12 +3,13 @@ package base
|
||||
import (
|
||||
"errors"
|
||||
"flag"
|
||||
|
||||
"github.com/safing/portbase/modules/subsystems"
|
||||
"fmt"
|
||||
|
||||
"github.com/safing/portbase/api"
|
||||
"github.com/safing/portbase/dataroot"
|
||||
"github.com/safing/portbase/info"
|
||||
"github.com/safing/portbase/modules"
|
||||
"github.com/safing/portbase/modules/subsystems"
|
||||
"github.com/safing/portbase/notifications"
|
||||
)
|
||||
|
||||
@@ -18,16 +19,31 @@ var (
|
||||
|
||||
dataDir string
|
||||
databaseDir string
|
||||
showVersion bool
|
||||
)
|
||||
|
||||
func init() {
|
||||
flag.StringVar(&dataDir, "data", "", "set data directory")
|
||||
flag.StringVar(&databaseDir, "db", "", "alias to --data (deprecated)")
|
||||
flag.BoolVar(&showVersion, "version", false, "show version and exit")
|
||||
|
||||
modules.SetGlobalPrepFn(globalPrep)
|
||||
}
|
||||
|
||||
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 {
|
||||
// initialize data dir
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ func init() {
|
||||
|
||||
func main() {
|
||||
// set meta info
|
||||
info.Set("Portmaster Control", "0.3.3", "AGPLv3", true)
|
||||
info.Set("Portmaster Control", "0.3.3", "AGPLv3", false)
|
||||
|
||||
// for debugging
|
||||
// log.Start()
|
||||
|
||||
Reference in New Issue
Block a user