Skip to content

Commit

Permalink
Merge pull request #1150 from carolynvs/exec-suffix-args
Browse files Browse the repository at this point in the history
Add suffix arguments to exec mixin
  • Loading branch information
carolynvs authored Jul 20, 2020
2 parents 1e2d7ab + 87aad2f commit a355e30
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 7 deletions.
4 changes: 3 additions & 1 deletion docs/content/mixins/exec.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ exec:
repeated-flag:
- flag-value1
- flag-value2
suffix-arguments:
- suffix-arg1
suppress-output: false
outputs:
- name: NAME
Expand All @@ -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
Expand Down
18 changes: 12 additions & 6 deletions pkg/exec/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}

Expand All @@ -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 {
Expand All @@ -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
}
Expand Down
18 changes: 18 additions & 0 deletions pkg/exec/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
7 changes: 7 additions & 0 deletions pkg/exec/schema/exec.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@
"type": "string"
}
},
"suffix-arguments": {
"type": "array",
"items": {
"type": "string",
"minItems": 1
}
},
"outputs": {
"type": "array",
"items": {
Expand Down
10 changes: 10 additions & 0 deletions pkg/exec/testdata/suffix-args-input.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
install:
- exec:
description: "Build a docker image"
command: docker
arguments:
- build
flags:
tag: "getporter/porter-hello:latest"
suffix-arguments:
- .
7 changes: 7 additions & 0 deletions pkg/porter/testdata/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,13 @@
"type": "object"
},
"type": "array"
},
"suffix-arguments": {
"items": {
"minItems": 1,
"type": "string"
},
"type": "array"
}
},
"required": [
Expand Down

0 comments on commit a355e30

Please sign in to comment.