From 87aad2fbbd2b09949a6e6f0ebd8153af59875f8b Mon Sep 17 00:00:00 2001 From: Carolyn Van Slyck Date: Mon, 20 Jul 2020 09:15:20 -0500 Subject: [PATCH] Add suffix arguments to exec mixin --- docs/content/mixins/exec.md | 4 +++- pkg/exec/action.go | 18 ++++++++++++------ pkg/exec/exec_test.go | 18 ++++++++++++++++++ pkg/exec/schema/exec.json | 7 +++++++ pkg/exec/testdata/suffix-args-input.yaml | 10 ++++++++++ pkg/porter/testdata/schema.json | 7 +++++++ 6 files changed, 57 insertions(+), 7 deletions(-) create mode 100644 pkg/exec/testdata/suffix-args-input.yaml diff --git a/docs/content/mixins/exec.md b/docs/content/mixins/exec.md index 387278e2e..8a39108b2 100644 --- a/docs/content/mixins/exec.md +++ b/docs/content/mixins/exec.md @@ -29,6 +29,8 @@ exec: repeated-flag: - flag-value1 - flag-value2 + suffix-arguments: + - suffix-arg1 suppress-output: false outputs: - name: NAME @@ -42,7 +44,7 @@ exec: This is executed as: ``` -$ cmd arg1 arg2 -a flag-value --long-flag true --repeated-flag flag-value1 --repeated-flag flag-value2 +$ cmd arg1 arg2 -a flag-value --long-flag true --repeated-flag flag-value1 --repeated-flag flag-value2 suffix-arg1 ``` ### Suppress Output diff --git a/pkg/exec/action.go b/pkg/exec/action.go index 57f481a84..00d88cbcf 100644 --- a/pkg/exec/action.go +++ b/pkg/exec/action.go @@ -88,6 +88,7 @@ func (a *Actions) UnmarshalYAML(unmarshal func(interface{}) error) error { return nil } +var _ builder.HasOrderedArguments = Step{} var _ builder.ExecutableStep = Step{} var _ builder.StepWithOutputs = Step{} @@ -96,12 +97,13 @@ type Step struct { } type Instruction struct { - Description string `yaml:"description"` - Command string `yaml:"command"` - Arguments []string `yaml:"arguments,omitempty"` - Flags builder.Flags `yaml:"flags,omitempty"` - Outputs []Output `yaml:"outputs,omitempty"` - SuppressOutput bool `yaml:"suppress-output,omitempty"` + Description string `yaml:"description"` + Command string `yaml:"command"` + Arguments []string `yaml:"arguments,omitempty"` + SuffixArguments []string `yaml:"suffix-arguments,omitempty"` + Flags builder.Flags `yaml:"flags,omitempty"` + Outputs []Output `yaml:"outputs,omitempty"` + SuppressOutput bool `yaml:"suppress-output,omitempty"` } func (s Step) GetCommand() string { @@ -112,6 +114,10 @@ func (s Step) GetArguments() []string { return s.Arguments } +func (s Step) GetSuffixArguments() []string { + return s.SuffixArguments +} + func (s Step) GetFlags() builder.Flags { return s.Flags } diff --git a/pkg/exec/exec_test.go b/pkg/exec/exec_test.go index bc437026e..f017f76f9 100644 --- a/pkg/exec/exec_test.go +++ b/pkg/exec/exec_test.go @@ -117,3 +117,21 @@ func TestMixin_Uninstall(t *testing.T) { step := action.Steps[0] assert.Equal(t, "bash", step.Instruction.Command) } + +func TestMixin_SuffixArgs(t *testing.T) { + os.Setenv(test.ExpectedCommandEnv, `docker build --tag getporter/porter-hello:latest .`) + defer os.Unsetenv(test.ExpectedCommandEnv) + + b, err := ioutil.ReadFile("testdata/suffix-args-input.yaml") + require.NoError(t, err, "ReadFile failed") + + var action Action + err = yaml.Unmarshal(b, &action) + require.NoError(t, err, "Unmarshal failed") + + h := NewTestMixin(t) + h.In = bytes.NewReader(b) + + err = h.Execute(ExecuteOptions{}) + require.NoError(t, err) +} diff --git a/pkg/exec/schema/exec.json b/pkg/exec/schema/exec.json index 46b80e114..050e80e98 100644 --- a/pkg/exec/schema/exec.json +++ b/pkg/exec/schema/exec.json @@ -64,6 +64,13 @@ "type": "string" } }, + "suffix-arguments": { + "type": "array", + "items": { + "type": "string", + "minItems": 1 + } + }, "outputs": { "type": "array", "items": { diff --git a/pkg/exec/testdata/suffix-args-input.yaml b/pkg/exec/testdata/suffix-args-input.yaml new file mode 100644 index 000000000..2569d7346 --- /dev/null +++ b/pkg/exec/testdata/suffix-args-input.yaml @@ -0,0 +1,10 @@ +install: + - exec: + description: "Build a docker image" + command: docker + arguments: + - build + flags: + tag: "getporter/porter-hello:latest" + suffix-arguments: + - . \ No newline at end of file diff --git a/pkg/porter/testdata/schema.json b/pkg/porter/testdata/schema.json index 3574f8f8a..8f7791657 100644 --- a/pkg/porter/testdata/schema.json +++ b/pkg/porter/testdata/schema.json @@ -264,6 +264,13 @@ "type": "object" }, "type": "array" + }, + "suffix-arguments": { + "items": { + "minItems": 1, + "type": "string" + }, + "type": "array" } }, "required": [