Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: shell completion improvements #831

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

scop
Copy link
Contributor

@scop scop commented Feb 11, 2025

See individual commits and their messages for details.

@scop scop requested a review from a team as a code owner February 11, 2025 22:32

cmd.Flags().StringVar(&o.AttestationPath, "attestation-path", "",
"path to a file containing the attestation")
cmd.MarkFlagFilename("attestation-path", "intoto.jsonl")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The filename can actually have any extension.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, removed this filter.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, also remove it for the other subcommands.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see we can actually specify multiple extensions, so how about using the common ones: .sigstore, .intoto, .intoto.jsonl, .json.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done for both related flags. Thanks for the guidance, I'm familiar with cobra but not that much with all things SLSA.

I suppose it should be noted that at least with bash (well readline more accurately), the user can invoke completion of all filenames by hitting Meta-/ (typically Esc-/) instead of Tab. Even though that's a bit inconvenient and not too well known combo, at least there is an escape hatch if we get some of the file extension filters wrong.

@@ -145,27 +162,34 @@ var _ Interface = (*VerifyVSAOptions)(nil)
func (o *VerifyVSAOptions) AddFlags(cmd *cobra.Command) {
cmd.Flags().StringArrayVar(&o.SubjectDigests, "subject-digest", []string{},
"the digests to be verified. Pass multiple digests by repeating the flag. e.g. --subject-digest <digest type>:<digest value> --subject-digest <digest type>:<digest value>")
cmd.RegisterFlagCompletionFunc("subject-digest", cobra.NoFileCompletions)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't add this line, would the behavior be the same?

Copy link
Contributor Author

@scop scop Feb 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No; without it, all filenames in the current dir will be suggested as arguments for the flag.

@scop scop force-pushed the fix/shell-completions branch 2 times, most recently from 589b2f3 to 4134a9b Compare February 12, 2025 21:02
Comment on lines +142 to +144
if len(args) != 0 {
return nil, cobra.ShellCompDirectiveNoFileComp
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works like a shortcut to say that all of options shouldn't offer completion?

Copy link
Contributor Author

@scop scop Feb 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It means that if we already have one or more positional argument, do not offer any more as completions, as verify-npm-package takes only one positional argument.

@scop scop force-pushed the fix/shell-completions branch from 4134a9b to 7aedf88 Compare February 12, 2025 21:56
Copy link
Contributor

@ramonpetgrave64 ramonpetgrave64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks okay so far.

Remember to signoff your commits.

@@ -45,31 +45,41 @@ type VerifyOptions struct {

var _ Interface = (*VerifyOptions)(nil)

var CommonFilenameExtensions = []string{"sigstore", "intoto", "intoto.jsonl", "json"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var CommonFilenameExtensions = []string{"sigstore", "intoto", "intoto.jsonl", "json"}
var CommonAttestationFilenameExtensions = []string{"sigstore", "intoto", "intoto.jsonl", "json"}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also being used for provenance filenames per earlier comments. Do we still want to rename it as suggested?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, provenance and attestation are mostly interchangeable terms, but attestation is more generic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@scop scop force-pushed the fix/shell-completions branch from 7aedf88 to 8c2605e Compare February 14, 2025 20:17
@scop
Copy link
Contributor Author

scop commented Feb 14, 2025

Remember to signoff your commits.

Done. This would be useful info to have in docs/CONTRIBUTING.md

scop added 3 commits February 14, 2025 23:13
Subject digests are not given as positional arguments, but with
--subject-digest flags.

Signed-off-by: Ville Skyttä <ville.skytta@iki.fi>
Signed-off-by: Ville Skyttä <ville.skytta@iki.fi>
Signed-off-by: Ville Skyttä <ville.skytta@iki.fi>
@scop scop force-pushed the fix/shell-completions branch from 8c2605e to d7880e2 Compare February 14, 2025 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants