Skip to content

Commit 37bae90

Browse files
authored
Feat/non filename completions (#4115)
* Do not offer filename completions to options not taking filenames Signed-off-by: Ville Skyttä <ville.skytta@iki.fi> * Fixed value set completion improvements Signed-off-by: Ville Skyttä <ville.skytta@iki.fi> --------- Signed-off-by: Ville Skyttä <ville.skytta@iki.fi>
1 parent 4c32996 commit 37bae90

10 files changed

+39
-13
lines changed

cmd/cosign/cli/options/annotations.go

+1
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,5 @@ func (o *AnnotationOptions) AnnotationsMap() (sigs.AnnotationsMap, error) {
5050
func (o *AnnotationOptions) AddFlags(cmd *cobra.Command) {
5151
cmd.Flags().StringSliceVarP(&o.Annotations, "annotations", "a", nil,
5252
"extra key=value pairs to sign")
53+
_ = cmd.RegisterFlagCompletionFunc("annotations", cobra.NoFileCompletions)
5354
}

cmd/cosign/cli/options/attach.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,15 @@ func (o *AttachSBOMOptions) AddFlags(cmd *cobra.Command) {
8282
"path to the sbom, or {-} for stdin")
8383
_ = cmd.MarkFlagFilename("sbom", sbomExts...)
8484

85-
cmd.Flags().StringVar(&o.SBOMType, "type", "spdx",
86-
"type of sbom (spdx|cyclonedx|syft)")
85+
sbomTypes := []string{"spdx", "cyclonedx", "syft"}
86+
cmd.Flags().StringVar(&o.SBOMType, "type", sbomTypes[0],
87+
"type of sbom ("+strings.Join(sbomTypes, "|")+")")
88+
_ = cmd.RegisterFlagCompletionFunc("type", cobra.FixedCompletions(sbomTypes, cobra.ShellCompDirectiveNoFileComp))
8789

90+
inputFormats := []string{ctypes.JSONInputFormat, ctypes.XMLInputFormat, ctypes.TextInputFormat}
8891
cmd.Flags().StringVar(&o.SBOMInputFormat, "input-format", "",
89-
"type of sbom input format (json|xml|text)")
92+
"type of sbom input format ("+strings.Join(inputFormats, "|")+")")
93+
_ = cmd.RegisterFlagCompletionFunc("input-format", cobra.FixedCompletions(inputFormats, cobra.ShellCompDirectiveNoFileComp))
9094
}
9195

