Skip to content

Commit

Permalink
Merge pull request #1875 from carolynvs/fix-explain-install-cmd
Browse files Browse the repository at this point in the history
Only include required install params in explain command
  • Loading branch information
carolynvs authored Jan 31, 2022
2 parents 01ff3a7 + 65fa0e6 commit 79ee7c3
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 7 deletions.
7 changes: 5 additions & 2 deletions pkg/porter/explain.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ type PrintableDependency struct {
}

type PrintableParameter struct {
param *bundle.Parameter
Name string `json:"name" yaml:"name"`
Type interface{} `json:"type" yaml:"type"`
Default interface{} `json:"default" yaml:"default"`
Expand Down Expand Up @@ -230,6 +231,7 @@ func generatePrintable(bun cnab.ExtendedBundle, action string) (*PrintableBundle
sort.Sort(SortPrintableCredential(pb.Credentials))

for p, v := range bun.Parameters {
v := v // Go closures are funny like that
if bun.IsInternalParameter(p) || bun.ParameterHasSource(p) {
continue
}
Expand All @@ -241,7 +243,7 @@ func generatePrintable(bun cnab.ExtendedBundle, action string) (*PrintableBundle
if def == nil {
return nil, fmt.Errorf("empty definition for %s", v.Definition)
}
pp := PrintableParameter{}
pp := PrintableParameter{param: &v}
pp.Name = p
pp.Type = bun.GetParameterType(def)
pp.Default = def.Default
Expand Down Expand Up @@ -485,7 +487,8 @@ func (p *Porter) printInstallationInstructionBlock(bun *PrintableBundle, bundleR
// Bundle installation instruction
var requiredParameterFlags string
for _, parameter := range bun.Parameters {
if parameter.Required {
// Only include parameters required for install
if parameter.Required && shouldIncludeInExplainOutput(parameter.param, cnab.ActionInstall) {
requiredParameterFlags += parameter.Name + "=TODO "
}
}
Expand Down
1 change: 1 addition & 0 deletions pkg/porter/explain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func TestExplain_generateTable(t *testing.T) {

err = p.printBundleExplain(opts, pb)
assert.NoError(t, err)

gotOutput := p.TestConfig.TestContext.GetOutput()
test.CompareGoldenFile(t, "testdata/explain/expected-table-output.txt", gotOutput)
}
Expand Down
16 changes: 16 additions & 0 deletions pkg/porter/testdata/explain/expected-json-output.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,29 @@
"version": "0.1.0",
"porterVersion": "v0.30.0",
"parameters": [
{
"name": "namespace",
"type": "string",
"default": null,
"applyTo": "upgrade",
"description": "",
"required": false
},
{
"name": "region",
"type": "string",
"default": "mars",
"applyTo": "All Actions",
"description": "",
"required": false
},
{
"name": "seed",
"type": "boolean",
"default": null,
"applyTo": "All Actions",
"description": "",
"required": true
}
],
"mixins": [
Expand Down
12 changes: 7 additions & 5 deletions pkg/porter/testdata/explain/expected-table-output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ Version: 0.1.0
Porter Version: v0.30.0

Parameters:
---------------------------------------------------------------
Name Description Type Default Required Applies To
---------------------------------------------------------------
region string mars false All Actions
-------------------------------------------------------------------
Name Description Type Default Required Applies To
-------------------------------------------------------------------
namespace string <nil> false upgrade
region string mars false All Actions
seed boolean <nil> true All Actions

This bundle uses the following tools: helm, terraform.

To install this bundle run the following command, passing --param KEY=VALUE for any parameters you want to customize:
porter install
porter install --param seed=TODO
12 changes: 12 additions & 0 deletions pkg/porter/testdata/explain/expected-yaml-output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,24 @@ description: An example Porter configuration
version: 0.1.0
porterVersion: v0.30.0
parameters:
- name: namespace
type: string
default: null
applyTo: upgrade
description: ""
required: false
- name: region
type: string
default: mars
applyTo: All Actions
description: ""
required: false
- name: seed
type: boolean
default: null
applyTo: All Actions
description: ""
required: true
mixins:
- helm
- terraform
20 changes: 20 additions & 0 deletions pkg/porter/testdata/explain/params-bundle.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
"region": {
"default": "mars",
"type": "string"
},
"seed": {
"type": "boolean"
},
"namespace": {
"type": "string"
}
},
"description": "An example Porter configuration",
Expand All @@ -44,6 +50,20 @@
"destination": {
"env": "REGION"
}
},
"seed": {
"definition": "seed",
"required": true,
"destination": {
"env": "SEED"
}
},
"namespace": {
"definition": "namespace",
"applyTo": ["upgrade"],
"destination": {
"env": "NAMESPACE"
}
}
},
"schemaVersion": "v1.0.0-WD",
Expand Down

0 comments on commit 79ee7c3

Please sign in to comment.