Browse Source

Move version varaible to cli helper package

master
Till Wegmüller 3 years ago
parent
commit
671cc8c54f
  1. 7
      cli/helpers.go
  2. 9
      cmd/buildhelper.go
  3. 4
      cmd/imageadm.go
  4. 5
      cmd/imageadm/root.go
  5. 4
      cmd/podadm.go
  6. 5
      cmd/podadm/root.go

7
cli/helpers.go

@ -0,0 +1,7 @@
package cli
var version string
func GetVersion() string {
return version
}

9
cmd/buildhelper.go

@ -6,22 +6,21 @@ import (
"runtime"
"time"
"git.wegmueller.it/opencloud/opencloud/cli"
"git.wegmueller.it/opencloud/opencloud/image/build"
"git.wegmueller.it/opencloud/opencloud/smf"
"git.wegmueller.it/opencloud/opencloud/svcgen"
"git.wegmueller.it/opencloud/opencloud/sysacct"
"github.com/goodhosts/hostsfile"
"github.com/sirupsen/logrus"
)
var version string
func main() {
logrus.SetFormatter(&logrus.TextFormatter{
DisableTimestamp: true,
QuoteEmptyFields: true,
})
logrus.Infof("running buildhelper for os %s(%s) version %s", runtime.GOOS, runtime.GOARCH, version)
logrus.Infof("running buildhelper for os %s(%s) version %s", runtime.GOOS, runtime.GOARCH, cli.GetVersion())
// A zone is not completely booted when you can login.
// normally people wont notice this due to the fact that a manually
@ -117,7 +116,7 @@ func main() {
for _, svc := range imageConfig.Services {
logrus.Infof("Importing service description for %s", svc.Name)
if err := smf.Import(svc.Manifest); err != nil {
if err := svcgen.Import(svc.Manifest); err != nil {
panic(err)
}
}

4
cmd/imageadm.go

@ -2,8 +2,6 @@ package main
import "git.wegmueller.it/opencloud/opencloud/cmd/imageadm"
var version string
func main() {
imageadm.Execute(version)
imageadm.Execute()
}

5
cmd/imageadm/root.go

@ -3,6 +3,7 @@ package imageadm
import (
"os"
"git.wegmueller.it/opencloud/opencloud/cli"
"git.wegmueller.it/opencloud/opencloud/host"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
@ -18,6 +19,7 @@ var RootCmd = &cobra.Command{
Long: `This is the Administrative Tool to Create and manage images
in an opencloud instance or whatever other application can use the images.
`,
Version: cli.GetVersion(),
SilenceUsage: true,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
viper.SetConfigName("opencloud")
@ -60,8 +62,7 @@ var RootCmd = &cobra.Command{
},
}
func Execute(version string) {
RootCmd.Version = version
func Execute() {
if err := RootCmd.Execute(); err != nil {
if logrus.GetLevel() >= logrus.DebugLevel {
tracerr.PrintSource(err)

4
cmd/podadm.go

@ -2,8 +2,6 @@ package main
import "git.wegmueller.it/opencloud/opencloud/cmd/podadm"
var version string
func main() {
podadm.Execute(version)
podadm.Execute()
}

5
cmd/podadm/root.go

@ -3,6 +3,7 @@ package podadm
import (
"os"
"git.wegmueller.it/opencloud/opencloud/cli"
"git.wegmueller.it/opencloud/opencloud/host"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
@ -19,6 +20,7 @@ var RootCmd = &cobra.Command{
For now KVM and BHyve Containers are not supported but should be in the future.
`,
Version: cli.GetVersion(),
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
viper.SetConfigName("opencloud")
viper.AddConfigPath("/etc/")
@ -61,8 +63,7 @@ var RootCmd = &cobra.Command{
},
}
func Execute(version string) {
RootCmd.Version = version
func Execute() {
if err := RootCmd.Execute(); err != nil {
if viper.GetBool("debug") {
tracerr.PrintSource(err)

Loading…
Cancel
Save