Skip to content

Commit

Permalink
Fix messages on init and uninstall (#392)
Browse files Browse the repository at this point in the history
  • Loading branch information
mukundansundar authored Jul 13, 2020
1 parent ff2d5dd commit 5ba8e9a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 57 deletions.
31 changes: 2 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand All @@ -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
```

Expand Down
27 changes: 13 additions & 14 deletions pkg/standalone/standalone.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
28 changes: 14 additions & 14 deletions pkg/standalone/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"os"

"github.com/dapr/cli/pkg/rundata"
"github.com/dapr/cli/pkg/print"
"github.com/dapr/cli/utils"
)

Expand Down Expand Up @@ -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",
Expand All @@ -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
}
Expand All @@ -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
Expand All @@ -88,15 +93,15 @@ 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)
_, placementErr := os.Stat(placementFilePath) // check if the placement binary exists
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
Expand All @@ -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")
Expand Down

0 comments on commit 5ba8e9a

Please sign in to comment.