From ca88b4d83334a983ee925b632072b76a6ce5e27e Mon Sep 17 00:00:00 2001 From: dkeven <82354774+dkeven@users.noreply.github.com> Date: Fri, 13 Dec 2024 15:55:00 +0800 Subject: [PATCH] cherry pick of #67: fix: use the logger from std lib at cmd entry (#72) --- cmd/ctl/os/download.go | 8 ++++---- cmd/ctl/os/install.go | 4 ++-- cmd/ctl/os/prepare.go | 4 ++-- cmd/ctl/os/uninstall.go | 6 +++++- pkg/pipelines/install_terminus.go | 7 +++---- pkg/pipelines/prepare_system.go | 6 +++--- 6 files changed, 19 insertions(+), 16 deletions(-) diff --git a/cmd/ctl/os/download.go b/cmd/ctl/os/download.go index 99f799e..81044e0 100644 --- a/cmd/ctl/os/download.go +++ b/cmd/ctl/os/download.go @@ -2,9 +2,9 @@ package os import ( "bytetrade.io/web3os/installer/cmd/ctl/options" - "bytetrade.io/web3os/installer/pkg/core/logger" "bytetrade.io/web3os/installer/pkg/pipelines" "github.com/spf13/cobra" + "log" ) func NewCmdRootDownload() *cobra.Command { @@ -28,7 +28,7 @@ func NewCmdDownload() *cobra.Command { Run: func(cmd *cobra.Command, args []string) { if err := pipelines.DownloadInstallationPackage(o); err != nil { - logger.Fatalf("download installation package error: %v", err) + log.Fatalf("error: %v", err) } }, } @@ -45,7 +45,7 @@ func NewCmdDownloadWizard() *cobra.Command { Run: func(cmd *cobra.Command, args []string) { if err := pipelines.DownloadInstallationWizard(o); err != nil { - logger.Fatalf("download installation wizard error: %v", err) + log.Fatalf("error: %v", err) } }, } @@ -62,7 +62,7 @@ func NewCmdCheckDownload() *cobra.Command { Run: func(cmd *cobra.Command, args []string) { if err := pipelines.CheckDownloadInstallationPackage(o); err != nil { - logger.Errorf("check download error: %v", err) + log.Fatalf("error: %v", err) } }, } diff --git a/cmd/ctl/os/install.go b/cmd/ctl/os/install.go index b7713e3..8737d3d 100644 --- a/cmd/ctl/os/install.go +++ b/cmd/ctl/os/install.go @@ -2,9 +2,9 @@ package os import ( "bytetrade.io/web3os/installer/cmd/ctl/options" - "bytetrade.io/web3os/installer/pkg/core/logger" "bytetrade.io/web3os/installer/pkg/pipelines" "github.com/spf13/cobra" + "log" ) type InstallOsOptions struct { @@ -24,7 +24,7 @@ func NewCmdInstallOs() *cobra.Command { Short: "Install Olares", Run: func(cmd *cobra.Command, args []string) { if err := pipelines.CliInstallTerminusPipeline(o.InstallOptions); err != nil { - logger.Fatalf("install Olares error: %v", err) + log.Fatalf("error: %v", err) } }, } diff --git a/cmd/ctl/os/prepare.go b/cmd/ctl/os/prepare.go index 5d3e9d6..b07a22f 100644 --- a/cmd/ctl/os/prepare.go +++ b/cmd/ctl/os/prepare.go @@ -2,9 +2,9 @@ package os import ( "bytetrade.io/web3os/installer/cmd/ctl/options" - "bytetrade.io/web3os/installer/pkg/core/logger" "bytetrade.io/web3os/installer/pkg/pipelines" "github.com/spf13/cobra" + "log" ) type PrepareSystemOptions struct { @@ -25,7 +25,7 @@ func NewCmdPrepare() *cobra.Command { Run: func(cmd *cobra.Command, args []string) { if err := pipelines.PrepareSystemPipeline(o.PrepareOptions); err != nil { - logger.Fatalf("prepare system error: %v", err) + log.Fatalf("error: %v", err) } }, } diff --git a/cmd/ctl/os/uninstall.go b/cmd/ctl/os/uninstall.go index 6142855..9fbe0bc 100644 --- a/cmd/ctl/os/uninstall.go +++ b/cmd/ctl/os/uninstall.go @@ -4,6 +4,7 @@ import ( "bytetrade.io/web3os/installer/cmd/ctl/options" "bytetrade.io/web3os/installer/pkg/pipelines" "github.com/spf13/cobra" + "log" ) type UninstallOsOptions struct { @@ -22,7 +23,10 @@ func NewCmdUninstallOs() *cobra.Command { Use: "uninstall", Short: "Uninstall Olares", Run: func(cmd *cobra.Command, args []string) { - pipelines.UninstallTerminusPipeline(o.UninstallOptions) + err := pipelines.UninstallTerminusPipeline(o.UninstallOptions) + if err != nil { + log.Fatalf("error: %v", err) + } }, } o.UninstallOptions.AddFlags(cmd) diff --git a/pkg/pipelines/install_terminus.go b/pkg/pipelines/install_terminus.go index 1382b15..d7d5542 100644 --- a/pkg/pipelines/install_terminus.go +++ b/pkg/pipelines/install_terminus.go @@ -3,6 +3,7 @@ package pipelines import ( "encoding/base64" "fmt" + "github.com/pkg/errors" "io/ioutil" "path" "path/filepath" @@ -18,8 +19,7 @@ import ( func CliInstallTerminusPipeline(opts *options.CliTerminusInstallOptions) error { var terminusVersion, _ = phase.GetTerminusVersion() if terminusVersion != "" { - fmt.Printf("Olares is already installed, please uninstall it first.") - return nil + return errors.New("Olares is already installed, please uninstall it first.") } arg := common.NewArgument() @@ -33,8 +33,7 @@ func CliInstallTerminusPipeline(opts *options.CliTerminusInstallOptions) error { runtime, err := common.NewKubeRuntime(common.AllInOne, *arg) if err != nil { - fmt.Printf("Error creating installation runtime: %v\n", err) - return nil + return fmt.Errorf("error creating runtime: %v", err) } manifest := path.Join(runtime.GetInstallerDir(), "installation.manifest") diff --git a/pkg/pipelines/prepare_system.go b/pkg/pipelines/prepare_system.go index 4cfafa4..9c80822 100644 --- a/pkg/pipelines/prepare_system.go +++ b/pkg/pipelines/prepare_system.go @@ -1,6 +1,7 @@ package pipelines import ( + "errors" "fmt" "os" "path" @@ -15,8 +16,7 @@ func PrepareSystemPipeline(opts *options.CliPrepareSystemOptions) error { var terminusVersion, _ = phase.GetTerminusVersion() if terminusVersion != "" { - fmt.Printf("Olares is already installed, please uninstall it first.") - return nil + return errors.New("Olares is already installed, please uninstall it first.") } var arg = common.NewArgument() @@ -34,7 +34,7 @@ func PrepareSystemPipeline(opts *options.CliPrepareSystemOptions) error { runtime, err := common.NewKubeRuntime(common.AllInOne, *arg) if err != nil { - return err + return fmt.Errorf("error creating runtime: %w", err) } manifest := path.Join(runtime.GetInstallerDir(), "installation.manifest")