diff --git a/cmd/apply.go b/cmd/apply.go index 789c3e3..3d867fc 100644 --- a/cmd/apply.go +++ b/cmd/apply.go @@ -7,6 +7,7 @@ import ( "io" "io/ioutil" "log" + "os" ) // applyOptions store apply command options @@ -48,7 +49,7 @@ func runApply(cmd *cobra.Command, options applyOptions) error { resourceManager := &rm.ResourceManager{} if err := resourceManager.Init(config); err != nil { - return err + os.Exit(2) } resources := resourceManager.GetResources() diff --git a/cmd/compare.go b/cmd/compare.go index 9cf4f54..b663b2a 100644 --- a/cmd/compare.go +++ b/cmd/compare.go @@ -1,7 +1,6 @@ package cmd import ( - "errors" "fmt" "io" "os" @@ -42,7 +41,7 @@ func runCompare(cmd *cobra.Command, options compareOptions) error { config.Merge(cfg) resourceManager := &rm.ResourceManager{} if err := resourceManager.Init(config); err != nil { - return err + os.Exit(2) } changes, err := resourceManager.GetChanges() if err != nil { @@ -52,8 +51,12 @@ func runCompare(cmd *cobra.Command, options compareOptions) error { return nil } + //print changes and exit with code 1 printCompareDiff(cmd.OutOrStdout(), changes) - return errors.New("end diff") + fmt.Println("end diff") + os.Exit(1) + + return nil } func printCompareDiff(out io.Writer, changes []rm.ResourceChange) { diff --git a/cmd/execute.go b/cmd/execute.go index 3b3bbb1..1318748 100644 --- a/cmd/execute.go +++ b/cmd/execute.go @@ -59,7 +59,7 @@ func runExecute(cmd *cobra.Command, options executeOptions) error { resourceManager := &rm.ResourceManager{} if err := resourceManager.Init(config); err != nil { - return err + os.Exit(2) } client := resourceManager.GetClient() diff --git a/cmd/inspect.go b/cmd/inspect.go index fc47d00..0791dcf 100644 --- a/cmd/inspect.go +++ b/cmd/inspect.go @@ -3,6 +3,7 @@ package cmd import ( "fmt" "io" + "os" c "github.com/codilime/floodgate/config" rm "github.com/codilime/floodgate/resourcemanager" @@ -40,7 +41,7 @@ func runInspect(cmd *cobra.Command, options inspectOptions) error { config.Merge(cfg) resourceManager := &rm.ResourceManager{} if err := resourceManager.Init(config); err != nil { - return err + os.Exit(2) } fmt.Fprintln(cmd.OutOrStdout(), "Current Spinnaker resource status:") fmt.Fprintln(cmd.OutOrStdout(), "\nApplications:") diff --git a/cmd/sync.go b/cmd/sync.go index a0e9032..840b948 100644 --- a/cmd/sync.go +++ b/cmd/sync.go @@ -44,7 +44,7 @@ func runSync(cmd *cobra.Command, options syncOptions) error { config.Merge(cfg) resourceManager := &rm.ResourceManager{} if err := resourceManager.Init(config); err != nil { - return err + os.Exit(2) } if options.dryRun { changes, err := resourceManager.GetChanges() diff --git a/parser/parser.go b/parser/parser.go index 1141572..5a2c3c8 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -65,7 +65,7 @@ func (p *Parser) ParseDirectories(directories []string) (*ParsedResourceData, er for _, entrypoint := range directories { output, err := p.loadFilesFromDirectory(entrypoint) if err != nil { - log.Fatal(err) + log.Warn(err) return nil, err } objects = append(objects, output...) @@ -93,8 +93,8 @@ func (p *Parser) loadFilesFromDirectory(entrypoint string) ([]map[string]interfa } obj, err := fileLoader.LoadFile(path) if err != nil { - log.Warn(f.Name(), " not loaded due to\n", err) - return nil + log.Warn(f.Name(), " not loaded due to") + return err } objects = append(objects, obj...) log.Debugf("Loaded file: %s", path) diff --git a/resourcemanager/resourcemanager.go b/resourcemanager/resourcemanager.go index aad3ad3..2cc2d3a 100644 --- a/resourcemanager/resourcemanager.go +++ b/resourcemanager/resourcemanager.go @@ -55,7 +55,10 @@ func (rm *ResourceManager) Init(config *c.Config, customOptions ...Option) error if err != nil { return err } - rm.createResourcesFromData(resourceData) + err = rm.createResourcesFromData(resourceData) + if err != nil { + return err + } return nil }