diff --git a/examples/bastion-tunnel-monorepo/.ize/env/testnut/ize.toml b/examples/bastion-tunnel-monorepo/.ize/env/testnut/ize.toml index 66b815ad..a065c747 100644 --- a/examples/bastion-tunnel-monorepo/.ize/env/testnut/ize.toml +++ b/examples/bastion-tunnel-monorepo/.ize/env/testnut/ize.toml @@ -3,7 +3,7 @@ namespace = "testnut" # (required) Namespace of the project ca terraform_version = "1.2.6" # (optional) Terraform version can be set here. 1.1.3 by default # prefer_runtime = "" # (optional) Prefer a specific runtime. (native or docker) (default 'native') # tag = "" # (optional) Tag can be set statically. Normally it is being constructed automatically based on the git revision. -# plain_text = false # (optional) Plain text output can be enabled here. Default is false. Can be overridden by IZE_PLAIN_TEXT env var or --plain-text flag. +# plain_text = false # (optional) Plain text output can be enabled here. Default is false. Can be overridden by IZE_PLAIN_TEXT env var or --plain-text-output flag. # env = "dev" # (optional) Environment name can be specified here. Normally it should be passed via `ENV` variable or --env flag. # env_dir = "" # (optional) Environment directory can be specified here. Normally it's calculated automatically based on the directory structure convention. # docker_registry = "" # (optional) Docker registry can be set here. By default it uses ECR repo with the name of the service. diff --git a/examples/ecs-apps-monorepo/.ize/env/testnut/ize.toml b/examples/ecs-apps-monorepo/.ize/env/testnut/ize.toml index 36b684dd..070192c4 100644 --- a/examples/ecs-apps-monorepo/.ize/env/testnut/ize.toml +++ b/examples/ecs-apps-monorepo/.ize/env/testnut/ize.toml @@ -3,7 +3,7 @@ namespace = "testnut" # (required) Namespace of the project ca terraform_version = "1.2.6" # (optional) Terraform version can be set here. 1.1.3 by default # prefer_runtime = "" # (optional) Prefer a specific runtime. (native or docker) (default 'native') # tag = "" # (optional) Tag can be set statically. Normally it is being constructed automatically based on the git revision. -# plain_text = false # (optional) Plain text output can be enabled here. Default is false. Can be overridden by IZE_PLAIN_TEXT env var or --plain-text flag. +# plain_text = false # (optional) Plain text output can be enabled here. Default is false. Can be overridden by IZE_PLAIN_TEXT env var or --plain-text-output flag. # env = "dev" # (optional) Environment name can be specified here. Normally it should be passed via `ENV` variable or --env flag. # env_dir = "" # (optional) Environment directory can be specified here. Normally it's calculated automatically based on the directory structure convention. # docker_registry = "" # (optional) Docker registry can be set here. By default it uses ECR repo with the name of the service. diff --git a/examples/multistate-monorepo/.ize/env/testnut/ize.toml b/examples/multistate-monorepo/.ize/env/testnut/ize.toml index e4df0421..f6dd1729 100644 --- a/examples/multistate-monorepo/.ize/env/testnut/ize.toml +++ b/examples/multistate-monorepo/.ize/env/testnut/ize.toml @@ -3,7 +3,7 @@ namespace = "testnut" # (required) Namespace of the project ca terraform_version = "1.2.6" # (optional) Terraform version can be set here. 1.1.3 by default # prefer_runtime = "" # (optional) Prefer a specific runtime. (native or docker) (default 'native') # tag = "" # (optional) Tag can be set statically. Normally it is being constructed automatically based on the git revision. -# plain_text = false # (optional) Plain text output can be enabled here. Default is false. Can be overridden by IZE_PLAIN_TEXT env var or --plain-text flag. +# plain_text = false # (optional) Plain text output can be enabled here. Default is false. Can be overridden by IZE_PLAIN_TEXT env var or --plain-text-output flag. # env = "dev" # (optional) Environment name can be specified here. Normally it should be passed via `ENV` variable or --env flag. # env_dir = "" # (optional) Environment directory can be specified here. Normally it's calculated automatically based on the directory structure convention. # docker_registry = "" # (optional) Docker registry can be set here. By default it uses ECR repo with the name of the service. diff --git a/examples/sls-apps-monorepo/.ize/env/testnut/ize.toml b/examples/sls-apps-monorepo/.ize/env/testnut/ize.toml index 81813392..bc936c4b 100644 --- a/examples/sls-apps-monorepo/.ize/env/testnut/ize.toml +++ b/examples/sls-apps-monorepo/.ize/env/testnut/ize.toml @@ -3,7 +3,7 @@ namespace = "testnut" # (required) Namespace of the project ca terraform_version = "1.2.6" # (optional) Terraform version can be set here. 1.1.3 by default # prefer_runtime = "" # (optional) Prefer a specific runtime. (native or docker) (default 'native') # tag = "" # (optional) Tag can be set statically. Normally it is being constructed automatically based on the git revision. -# plain_text = false # (optional) Plain text output can be enabled here. Default is false. Can be overridden by IZE_PLAIN_TEXT env var or --plain-text flag. +# plain_text = false # (optional) Plain text output can be enabled here. Default is false. Can be overridden by IZE_PLAIN_TEXT env var or --plain-text-output flag. # env = "dev" # (optional) Environment name can be specified here. Normally it should be passed via `ENV` variable or --env flag. # env_dir = "" # (optional) Environment directory can be specified here. Normally it's calculated automatically based on the directory structure convention. # docker_registry = "" # (optional) Docker registry can be set here. By default it uses ECR repo with the name of the service. diff --git a/internal/commands/console_test.go b/internal/commands/console_test.go index f710c27c..e9aa282c 100644 --- a/internal/commands/console_test.go +++ b/internal/commands/console_test.go @@ -3,6 +3,11 @@ package commands import ( _ "embed" "fmt" + "os" + "path/filepath" + "strings" + "testing" + "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/ecs" @@ -12,10 +17,6 @@ import ( "github.com/hazelops/ize/pkg/mocks" "github.com/spf13/pflag" "github.com/spf13/viper" - "os" - "path/filepath" - "strings" - "testing" ) //go:generate mockgen -package=mocks -destination ../../pkg/mocks/mock_ecs.go github.com/aws/aws-sdk-go/service/ecs/ecsiface ECSAPI @@ -91,7 +92,7 @@ func TestConsole(t *testing.T) { }, { name: "failed (list tasks cluster not found)", - args: []string{"console", "goblin", "--plain-text"}, + args: []string{"console", "goblin", "--plain-text-output"}, env: map[string]string{"ENV": "test", "AWS_PROFILE": "test", "NAMESPACE": "dev-testnut", "AWS_REGION": "us-west-2"}, wantErr: true, mockECSClient: func(m *mocks.MockECSAPI) { @@ -100,7 +101,7 @@ func TestConsole(t *testing.T) { }, { name: "failed (list tasks any err)", - args: []string{"console", "goblin", "--plain-text"}, + args: []string{"console", "goblin", "--plain-text-output"}, env: map[string]string{"ENV": "test", "AWS_PROFILE": "test", "NAMESPACE": "dev-testnut", "AWS_REGION": "us-west-2"}, wantErr: true, mockECSClient: func(m *mocks.MockECSAPI) { @@ -109,7 +110,7 @@ func TestConsole(t *testing.T) { }, { name: "failed (execute command cluster not found)", - args: []string{"console", "goblin", "--plain-text"}, + args: []string{"console", "goblin", "--plain-text-output"}, env: map[string]string{"ENV": "test", "AWS_PROFILE": "test", "NAMESPACE": "dev-testnut", "AWS_REGION": "us-west-2"}, wantErr: true, mockECSClient: func(m *mocks.MockECSAPI) { @@ -122,7 +123,7 @@ func TestConsole(t *testing.T) { }, { name: "failed (execute command any err)", - args: []string{"console", "goblin", "--plain-text"}, + args: []string{"console", "goblin", "--plain-text-output"}, env: map[string]string{"ENV": "test", "AWS_PROFILE": "test", "NAMESPACE": "dev-testnut", "AWS_REGION": "us-west-2"}, wantErr: true, mockECSClient: func(m *mocks.MockECSAPI) { diff --git a/internal/commands/exec_test.go b/internal/commands/exec_test.go index 6bb4296d..7202e8db 100644 --- a/internal/commands/exec_test.go +++ b/internal/commands/exec_test.go @@ -3,6 +3,11 @@ package commands import ( _ "embed" "fmt" + "os" + "path/filepath" + "strings" + "testing" + "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/ecs" @@ -12,10 +17,6 @@ import ( "github.com/hazelops/ize/pkg/mocks" "github.com/spf13/pflag" "github.com/spf13/viper" - "os" - "path/filepath" - "strings" - "testing" ) //go:generate mockgen -package=mocks -destination ../../pkg/mocks/mock_ecs.go github.com/aws/aws-sdk-go/service/ecs/ecsiface ECSAPI @@ -91,7 +92,7 @@ func TestExec(t *testing.T) { }, { name: "failed (list tasks cluster not found)", - args: []string{"console", "goblin", "--plain-text"}, + args: []string{"console", "goblin", "--plain-text-output"}, env: map[string]string{"ENV": "test", "AWS_PROFILE": "test", "NAMESPACE": "dev-testnut", "AWS_REGION": "us-west-2"}, wantErr: true, mockECSClient: func(m *mocks.MockECSAPI) { @@ -100,7 +101,7 @@ func TestExec(t *testing.T) { }, { name: "failed (list tasks any err)", - args: []string{"console", "goblin", "--plain-text"}, + args: []string{"console", "goblin", "--plain-text-output"}, env: map[string]string{"ENV": "test", "AWS_PROFILE": "test", "NAMESPACE": "dev-testnut", "AWS_REGION": "us-west-2"}, wantErr: true, mockECSClient: func(m *mocks.MockECSAPI) { @@ -109,7 +110,7 @@ func TestExec(t *testing.T) { }, { name: "failed (execute command cluster not found)", - args: []string{"console", "goblin", "--plain-text"}, + args: []string{"console", "goblin", "--plain-text-output"}, env: map[string]string{"ENV": "test", "AWS_PROFILE": "test", "NAMESPACE": "dev-testnut", "AWS_REGION": "us-west-2"}, wantErr: true, mockECSClient: func(m *mocks.MockECSAPI) { @@ -122,7 +123,7 @@ func TestExec(t *testing.T) { }, { name: "failed (execute command any err)", - args: []string{"console", "goblin", "--plain-text"}, + args: []string{"console", "goblin", "--plain-text-output"}, env: map[string]string{"ENV": "test", "AWS_PROFILE": "test", "NAMESPACE": "dev-testnut", "AWS_REGION": "us-west-2"}, wantErr: true, mockECSClient: func(m *mocks.MockECSAPI) { diff --git a/internal/commands/ize.go b/internal/commands/ize.go index 264a5dc7..fa0aab6a 100644 --- a/internal/commands/ize.go +++ b/internal/commands/ize.go @@ -3,6 +3,12 @@ package commands import ( "bytes" "fmt" + "os" + "path" + "runtime" + "strings" + "text/template" + "github.com/hazelops/ize/internal/config" "github.com/hazelops/ize/internal/version" "github.com/hazelops/ize/pkg/templates" @@ -12,11 +18,6 @@ import ( "github.com/spf13/pflag" "github.com/spf13/viper" "golang.org/x/exp/slices" - "os" - "path" - "runtime" - "strings" - "text/template" ) var izeDescTpl = templates.LongDesc(` @@ -60,7 +61,7 @@ func newRootCmd(project *config.Project) *cobra.Command { cmd.CompletionOptions.DisableDefaultCmd = true cmd.PersistentFlags().StringP("log-level", "l", "", "set log level. Possible levels: info, debug, trace, panic, warn, error, fatal(default)") - cmd.PersistentFlags().Bool("plain-text", false, "enable plain text") + cmd.PersistentFlags().Bool("plain-text-output", false, "enable plain text output") cmd.PersistentFlags().StringP("config-file", "c", "", "set config file name") cmd.PersistentFlags().StringP("env", "e", "", "(required) set environment name (overrides value set in IZE_ENV / ENV if any of them are set)") cmd.PersistentFlags().StringP("aws-profile", "p", "", "(required) set AWS profile (overrides value in ize.toml and IZE_AWS_PROFILE / AWS_PROFILE if any of them are set)") diff --git a/internal/config/config.go b/internal/config/config.go index cbc3d0cd..4c044e24 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -2,9 +2,6 @@ package config import ( "fmt" - "github.com/hazelops/ize/internal/schema" - "github.com/mitchellh/mapstructure" - "github.com/spf13/cobra" "os" "os/exec" "path/filepath" @@ -12,6 +9,10 @@ import ( "strings" "text/template" + "github.com/hazelops/ize/internal/schema" + "github.com/mitchellh/mapstructure" + "github.com/spf13/cobra" + "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/sts" "github.com/hazelops/ize/internal/aws/utils" @@ -240,7 +241,7 @@ func InitConfig() { viper.SetDefault("TERRAFORM_VERSION", "1.1.3") viper.SetDefault("PREFER_RUNTIME", "native") viper.SetDefault("CUSTOM_PROMPT", false) - viper.SetDefault("PLAIN_TEXT", false) + viper.SetDefault("PLAIN_TEXT_OUTPUT", false) home, err := os.UserHomeDir() if err != nil { @@ -541,7 +542,7 @@ func structToMap(item interface{}) map[string]interface{} { return res } -//GetApps returns a list of application names in the directory for shell completions +// GetApps returns a list of application names in the directory for shell completions func GetApps(*cobra.Command, []string, string) ([]string, cobra.ShellCompDirective) { var apps []string diff --git a/internal/config/project.go b/internal/config/project.go index ed2dde16..bc511d22 100644 --- a/internal/config/project.go +++ b/internal/config/project.go @@ -27,7 +27,7 @@ type Project struct { Namespace string `mapstructure:",omitempty"` Env string `mapstructure:",omitempty"` LogLevel string `mapstructure:"log_level,omitempty"` - PlainText bool `mapstructure:"plain_text,omitempty"` + PlainText bool `mapstructure:"plain_text_output,omitempty"` CustomPrompt bool `mapstructure:"custom_prompt,omitempty"` PreferRuntime string `mapstructure:"prefer_runtime,omitempty"` Tag string `mapstructure:",omitempty"` diff --git a/internal/schema/ize-spec.json b/internal/schema/ize-spec.json index cbdf04bf..9752468c 100644 --- a/internal/schema/ize-spec.json +++ b/internal/schema/ize-spec.json @@ -38,8 +38,8 @@ "type": "string", "description": "(required) Namespace of the project can be specified here. It is used as a base for all naming. It can be overridden by NAMESPACE env var or --namespace flag." }, - "plain_text": { - "description": "(optional) Plain text output can be enabled here. Default is false. Can be overridden by IZE_PLAIN_TEXT env var or --plain-text flag.", + "plain_text_output": { + "description": "(optional) Plain text output can be enabled here. Default is false. Can be overridden by IZE_PLAIN_TEXT env var or --plain-text-output flag.", "anyOf": [ { "type": "string" diff --git a/pkg/terminal/noninteractive.go b/pkg/terminal/noninteractive.go index 4c614c00..af2767a8 100644 --- a/pkg/terminal/noninteractive.go +++ b/pkg/terminal/noninteractive.go @@ -6,7 +6,6 @@ import ( "fmt" "io" "os" - "regexp" "strings" "sync" "text/tabwriter" @@ -268,7 +267,5 @@ type stripAnsiWriter struct { } func (w *stripAnsiWriter) Write(p []byte) (n int, err error) { - return w.Next.Write(reAnsi.ReplaceAll(p, []byte{})) + return w.Next.Write(p) } - -var reAnsi = regexp.MustCompile("[\u001B\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))") diff --git a/test-e2e/ecs_apps_test.go b/test-e2e/ecs_apps_test.go index 2783d1ed..bcec79da 100644 --- a/test-e2e/ecs_apps_test.go +++ b/test-e2e/ecs_apps_test.go @@ -323,7 +323,7 @@ func TestIzeExecGoblin(t *testing.T) { ize := NewBinary(t, izeBinary, examplesRootDir) - stdout, stderr, err := ize.RunPty("--plain-text", "exec", "goblin", "--", "sh -c \"echo $APP_NAME\"") + stdout, stderr, err := ize.RunPty("--plain-text-output", "exec", "goblin", "--", "sh -c \"echo $APP_NAME\"") if err != nil { t.Errorf("error: %s", err) @@ -347,7 +347,7 @@ func TestIzeExecSquibby(t *testing.T) { ize := NewBinary(t, izeBinary, examplesRootDir) - stdout, stderr, err := ize.RunPty("--plain-text", "exec", "squibby", "--", "sh -c \"echo $APP_NAME\"") + stdout, stderr, err := ize.RunPty("--plain-text-output", "exec", "squibby", "--", "sh -c \"echo $APP_NAME\"") if err != nil { t.Errorf("error: %s", err)