Skip to content

Commit

Permalink
Fix exit codes
Browse files Browse the repository at this point in the history
  • Loading branch information
kacpersaw committed Nov 3, 2020
1 parent 371322e commit f71d8fe
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 11 deletions.
3 changes: 2 additions & 1 deletion cmd/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"io/ioutil"
"log"
"os"
)

// applyOptions store apply command options
Expand Down Expand Up @@ -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()
Expand Down
9 changes: 6 additions & 3 deletions cmd/compare.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
"errors"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
3 changes: 2 additions & 1 deletion cmd/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"fmt"
"io"
"os"

c "github.com/codilime/floodgate/config"
rm "github.com/codilime/floodgate/resourcemanager"
Expand Down Expand Up @@ -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:")
Expand Down
2 changes: 1 addition & 1 deletion cmd/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion resourcemanager/resourcemanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit f71d8fe

Please sign in to comment.