9296
func (o *AttachSBOMOptions) MediaType() (types.MediaType, error) {

cmd/cosign/cli/options/attest.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
package options
1717

1818
import (
19+
"strings"
20+
1921
"github.com/spf13/cobra"
2022
)
2123

@@ -87,8 +89,9 @@ func (o *AttestOptions) AddFlags(cmd *cobra.Command) {
8789
cmd.Flags().BoolVar(&o.TlogUpload, "tlog-upload", true,
8890
"whether or not to upload to the tlog")
8991

90-
cmd.Flags().StringVar(&o.RekorEntryType, "rekor-entry-type", "dsse",
91-
"specifies the type to be used for a rekor entry upload. Options are intoto or dsse (default). ")
92+
cmd.Flags().StringVar(&o.RekorEntryType, "rekor-entry-type", rekorEntryTypes[0],
93+
"specifies the type to be used for a rekor entry upload ("+strings.Join(rekorEntryTypes, "|")+")")
94+
_ = cmd.RegisterFlagCompletionFunc("rekor-entry-type", cobra.FixedCompletions(rekorEntryTypes, cobra.ShellCompDirectiveNoFileComp))
9295

9396
cmd.Flags().StringVar(&o.TSAClientCACert, "timestamp-client-cacert", "",
9497
"path to the X.509 CA certificate file in PEM format to be used for the connection to the TSA Server")
@@ -104,6 +107,7 @@ func (o *AttestOptions) AddFlags(cmd *cobra.Command) {
104107

105108
cmd.Flags().StringVar(&o.TSAServerURL, "timestamp-server-url", "",
106109
"url to the Timestamp RFC3161 server, default none. Must be the path to the API to request timestamp responses, e.g. https://freetsa.org/tsr")
110+
_ = cmd.RegisterFlagCompletionFunc("timestamp-server-url", cobra.NoFileCompletions)
107111

108112
cmd.Flags().BoolVar(&o.RecordCreationTimestamp, "record-creation-timestamp", false,
109113
"set the createdAt timestamp in the attestation artifact to the time it was created; by default, cosign sets this to the zero value")

cmd/cosign/cli/options/attest_blob.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
package options
1616

1717
import (
18+
"strings"
19+
1820
"github.com/spf13/cobra"
1921
)
2022

@@ -97,15 +99,17 @@ func (o *AttestBlobOptions) AddFlags(cmd *cobra.Command) {
9799

98100
cmd.Flags().StringVar(&o.Hash, "hash", "",
99101
"hash of blob in hexadecimal (base16). Used if you want to sign an artifact stored elsewhere and have the hash")
102+
_ = cmd.RegisterFlagCompletionFunc("hash", cobra.NoFileCompletions)
100103

101104
cmd.Flags().BoolVarP(&o.SkipConfirmation, "yes", "y", false,
102105
"skip confirmation prompts for non-destructive operations")
103106

104107
cmd.Flags().BoolVar(&o.TlogUpload, "tlog-upload", true,
105108
"whether or not to upload to the tlog")
106109

107-
cmd.Flags().StringVar(&o.RekorEntryType, "rekor-entry-type", "dsse",
108-
"specifies the type to be used for a rekor entry upload. Options are intoto or dsse (default). ")
110+
cmd.Flags().StringVar(&o.RekorEntryType, "rekor-entry-type", rekorEntryTypes[0],
111+
"specifies the type to be used for a rekor entry upload ("+strings.Join(rekorEntryTypes, "|")+")")
112+
_ = cmd.RegisterFlagCompletionFunc("rekor-entry-type", cobra.FixedCompletions(rekorEntryTypes, cobra.ShellCompDirectiveNoFileComp))
109113

110114
cmd.Flags().StringVar(&o.TSAClientCACert, "timestamp-client-cacert", "",
111115
"path to the X.509 CA certificate file in PEM format to be used for the connection to the TSA Server")
@@ -121,6 +125,7 @@ func (o *AttestBlobOptions) AddFlags(cmd *cobra.Command) {
121125

122126
cmd.Flags().StringVar(&o.TSAServerURL, "timestamp-server-url", "",
123127
"url to the Timestamp RFC3161 server, default none. Must be the path to the API to request timestamp responses, e.g. https://freetsa.org/tsr")
128+
_ = cmd.RegisterFlagCompletionFunc("timestamp-server-url", cobra.NoFileCompletions)
124129

125130
cmd.Flags().StringVar(&o.RFC3161TimestampPath, "rfc3161-timestamp-bundle", "",
126131
"path to an RFC 3161 timestamp bundle FILE")

cmd/cosign/cli/options/bundle.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
package options
1717

1818
import (
19+
"strings"
20+
1921
"github.com/spf13/cobra"
2022
)
2123

@@ -66,6 +68,7 @@ func (o *BundleCreateOptions) AddFlags(cmd *cobra.Command) {
6668

6769
cmd.Flags().StringVar(&o.RekorURL, "rekor-url", "https://rekor.sigstore.dev",
6870
"address of rekor STL server")
71+
_ = cmd.RegisterFlagCompletionFunc("rekor-url", cobra.NoFileCompletions)
6972

7073
cmd.Flags().StringVar(&o.RFC3161TimestampPath, "rfc3161-timestamp", "",
7174
"path to RFC3161 timestamp FILE")
@@ -78,9 +81,11 @@ func (o *BundleCreateOptions) AddFlags(cmd *cobra.Command) {
7881
cmd.Flags().BoolVar(&o.Sk, "sk", false,
7982
"whether to use a hardware security key")
8083

81-
cmd.Flags().StringVar(&o.Slot, "slot", "",
82-
"security key slot to use for generated key (default: signature) "+
83-
"(authentication|signature|card-authentication|key-management)")
84+
slots := []string{"authentication", "signature", "card-authentication", "key-management"}
85+
cmd.Flags().StringVar(&o.Slot, "slot", "signature",
86+
"security key slot to use for generated key ("+
87+
strings.Join(slots, "|")+")")
88+
_ = cmd.RegisterFlagCompletionFunc("slot", cobra.FixedCompletions(slots, cobra.ShellCompDirectiveNoFileComp))
8489

8590
cmd.MarkFlagsMutuallyExclusive("bundle", "certificate")
8691
cmd.MarkFlagsMutuallyExclusive("bundle", "signature")

cmd/cosign/cli/options/options.go

+5
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,8 @@ var signatureExts = []string{
5555
var wasmExts = []string{
5656
"wasm",
5757
}
58+
59+
var rekorEntryTypes = []string{
60+
"dsse", // first one is the default
61+
"intoto",
62+
}

cmd/cosign/cli/options/signblob.go

+2
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,11 @@ func (o *SignBlobOptions) AddFlags(cmd *cobra.Command) {
101101

102102
cmd.Flags().StringVar(&o.TSAServerName, "timestamp-server-name", "",
103103
"SAN name to use as the 'ServerName' tls.Config field to verify the mTLS connection to the TSA Server")
104+
_ = cmd.RegisterFlagCompletionFunc("timestamp-server-name", cobra.NoFileCompletions)
104105

105106
cmd.Flags().StringVar(&o.TSAServerURL, "timestamp-server-url", "",
106107
"url to the Timestamp RFC3161 server, default none. Must be the path to the API to request timestamp responses, e.g. https://freetsa.org/tsr")
108+
_ = cmd.RegisterFlagCompletionFunc("timestamp-server-url", cobra.NoFileCompletions)
107109

108110
cmd.Flags().StringVar(&o.RFC3161TimestampPath, "rfc3161-timestamp", "",
109111
"write the RFC3161 timestamp to a file")

doc/cosign_attest-blob.md

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/cosign_attest.md

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/cosign_bundle_create.md

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)