From 5ba8e9ab3999e27394663e34ca95e6e7cef0addb Mon Sep 17 00:00:00 2001 From: Mukundan Sundararajan Date: Mon, 13 Jul 2020 16:50:51 -0700 Subject: [PATCH] Fix messages on init and uninstall (#392) --- README.md | 31 ++----------------------------- pkg/standalone/standalone.go | 27 +++++++++++++-------------- pkg/standalone/uninstall.go | 28 ++++++++++++++-------------- 3 files changed, 29 insertions(+), 57 deletions(-) diff --git a/README.md b/README.md index 64066e045..d6ef8d440 100644 --- a/README.md +++ b/README.md @@ -72,24 +72,12 @@ Output should look like so: ``` ⌛ Making the jump to hyperspace... -creating default components folder: ~/.dapr/components -↓ Downloading binaries and setting up components... -removing archive ~/.dapr/daprd_darwin_amd64.tar.gz -↙ Downloading binaries and setting up components... -installing Dapr to /usr/local/bin - -removing extracted binary ~/.dapr/daprd ✅ Downloaded binaries and completed components set up. -ℹ️ daprd binary has been installed. - +ℹ️ daprd binary has been installed to /usr/local/bin. ℹ️ dapr_placement container is running. - ℹ️ dapr_redis container is running. - ℹ️ dapr_zipkin container is running. - ℹ️ Use `docker ps` to check running containers. - ✅ Success! Dapr is up and running. To get started, go here: https://aka.ms/dapr-getting-started ``` @@ -112,24 +100,9 @@ Output should look like so: ```bash ⌛ Making the jump to hyperspace... -creating default components folder: ~/.dapr/components -↙ Downloading binaries and setting up components... -removing archive ~/.dapr/placement_darwin_amd64.tar.gz - -installing Dapr to /usr/local/bin - -removing extracted binary ~/.dapr/placement -↙ Downloading binaries and setting up components... -removing archive ~/.dapr/daprd_darwin_amd64.tar.gz -← Downloading binaries and setting up components... -installing Dapr to /usr/local/bin - -removing extracted binary ~/.dapr/daprd ✅ Downloaded binaries and completed components set up. -ℹ️ daprd binary has been installed. - +ℹ️ daprd binary has been installed to /usr/local/bin. ℹ️ placement binary has been installed. - ✅ Success! Dapr is up and running. To get started, go here: https://aka.ms/dapr-getting-started ``` diff --git a/pkg/standalone/standalone.go b/pkg/standalone/standalone.go index 8f211f83d..66257ddf5 100644 --- a/pkg/standalone/standalone.go +++ b/pkg/standalone/standalone.go @@ -186,10 +186,17 @@ func Init(runtimeVersion string, dockerNetwork string, installLocation string, r msg = "Downloaded binaries and completed components set up." print.SuccessStatusEvent(os.Stdout, msg) - print.InfoStatusEvent(os.Stdout, "%s binary has been installed.\n", daprRuntimeFilePrefix) + destDir := daprDefaultLinuxAndMacInstallPath + if runtime.GOOS == daprWindowsOS { + destDir = daprDefaultWindowsInstallPath + } + if installLocation != "" { + destDir = installLocation + } + print.InfoStatusEvent(os.Stdout, "%s binary has been installed to %s.", daprRuntimeFilePrefix, destDir) if slimMode { // Print info on placement binary only on slim install - print.InfoStatusEvent(os.Stdout, "%s binary has been installed.\n", placementServiceFilePrefix) + print.InfoStatusEvent(os.Stdout, "%s binary has been installed to %s.", placementServiceFilePrefix, destDir) } else { dockerContainerNames := []string{DaprPlacementContainerName, DaprRedisContainerName, DaprZipkinContainerName} for _, container := range dockerContainerNames { @@ -198,10 +205,10 @@ func Init(runtimeVersion string, dockerNetwork string, installLocation string, r return err } if ok { - print.InfoStatusEvent(os.Stdout, "%s container is running.\n", container) + print.InfoStatusEvent(os.Stdout, "%s container is running.", container) } } - print.InfoStatusEvent(os.Stdout, "Use `docker ps` to check running containers.\n") + print.InfoStatusEvent(os.Stdout, "Use `docker ps` to check running containers.") } return nil } @@ -252,7 +259,6 @@ func runZipkin(wg *sync.WaitGroup, errorChan chan<- error, dir, version string, if exists { // do not create container again if it exists - fmt.Printf("\n%s container exists\n", zipkinContainerName) args = append(args, "start", zipkinContainerName) } else { args = append(args, @@ -309,7 +315,6 @@ func runRedis(wg *sync.WaitGroup, errorChan chan<- error, dir, version string, d if exists { // do not create container again if it exists - fmt.Printf("\n%s container exists\n", redisContainerName) args = append(args, "start", redisContainerName) } else { args = append(args, @@ -413,7 +418,6 @@ func runPlacementService(wg *sync.WaitGroup, errorChan chan<- error, dir, versio errorChan <- err return } else if exists { - print.FailureStatusEvent(os.Stdout, "%s container exists.\n", placementContainerName) errorChan <- fmt.Errorf("%s container exists or is running. %s", placementContainerName, errInstallTemplate) return } @@ -503,7 +507,6 @@ func installBinary(wg *sync.WaitGroup, errorChan chan<- error, dir, version, bin errorChan <- fmt.Errorf("error extracting %s binary: %s", binaryFilePrefix, err) return } - fmt.Printf("\nremoving archive %s\n", filepath) err = os.Remove(filepath) if err != nil { @@ -517,7 +520,6 @@ func installBinary(wg *sync.WaitGroup, errorChan chan<- error, dir, version, bin return } - fmt.Printf("\nremoving extracted binary %s\n", extractedFilePath) err = os.Remove(extractedFilePath) if err != nil { @@ -569,7 +571,6 @@ func makeDefaultComponentsDir() error { componentsDir := DefaultComponentsDirPath() _, err := os.Stat(componentsDir) if os.IsNotExist(err) { - fmt.Printf("creating default components folder: %s\n", componentsDir) errDir := os.MkdirAll(componentsDir, 0755) if errDir != nil { return fmt.Errorf("error creating default components folder: %s", errDir) @@ -707,7 +708,6 @@ func moveFileToPath(filepath string, installLocation string) (string, error) { return "", err } - fmt.Printf("\ninstalling Dapr to %s\n", destDir) err = utils.CreateDirectory(destDir) if err != nil { return "", err @@ -735,7 +735,8 @@ func moveFileToPath(filepath string, installLocation string) (string, error) { return fmt.Sprintf("%s\\daprd.exe", destDir), nil } - if installLocation != "" { + if !strings.HasPrefix(fileName, placementServiceFilePrefix) && installLocation != "" { + // print only on daprd binary install in custom location color.Set(color.FgYellow) fmt.Printf("\nDapr installed to %s, please run the following to add it to your path:\n", destDir) fmt.Printf(" export PATH=$PATH:%s\n", destDir) @@ -900,8 +901,6 @@ func checkAndOverWriteFile(filePath string, b []byte) error { if err = ioutil.WriteFile(filePath, b, 0644); err != nil { return err } - } else { - fmt.Printf("\nfile %s exists in the default dapr path\n", filePath) } return nil } diff --git a/pkg/standalone/uninstall.go b/pkg/standalone/uninstall.go index ed590b367..ff97c061e 100644 --- a/pkg/standalone/uninstall.go +++ b/pkg/standalone/uninstall.go @@ -5,7 +5,7 @@ import ( "fmt" "os" - "github.com/dapr/cli/pkg/rundata" + "github.com/dapr/cli/pkg/print" "github.com/dapr/cli/utils" ) @@ -39,10 +39,10 @@ func removeContainers(uninstallPlacementContainer, uninstallAll bool, dockerNetw func removeDockerContainer(containerErrs []error, containerName, network string) []error { exists, _ := confirmContainerIsRunningOrExists(containerName, false) if !exists { - fmt.Printf("WARNING: %s container does not exist\n", containerName) + print.WarningStatusEvent(os.Stdout, "WARNING: %s container does not exist", containerName) return containerErrs } - fmt.Println("removing container: ", containerName) + print.InfoStatusEvent(os.Stdout, "Removing container: %s", containerName) _, err := utils.RunCmdAndWait( "docker", "rm", "--force", @@ -61,8 +61,13 @@ func removeDefaultDaprDir(uninstallAll bool) (string, error) { return "", nil } defaultDaprPath := defaultFolderPath(defaultDaprDirName) - fmt.Println("removing folder: ", defaultDaprPath) - err := os.RemoveAll(defaultDaprPath) + _, err := os.Stat(defaultDaprPath) + if os.IsNotExist(err) { + print.WarningStatusEvent(os.Stdout, "WARNING: %s default Dapr folder does not exist", defaultDaprPath) + return defaultDaprPath, nil + } + print.InfoStatusEvent(os.Stdout, "Removing folder: %s", defaultDaprPath) + err = os.RemoveAll(defaultDaprPath) return defaultDaprPath, err } @@ -73,7 +78,7 @@ func removeInstalledBinaries(binaryFilePrefix, installLocation string) (string, if os.IsNotExist(err) { return binaryPath, nil } - fmt.Println("removing binary: ", binaryPath) + print.InfoStatusEvent(os.Stdout, "Removing binary: %s", binaryPath) err = os.Remove(binaryPath) return binaryPath, err @@ -88,7 +93,7 @@ func Uninstall(uninstallAll bool, installLocation, dockerNetwork string) error { path, err = removeInstalledBinaries(daprRuntimeFilePrefix, installLocation) if err != nil { - fmt.Println("WARNING: could not delete binary file: ", path) + print.WarningStatusEvent(os.Stdout, "WARNING: could not delete binary file: %s", path) } placementFilePath := binaryFilePath(placementServiceFilePrefix, installLocation) @@ -96,7 +101,7 @@ func Uninstall(uninstallAll bool, installLocation, dockerNetwork string) error { uninstallPlacementContainer := os.IsNotExist(placementErr) path, err = removeInstalledBinaries(placementServiceFilePrefix, installLocation) if err != nil { - fmt.Println("WARNING: could not delete binary file: ", path) + print.WarningStatusEvent(os.Stdout, "WARNING: could not delete binary file: %s", path) } dockerInstalled := false @@ -105,14 +110,9 @@ func Uninstall(uninstallAll bool, installLocation, dockerNetwork string) error { containerErrs = removeContainers(uninstallPlacementContainer, uninstallAll, dockerNetwork) } - err = rundata.DeleteRunDataFile() - if err != nil { - fmt.Println("WARNING: could not delete run data file") - } - path, err = removeDefaultDaprDir(uninstallAll) if err != nil { - fmt.Println("WARNING: could not delete default dapr folder: ", path) + print.WarningStatusEvent(os.Stdout, "WARNING: could not delete default dapr folder: %s", path) } err = errors.New("uninstall failed")