Skip to content

Commit

Permalink
Merge pull request #458 from hazelops/IZE-577-invalid-ize-exec-comman…
Browse files Browse the repository at this point in the history
…d-not-handled
  • Loading branch information
psihachina authored Sep 19, 2022
2 parents 63049ad + 15f545f commit 04ccacb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
7 changes: 6 additions & 1 deletion internal/commands/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/pterm/pterm"
"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
"os"
)

func NewCmdDoc() *cobra.Command {
Expand All @@ -14,8 +15,12 @@ func NewCmdDoc() *cobra.Command {
Long: "Create docs with ize commands description",
RunE: func(cmd *cobra.Command, args []string) error {
cmd.SilenceUsage = true
err := os.MkdirAll("./website/commands", 0777)
if err != nil {
return err
}

err := doc.GenMarkdownTree(cmd.Root(), "./commands")
err = doc.GenMarkdownTree(cmd.Root(), "./website/commands")
if err != nil {
return err
}
Expand Down
15 changes: 8 additions & 7 deletions internal/commands/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,24 @@ package commands

import (
"fmt"
"github.com/hazelops/ize/internal/requirements"
"strings"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/ecs"
"github.com/hazelops/ize/internal/config"
"github.com/hazelops/ize/internal/requirements"
"github.com/hazelops/ize/pkg/ssmsession"
"github.com/hazelops/ize/pkg/templates"
"github.com/pterm/pterm"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"strings"
)

type ExecOptions struct {
Config *config.Project
AppName string
EcsCluster string
Command string
Command []string
Task string
ContainerName string
}
Expand Down Expand Up @@ -90,7 +89,9 @@ func (o *ExecOptions) Complete(cmd *cobra.Command, args []string, argsLenAtDash
o.ContainerName = o.AppName
}

o.Command = strings.Join(args[argsLenAtDash:], " ")
if argsLenAtDash > -1 {
o.Command = args[argsLenAtDash:]
}

return nil
}
Expand All @@ -109,7 +110,7 @@ func (o *ExecOptions) Validate() error {
}

if len(o.Command) == 0 {
return fmt.Errorf("can't validate: command must be specified")
return fmt.Errorf("can't validate: you must specify at least one command for the container")
}

return nil
Expand Down Expand Up @@ -154,7 +155,7 @@ func (o *ExecOptions) Run() error {
Interactive: aws.Bool(true),
Cluster: &o.EcsCluster,
Task: &o.Task,
Command: aws.String(o.Command),
Command: aws.String(strings.Join(o.Command, " ")),
})
if aerr, ok := err.(awserr.Error); ok {
switch aerr.Code() {
Expand Down
16 changes: 8 additions & 8 deletions internal/commands/ize.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@ func Execute() {
}

func getConfig(cfg *config.Project) {
if !(slices.Contains(os.Args, "aws-profile") ||
slices.Contains(os.Args, "doc") ||
slices.Contains(os.Args, "completion") ||
slices.Contains(os.Args, "version") ||
slices.Contains(os.Args, "init") ||
slices.Contains(os.Args, "validate") ||
slices.Contains(os.Args, "config")) ||
slices.Contains(os.Args, "terraform") {
if slices.Contains(os.Args, "terraform") ||
!(slices.Contains(os.Args, "aws-profile") ||
slices.Contains(os.Args, "doc") ||
slices.Contains(os.Args, "completion") ||
slices.Contains(os.Args, "version") ||
slices.Contains(os.Args, "init") ||
slices.Contains(os.Args, "validate") ||
slices.Contains(os.Args, "config")) {
err := cfg.GetConfig()
if err != nil {
pterm.Error.Println(err)
Expand Down

0 comments on commit 04ccacb

Please sign in to comment.