From 0efc95f8cb8b1569291553fe1c74bad31e7a2219 Mon Sep 17 00:00:00 2001 From: Martin Nirtl Date: Tue, 25 Feb 2020 12:41:39 +0100 Subject: [PATCH] updated output --- internal/commands/envcmd/init.go | 20 ++++++++++---------- internal/commands/envcmd/set.go | 8 +++++++- internal/commands/initcmd/root.go | 2 ++ internal/commands/profilecmd/create.go | 2 +- internal/commands/profilecmd/delete.go | 2 +- internal/commands/profilecmd/list.go | 2 +- internal/commands/profilecmd/rename.go | 2 +- internal/commands/profilecmd/update.go | 2 +- internal/commands/restartcmd/root.go | 2 +- 9 files changed, 25 insertions(+), 17 deletions(-) diff --git a/internal/commands/envcmd/init.go b/internal/commands/envcmd/init.go index 9f3920e..967f68e 100644 --- a/internal/commands/envcmd/init.go +++ b/internal/commands/envcmd/init.go @@ -25,7 +25,7 @@ func getInitCommand() *cobra.Command { } func runInitCommand(cmd *cobra.Command, args []string) { - var env string + var envName string path := "." if len(args) == 1 { @@ -40,7 +40,7 @@ func runInitCommand(cmd *cobra.Command, args []string) { utils.Warn("No path provided. Default is: .") } - env = survey.InputName("Enter a name for the new environment (has to be unique)", "") + envName = survey.InputName("Enter a name for the new environment (has to be unique)", "") workingDir, err := os.Getwd() if err != nil { @@ -54,31 +54,31 @@ func runInitCommand(cmd *cobra.Command, args []string) { pull = "no-git" } - proceed := survey.Confirm(fmt.Sprintf("Add new environment %s (location: %s)", chalk.Cyan.Color(env), workingDir), true) + proceed := survey.Confirm(fmt.Sprintf("Add new environment %s (location: %s)", chalk.Cyan.Color(envName), workingDir), true) if !proceed { utils.Abort() } - viper.Set(fmt.Sprintf("envs.%s.home", env), workingDir) - viper.Set(fmt.Sprintf("envs.%s.pull", env), pull) - viper.Set(fmt.Sprintf("envs.%s.running", env), false) + viper.Set(fmt.Sprintf("envs.%s.home", envName), workingDir) + viper.Set(fmt.Sprintf("envs.%s.pull", envName), pull) + viper.Set(fmt.Sprintf("envs.%s.running", envName), false) - config.Save(fmt.Sprintf("Initialized new environment: %s", chalk.Cyan.Color(env)), fmt.Errorf("Failed to save newly created environment")) + config.Save(fmt.Sprintf("Initialized new environment: %s", chalk.Cyan.Color(envName)), fmt.Errorf("Failed to save newly created environment")) activeEnv := config.GetActiveEnv() oldEnv := activeEnv.GetName() set := true if activeEnv.IsRunning() { - message := fmt.Sprintf("Current active environment running: %s. Set newly initialized environment active", oldEnv) + message := fmt.Sprintf("Currently active environment %s is %s. Set new environment %s active", chalk.Cyan.Color(oldEnv), chalk.Green.Color("running"), chalk.Cyan.Color(envName)) set = survey.Confirm(message, false) } if set { - viper.Set("active", env) + viper.Set("active", envName) - config.Save(fmt.Sprintf("Set active environment: %s", chalk.Cyan.Color(env)), fmt.Errorf("Failed to set active environment")) + config.Save(fmt.Sprintf("Set active environment: %s", chalk.Cyan.Color(envName)), fmt.Errorf("Failed to set active environment")) } } diff --git a/internal/commands/envcmd/set.go b/internal/commands/envcmd/set.go index 56fdd16..368f96a 100644 --- a/internal/commands/envcmd/set.go +++ b/internal/commands/envcmd/set.go @@ -43,11 +43,17 @@ func runSetCommand(cmd *cobra.Command, args []string) { } if activeEnv.IsRunning() { - utils.Warn(fmt.Sprintf("Switching from running environment.")) + utils.Warn(fmt.Sprintf("Leaving running environment: %s", activeEnv.GetName())) } viper.Set("active", envName) config.Save(fmt.Sprintf("New active environment: %s (old: %s)", chalk.Cyan.Color(envName), activeEnv.GetName()), fmt.Errorf("Failed to set active environment")) + env, err := config.GetEnv(envName) + utils.ErrorAndExit(err) + + if env.IsRunning() { + utils.Warn("New active environment is presently running.") + } } diff --git a/internal/commands/initcmd/root.go b/internal/commands/initcmd/root.go index 2744ca6..dc54c69 100644 --- a/internal/commands/initcmd/root.go +++ b/internal/commands/initcmd/root.go @@ -67,4 +67,6 @@ func runInitCommand(cmd *cobra.Command, args []string) { if err := viper.WriteConfigAs(filepath); err != nil { utils.ErrorAndExit(fmt.Errorf("Could not save config.json at: %s", home)) } + + fmt.Printf("%s has been initialized successfully!\n\nStart with adding a new environment by %s or run %s for some little docs.\n", chalk.Cyan.Color("Dockma"), chalk.Cyan.Color("dockma env init"), chalk.Cyan.Color("dockma help")) } diff --git a/internal/commands/profilecmd/create.go b/internal/commands/profilecmd/create.go index fb9b758..21d3dce 100644 --- a/internal/commands/profilecmd/create.go +++ b/internal/commands/profilecmd/create.go @@ -72,5 +72,5 @@ func runCreateCommand(cmd *cobra.Command, args []string) { viper.Set(fmt.Sprintf("envs.%s.profiles.%s", activeEnv.GetName(), profileName), selected) - config.Save(fmt.Sprintf("Saved profile to %s environment: %s", chalk.Bold.TextStyle(activeEnv.GetName()), chalk.Cyan.Color(profileName)), fmt.Errorf("Failed to save profile: %s", profileName)) + config.Save(fmt.Sprintf("Saved profile %s to environment %s.", chalk.Cyan.Color(profileName), chalk.Cyan.Color(activeEnv.GetName())), fmt.Errorf("Failed to save profile: %s", profileName)) } diff --git a/internal/commands/profilecmd/delete.go b/internal/commands/profilecmd/delete.go index f672a5f..49ac8bc 100644 --- a/internal/commands/profilecmd/delete.go +++ b/internal/commands/profilecmd/delete.go @@ -54,7 +54,7 @@ func runDeleteCommand(cmd *cobra.Command, args []string) { for _, profileName := range selected { profileMap[profileName] = nil - config.Save(fmt.Sprintf("Deleted profile from %s environment: %s", chalk.Bold.TextStyle(activeEnvName), chalk.Cyan.Color(profileName)), fmt.Errorf("Failed to delete profile: %s", profileName)) + config.Save(fmt.Sprintf("Deleted profile %s from environment %s.", chalk.Cyan.Color(profileName), chalk.Cyan.Color(activeEnvName)), fmt.Errorf("Failed to delete profile: %s", profileName)) } viper.Set(fmt.Sprintf("envs.%s.profiles", activeEnvName), profileMap) diff --git a/internal/commands/profilecmd/list.go b/internal/commands/profilecmd/list.go index d91347e..55e5c5b 100644 --- a/internal/commands/profilecmd/list.go +++ b/internal/commands/profilecmd/list.go @@ -36,7 +36,7 @@ func runListCommand(cmd *cobra.Command, args []string) { fmt.Printf("No profiles in %s. Create one with %s.\n", chalk.Cyan.Color(activeEnv.GetName()), chalk.Cyan.Color("dockma profile create")) } - fmt.Printf("Profiles of %s environment:\n", chalk.Bold.TextStyle(activeEnv.GetName())) + fmt.Printf("Profiles of %s environment:\n", chalk.Cyan.Color(activeEnv.GetName())) for _, profileName := range profileNames { if servicesFlag { diff --git a/internal/commands/profilecmd/rename.go b/internal/commands/profilecmd/rename.go index 6010ebb..8a4d565 100644 --- a/internal/commands/profilecmd/rename.go +++ b/internal/commands/profilecmd/rename.go @@ -57,5 +57,5 @@ func runRenameCommand(cmd *cobra.Command, args []string) { viper.Set(fmt.Sprintf("envs.%s.profiles", activeEnv.GetName()), profileMap) - config.Save(fmt.Sprintf("Renamed profile of env %s from %s to %s", chalk.Bold.TextStyle(activeEnv.GetName()), chalk.Cyan.Color(renameProfile), chalk.Cyan.Color(profileName)), fmt.Errorf("Failed to rename profile: %s", renameProfile)) + config.Save(fmt.Sprintf("Renamed profile of environment %s from %s to %s.", chalk.Cyan.Color(activeEnv.GetName()), chalk.Yellow.Color(renameProfile), chalk.Cyan.Color(profileName)), fmt.Errorf("Failed to rename profile: %s", renameProfile)) } diff --git a/internal/commands/profilecmd/update.go b/internal/commands/profilecmd/update.go index 9955176..d1d82a3 100644 --- a/internal/commands/profilecmd/update.go +++ b/internal/commands/profilecmd/update.go @@ -61,5 +61,5 @@ func runUpdateCommand(cmd *cobra.Command, args []string) { viper.Set(fmt.Sprintf("envs.%s.profiles.%s", activeEnv.GetName(), profileName), selected) - config.Save(fmt.Sprintf("Updated profile of env %s: %s", chalk.Bold.TextStyle(activeEnv.GetName()), chalk.Cyan.Color(profileName)), fmt.Errorf("Failed to update profile: %s", profileName)) + config.Save(fmt.Sprintf("Updated profile %s of environment %s.", chalk.Cyan.Color(activeEnv.GetName()), chalk.Cyan.Color(profileName)), fmt.Errorf("Failed to update profile: %s", profileName)) } diff --git a/internal/commands/restartcmd/root.go b/internal/commands/restartcmd/root.go index 588e13b..23d6d50 100644 --- a/internal/commands/restartcmd/root.go +++ b/internal/commands/restartcmd/root.go @@ -56,7 +56,7 @@ func runRestartCommand(cmd *cobra.Command, args []string) { var timebridger externalcommand.Timebridger if config.GetHideSubcommandOutputSetting() { - timebridger = spinnertimebridger.Default(fmt.Sprintf("Running %s", chalk.Cyan.Color("docker-compose restart"))) + timebridger = spinnertimebridger.Default(fmt.Sprintf("Running %s", chalk.Cyan.Color(command))) } output, err := externalcommand.Execute(command, timebridger, logfile)