Skip to content
This repository has been archived by the owner on Jun 9, 2022. It is now read-only.

Commit

Permalink
updated output
Browse files Browse the repository at this point in the history
  • Loading branch information
martinnirtl committed Feb 25, 2020
1 parent a5aafe9 commit 0efc95f
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 17 deletions.
20 changes: 10 additions & 10 deletions internal/commands/envcmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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"))
}

}
8 changes: 7 additions & 1 deletion internal/commands/envcmd/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}
}
2 changes: 2 additions & 0 deletions internal/commands/initcmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
2 changes: 1 addition & 1 deletion internal/commands/profilecmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
2 changes: 1 addition & 1 deletion internal/commands/profilecmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion internal/commands/profilecmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion internal/commands/profilecmd/rename.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
2 changes: 1 addition & 1 deletion internal/commands/profilecmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
2 changes: 1 addition & 1 deletion internal/commands/restartcmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0efc95f

Please sign in to comment.