diff --git a/internal/cmd/deployorder.go b/internal/cmd/deployorder.go index b9155a4..5e29521 100644 --- a/internal/cmd/deployorder.go +++ b/internal/cmd/deployorder.go @@ -47,7 +47,7 @@ type deployOrder struct { apps []string src string - eEnv string + Env string region string srcType fs.PathType @@ -93,6 +93,9 @@ func newDeployOrder() *deployOrder { return fmt.Errorf("expecting 3 arguments, got: %d", len(args)) } + cmd.Env = args[1] + cmd.region = args[2] + case fs.PathTypeFile: if len(args) != 1 { return fmt.Errorf("expecting 1 arguments, got: %d", len(args)) @@ -103,8 +106,6 @@ func newDeployOrder() *deployOrder { } cmd.src = args[0] - cmd.eEnv = args[1] - cmd.region = args[2] cmd.srcType = pType return validateAppsParam(cmd.apps) @@ -114,7 +115,7 @@ func newDeployOrder() *deployOrder { return &cmd } -func (c *deployOrder) run(*cobra.Command, []string) error { +func (c *deployOrder) run(cc *cobra.Command, _ []string) error { var depsfrom deps.Composition composition, err := c.loadComposition() @@ -140,16 +141,16 @@ func (c *deployOrder) run(*cobra.Command, []string) error { } for _, i := range secondsorted { - fmt.Println(i) + cc.Println(i) } case "dot": - fmt.Printf("###########\n# dot of %s\n##########\n", strings.Join(c.apps, ", ")) + cc.Printf("###########\n# dot of %s\n##########\n", strings.Join(c.apps, ", ")) depsgraph, err := deps.OutputDotGraph(depsfrom) if err != nil { return err } - fmt.Println(depsgraph) + cc.Println(depsgraph) } return nil @@ -167,7 +168,7 @@ func validateAppsParam(apps []string) error { func (c *deployOrder) loadComposition() (*deps.Composition, error) { switch c.srcType { case fs.PathTypeDir: - return deps.CompositionFromSisuDir(c.src, c.eEnv, c.region) + return deps.CompositionFromSisuDir(c.src, c.Env, c.region) case fs.PathTypeFile: return deps.CompositionFromJSON(c.src) diff --git a/internal/cmd/export.go b/internal/cmd/export.go index 569e4e9..a05bc08 100644 --- a/internal/cmd/export.go +++ b/internal/cmd/export.go @@ -1,7 +1,6 @@ package cmd import ( - "fmt" "path/filepath" "github.com/spf13/cobra" @@ -40,7 +39,7 @@ func newExportCmd() *exportCmd { return &cmd } -func (c *exportCmd) run(*cobra.Command, []string) error { +func (c *exportCmd) run(cc *cobra.Command, _ []string) error { absPath, err := filepath.Abs(c.destFile) if err != nil { return err @@ -56,7 +55,7 @@ func (c *exportCmd) run(*cobra.Command, []string) error { return err } - fmt.Printf("written dependency tree to %s\n", absPath) + cc.Printf("written dependency tree to %s\n", absPath) return nil } diff --git a/internal/cmd/root.go b/internal/cmd/root.go index 9186c42..39f4a64 100644 --- a/internal/cmd/root.go +++ b/internal/cmd/root.go @@ -1,6 +1,8 @@ package cmd import ( + "os" + "github.com/spf13/cobra" ) @@ -22,5 +24,6 @@ func newRoot() *cobra.Command { func Execute() { root := newRoot() + root.SetOut(os.Stdout) _ = root.Execute() } diff --git a/internal/cmd/verify.go b/internal/cmd/verify.go index dc20771..cedb5f5 100644 --- a/internal/cmd/verify.go +++ b/internal/cmd/verify.go @@ -1,8 +1,6 @@ package cmd import ( - "fmt" - "github.com/spf13/cobra" "github.com/simplesurance/dependencies-tool/internal/deps" @@ -35,7 +33,7 @@ func newVerify() *verify { return &cmd } -func (c *verify) run(*cobra.Command, []string) error { +func (c *verify) run(cc *cobra.Command, _ []string) error { composition, err := deps.CompositionFromSisuDir(c.path, c.env, c.region) if err != nil { return err @@ -45,7 +43,7 @@ func (c *verify) run(*cobra.Command, []string) error { return err } - fmt.Println("verification successful") + cc.Println("verification successful") return nil }