Skip to content

Commit

Permalink
Return errors immediately, rather than cache-and-return-later
Browse files Browse the repository at this point in the history
  • Loading branch information
xxxserxxx authored and botto committed Sep 12, 2022
1 parent dff6182 commit 65bee72
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ import (

var (
// Flags.
owner string
description string
confirm bool
error_encountered bool
owner string
description string
confirm bool

// Commands.
rootCmd = &cobra.Command{}
Expand All @@ -38,34 +37,32 @@ var (
upCmd = &cobra.Command{
Use: "up",
Short: "Create the interface, run pre/post up, sync",
Run: func(cmd *cobra.Command, args []string) {
RunE: func(cmd *cobra.Command, args []string) error {
config := cli.MustLoadConfigFile()
server := cli.GetServer(config)
if e := server.Up(); e != nil {
fmt.Printf("error bringing up the network: %s\n", e)
error_encountered = true
return e
}
if e := utils.ShellOut(config.PostUp, "PostUp"); e != nil {
fmt.Printf("error bringing up the network: %s\n", e)
error_encountered = true
return e
}
return nil
},
}

downCmd = &cobra.Command{
Use: "down",
Short: "Destroy the interface, run pre/post down",
Run: func(cmd *cobra.Command, args []string) {
RunE: func(cmd *cobra.Command, args []string) error {
config := cli.MustLoadConfigFile()
server := cli.GetServer(config)
if e := server.DeleteLink(); e != nil {
fmt.Printf("error bringing up the network: %s\n", e)
error_encountered = true
return e
}
if e := utils.ShellOut(config.PostDown, "PostDown"); e != nil {
fmt.Printf("error bringing up the network: %s\n", e)
error_encountered = true
return e
}
return nil
},
}

Expand Down Expand Up @@ -183,8 +180,5 @@ func main() {
if err := rootCmd.Execute(); err != nil {
cli.ExitFail(err.Error())
}
if error_encountered {
os.Exit(1)
}
os.Exit(0)
}

0 comments on commit 65bee72

Please sign in to comment.