Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IZE-585 IZE-577 IZE-580 invalid ize exec command not handled #458

Merged
merged 3 commits into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -156,7 +157,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 @@ -119,14 +119,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