Skip to content

Commit 8c2605e

Browse files
committed
fix: filter shell filename completions to appropriate extensions
Signed-off-by: Ville Skyttä <[email protected]>
1 parent 988b7fd commit 8c2605e

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

cli/slsa-verifier/verify.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ func verifyArtifactCmd() *cobra.Command {
7272
o.AddFlags(cmd)
7373
// --provenance-path must be supplied when verifying an artifact.
7474
cmd.MarkFlagRequired("provenance-path")
75+
cmd.MarkFlagFilename("provenance-path", verify.CommonFilenameExtensions...)
7576
return cmd
7677
}
7778

@@ -137,6 +138,12 @@ func verifyNpmPackageCmd() *cobra.Command {
137138
}
138139
return nil
139140
},
141+
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
142+
if len(args) != 0 {
143+
return nil, cobra.ShellCompDirectiveNoFileComp
144+
}
145+
return []string{"tgz"}, cobra.ShellCompDirectiveFilterFileExt
146+
},
140147
Short: "Verifies SLSA provenance for an npm package tarball [experimental]",
141148
Run: func(cmd *cobra.Command, args []string) {
142149
v := verify.VerifyNpmPackageCommand{

cli/slsa-verifier/verify/options.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ type VerifyOptions struct {
4545

4646
var _ Interface = (*VerifyOptions)(nil)
4747

48+
var CommonFilenameExtensions = []string{"sigstore", "intoto", "intoto.jsonl", "json"}
49+
4850
// AddFlags implements Interface.
4951
func (o *VerifyOptions) AddFlags(cmd *cobra.Command) {
5052
/* Builder options */
@@ -73,6 +75,7 @@ func (o *VerifyOptions) AddFlags(cmd *cobra.Command) {
7375
/* Other options */
7476
cmd.Flags().StringVar(&o.ProvenancePath, "provenance-path", "",
7577
"path to a provenance file")
78+
cmd.MarkFlagFilename("provenance-path", CommonFilenameExtensions...)
7679

7780
cmd.Flags().StringVar(&o.ProvenanceRepository, "provenance-repository", "",
7881
"image repository for provenance with format: <registry>/<repository>")
@@ -123,6 +126,7 @@ func (o *VerifyNpmOptions) AddFlags(cmd *cobra.Command) {
123126

124127
cmd.Flags().StringVar(&o.AttestationsPath, "attestations-path", "",
125128
"path to a file containing the attestations")
129+
cmd.MarkFlagFilename("attestations-path", CommonFilenameExtensions...)
126130

127131
cmd.Flags().StringVar(&o.PackageName, "package-name", "",
128132
"the package name")
@@ -164,6 +168,7 @@ func (o *VerifyVSAOptions) AddFlags(cmd *cobra.Command) {
164168

165169
cmd.Flags().StringVar(&o.AttestationPath, "attestation-path", "",
166170
"path to a file containing the attestation")
171+
cmd.MarkFlagFilename("attestation-path", CommonFilenameExtensions...)
167172

168173
cmd.Flags().StringVar(&o.VerifierID, "verifier-id", "",
169174
"the unique verifier ID who created the attestation")
@@ -182,6 +187,7 @@ func (o *VerifyVSAOptions) AddFlags(cmd *cobra.Command) {
182187

183188
cmd.Flags().StringVar(&o.PublicKeyPath, "public-key-path", "",
184189
"path to a public key file")
190+
cmd.MarkFlagFilename("public-key-path", "pem")
185191

186192
cmd.Flags().StringVar(&o.PublicKeyID, "public-key-id", "",
187193
"[optional] the ID of the public key, defaults to the SHA256 digest of the base64-encoded public key")

0 commit comments

Comments
 (0)