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

Commit

Permalink
use new utils.Error func for improved error processing
Browse files Browse the repository at this point in the history
  • Loading branch information
martinnirtl committed Feb 8, 2020
1 parent 1773cef commit a1d7809
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 66 deletions.
4 changes: 1 addition & 3 deletions internal/commands/configcmd/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ func setConfigVar(varname string) error {

err := config.Save()

if err != nil {
utils.Error(err)
}
utils.Error(err)

return nil
}
8 changes: 2 additions & 6 deletions internal/commands/downcmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ var DownCommand = &cobra.Command{

err := os.Chdir(envHomeDir)

if err != nil {
utils.Error(err)
}
utils.Error(err)

var timebridger externalcommand.Timebridger
if hideCmdOutput := viper.GetBool("hidesubcommandoutput"); hideCmdOutput {
Expand All @@ -41,8 +39,6 @@ var DownCommand = &cobra.Command{

_, err = externalcommand.Execute("docker-compose down", timebridger, filepath)

if err != nil {
utils.Error(err)
}
utils.Error(err)
},
}
8 changes: 2 additions & 6 deletions internal/commands/logscmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,15 @@ var LogsCommand = &cobra.Command{

err := os.Chdir(envHomeDir)

if err != nil {
utils.Error(err)
}
utils.Error(err)

args = addFlagsToArgs(args)

command := externalcommand.JoinCommand("docker-compose logs", args...)

_, err = externalcommand.Execute(command, nil, "")

if err != nil {
utils.Error(err)
}
utils.Error(err)
},
}

Expand Down
4 changes: 1 addition & 3 deletions internal/commands/profilecmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ var createCmd = &cobra.Command{

err = config.Save()

if err != nil {
utils.Error(err)
}
utils.Error(err)

utils.Success(fmt.Sprintf("Successfully saved profile: %s [%s]", profileName, activeEnv))
},
Expand Down
8 changes: 2 additions & 6 deletions internal/commands/profilecmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ var deleteCmd = &cobra.Command{

profileName, err := survey.Select("Select profile to be deleted", profileNames)

if err != nil {
utils.Error(err)
}
utils.Error(err)

profileMap := viper.GetStringMap(fmt.Sprintf("envs.%s.profiles", activeEnv))

Expand All @@ -42,9 +40,7 @@ var deleteCmd = &cobra.Command{

err = config.Save()

if err != nil {
utils.Error(err)
}
utils.Error(err)

utils.Success(fmt.Sprintf("Successfully deleted profile: %s [%s]", profileName, activeEnv))
},
Expand Down
4 changes: 1 addition & 3 deletions internal/commands/profilecmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ var listCmd = &cobra.Command{
if servicesFlag {
profile, err := config.GetProfile(activeEnv, profileName)

if err != nil {
utils.Error(err)
}
utils.Error(err)

for _, service := range profile.Services {
if utils.Includes(profile.Selected, service) {
Expand Down
4 changes: 1 addition & 3 deletions internal/commands/profilecmd/rename.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ var renameCmd = &cobra.Command{

err = config.Save()

if err != nil {
utils.Error(err)
}
utils.Error(err)

utils.Success(fmt.Sprintf("Successfully renamed profile from %s to %s [%s]", renameProfile, profileName, activeEnv))
},
Expand Down
8 changes: 2 additions & 6 deletions internal/commands/profilecmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ var updateCmd = &cobra.Command{

profile, err := config.GetProfile(activeEnv, profileName)

if err != nil {
utils.Error(err)
}
utils.Error(err)

selected, err := survey.MultiSelect(fmt.Sprintf("Select services for profile %s%s%s", chalk.Cyan, profileName, chalk.ResetColor), services.All, profile.Selected)

Expand All @@ -63,9 +61,7 @@ var updateCmd = &cobra.Command{

err = config.Save()

if err != nil {
utils.Error(err)
}
utils.Error(err)

utils.Success(fmt.Sprintf("Successfully updated profile: %s [%s]", profileName, activeEnv))
},
Expand Down
8 changes: 2 additions & 6 deletions internal/commands/pscmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,10 @@ var PSCommand = &cobra.Command{

err := os.Chdir(envHomeDir)

if err != nil {
utils.Error(err)
}
utils.Error(err)

_, err = externalcommand.Execute("docker-compose ps", nil, "")

if err != nil {
utils.Error(err)
}
utils.Error(err)
},
}
4 changes: 1 addition & 3 deletions internal/commands/pullcmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ var PullCommand = &cobra.Command{

err := Pull(envHomeDir, true)

if err != nil {
utils.Error(err)
}
utils.Error(err)
},
}
28 changes: 7 additions & 21 deletions internal/commands/upcmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,13 @@ var UpCommand = &cobra.Command{
if profileName != "latest" {
profile, err := config.GetProfile(activeEnv, profileName)

if err != nil {
utils.Error(err)
}
utils.Error(err)

preselected = profile.Selected
} else {
profile, err := config.GetLatest(activeEnv)

if err != nil {
utils.Error(err)
}
utils.Error(err)

preselected = profile.Selected
}
Expand All @@ -84,9 +80,7 @@ var UpCommand = &cobra.Command{
preselected = services.All
}

if err != nil {
utils.Error(err)
}
utils.Error(err)

if len(services.Override) > 0 {
fmt.Printf("%sFound %d services in docker-compose.override.y(a)ml: %s%s\n\n", chalk.Yellow, len(services.Override), strings.Join(services.Override, ", "), chalk.ResetColor)
Expand Down Expand Up @@ -119,22 +113,16 @@ var UpCommand = &cobra.Command{

err = config.Save()

if err != nil {
fmt.Printf("%sSome problem ocurred: Could not save profile/latest selection%s\n")
}
utils.Error(err)
}

err = envvars.SetEnvVars(services.All, selectedServices)

if err != nil {
utils.Error(err)
}
utils.Error(err)

err = os.Chdir(envHomeDir)

if err != nil {
utils.Error(err)
}
utils.Error(err)

var timebridger externalcommand.Timebridger
if hideCmdOutput := viper.GetBool("hidesubcommandoutput"); hideCmdOutput {
Expand All @@ -145,8 +133,6 @@ var UpCommand = &cobra.Command{

_, err = externalcommand.Execute(command, timebridger, filepath)

if err != nil {
utils.Error(err)
}
utils.Error(err)
},
}

0 comments on commit a1d7809

Please sign in to comment.