Skip to content

Commit aa2066e

Browse files
authored
docs: fix assert artifact help text on flag mutual exclusivity (#768)
* docs: fix assert artifact help text on flag mutual exclusivity The help text incorrectly stated all four modes were mutually exclusive. In reality only --environment and --policy are mutually exclusive. --flow is an independent filter that can be combined with either. * fix: enforce --environment and --policy mutual exclusivity client-side Use Cobra's MarkFlagsMutuallyExclusive to give users a fast error message without a server round-trip. * fix: update test golden string for client-side mutual exclusivity error
1 parent 68f7b91 commit aa2066e

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

cmd/kosli/assertArtifact.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,21 @@ import (
1414

1515
const assertArtifactShortDesc = `Assert the compliance status of an artifact in Kosli. ` +
1616
`
17-
There are four (mutually exclusive) ways to use ^kosli assert artifact^:
17+
There are three ways to choose what to assert against:
1818
1919
1. Against an environment. When ^--environment^ is specified,
2020
asserts against all policies currently attached to the given environment.
2121
2. Against one or more policies. When ^--policy^ is specified,
2222
asserts against all the given policies.
23-
3. Against a flow. When ^--flow^ is specified, asserts against the
24-
current template file of the given flow.
25-
4. Against many flows. When none of ^--environment^, ^--policy^, or ^--flow^
26-
are specified, asserts against the template files of *all* flows the artifact
27-
is found in (by fingerprint).
23+
3. Against flow templates. When neither ^--environment^ nor ^--policy^
24+
is specified, asserts against the template files of the flows the artifact
25+
is found in.
26+
27+
^--environment^ and ^--policy^ are mutually exclusive.
28+
29+
^--flow^ can be combined with any of the above to narrow the lookup
30+
to a specific flow. Without ^--flow^, all flows containing the artifact
31+
(by fingerprint) are considered.
2832
`
2933

3034
const assertArtifactLongDesc = assertArtifactShortDesc + `
@@ -104,6 +108,7 @@ func newAssertArtifactCmd(out io.Writer) *cobra.Command {
104108

105109
addFingerprintFlags(cmd, o.fingerprintOptions)
106110
addDryRunFlag(cmd)
111+
cmd.MarkFlagsMutuallyExclusive("environment", "policy")
107112

108113
return cmd
109114
}

cmd/kosli/assertArtifact_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ func (suite *AssertArtifactCommandTestSuite) TestAssertArtifactCmd() {
185185
wantError: true,
186186
name: "15 providing both --environment and --polices fails",
187187
cmd: fmt.Sprintf(`assert artifact --fingerprint %s --environment %s --policy %s %s`, suite.fingerprint1, suite.envName, suite.policyName1, suite.defaultKosliArguments),
188-
golden: "Error: Cannot specify both 'environment_name' and 'policy_name' at the same time\n",
188+
golden: "Error: if any flags in the group [environment policy] are set none of the others can be; [environment policy] were all set\n",
189189
},
190190
{
191191
wantError: true,

0 commit comments

Comments
 (0)