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

Feat/file flag completion improvements #4028

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

Conversation

scop
Copy link

@scop scop commented Jan 30, 2025

Summary

As described in sigstore/community#538

To test, generate and install shell completions and invoke completion for flags taking filenames as arguments, observe results.

Release Note

NONE

Documentation

NONE

Signed-off-by: Ville Skyttä <ville.skytta@iki.fi>
Copy link

codecov bot commented Feb 1, 2025

Codecov Report

Attention: Patch coverage is 0% with 73 lines in your changes missing coverage. Please review.

Project coverage is 36.76%. Comparing base (2ef6022) to head (b6ac9b3).
Report is 300 commits behind head on main.

Files with missing lines Patch % Lines
cmd/cosign/cli/options/sign.go 0.00% 12 Missing ⚠️
cmd/cosign/cli/options/signblob.go 0.00% 9 Missing ⚠️
cmd/cosign/cli/options/attest_blob.go 0.00% 8 Missing ⚠️
cmd/cosign/cli/options/bundle.go 0.00% 8 Missing ⚠️
cmd/cosign/cli/options/certificate.go 0.00% 5 Missing ⚠️
cmd/cosign/cli/options/trustedroot.go 0.00% 5 Missing ⚠️
cmd/cosign/cli/options/verify.go 0.00% 4 Missing ⚠️
cmd/cosign/cli/options/attest.go 0.00% 3 Missing ⚠️
cmd/cosign/cli/options/registry.go 0.00% 3 Missing ⚠️
cmd/cosign/cli/options/import_key_pair.go 0.00% 2 Missing ⚠️
... and 12 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4028      +/-   ##
==========================================
- Coverage   40.10%   36.76%   -3.35%     
==========================================
  Files         155      210      +55     
  Lines       10044    13386    +3342     
==========================================
+ Hits         4028     4921     +893     
- Misses       5530     7847    +2317     
- Partials      486      618     +132     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

haydentherapper
haydentherapper previously approved these changes Feb 3, 2025
Copy link
Contributor

@haydentherapper haydentherapper left a comment

Choose a reason for hiding this comment

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

Thank you! Just one question

@@ -107,5 +108,5 @@ func (o *AttestBlobOptions) AddFlags(cmd *cobra.Command) {

cmd.Flags().StringVar(&o.RFC3161TimestampPath, "rfc3161-timestamp-bundle", "",
"path to an RFC 3161 timestamp bundle FILE")
_ = cmd.Flags().SetAnnotation("rfc3161-timestamp-bundle", cobra.BashCompFilenameExt, []string{})
// _ = cmd.MarkFlagFilename("rfc3161-timestamp-bundle") // no typical extensions
Copy link
Contributor

Choose a reason for hiding this comment

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

To confirm, is there any purpose to including this? As in, will shell completion still work with rfc3161-... for example?

Copy link
Author

@scop scop Feb 9, 2025

Choose a reason for hiding this comment

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

This is discussed in detail in the b6ac9b3 commit message.

Copy link
Author

Choose a reason for hiding this comment

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

But TL;DR: yes :)

@@ -80,7 +80,7 @@ func (o *AttachSBOMOptions) AddFlags(cmd *cobra.Command) {

cmd.Flags().StringVar(&o.SBOM, "sbom", "",
"path to the sbom, or {-} for stdin")
_ = cmd.Flags().SetAnnotation("sbom", cobra.BashCompFilenameExt, []string{})
cmd.MarkFlagFilename("sbom", sbomExts...)
Copy link
Contributor

Choose a reason for hiding this comment

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

fix lint here

Copy link
Author

Choose a reason for hiding this comment

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

Done.

Be more consistent across with extensions accepted/filtered, add some.

Also, mark and comment out cases where there are no known typical
filename extensions for flags taking filename arguments, to make it
obvious that they have not been inadvertently omitted. Marking a flag as
filename without specifying extensions is a no-op, and actually
considered a bug per commentary in cobra sources:
https://github.com/spf13/cobra/blob/41b26ec8bb59dfba580f722201bf371c4f5703dd/completions.go#L387-L390

Closes sigstore/community#538

Signed-off-by: Ville Skyttä <ville.skytta@iki.fi>
@scop scop force-pushed the feat/file-flag-completion-improvements branch from aa5537c to b6ac9b3 Compare February 9, 2025 12:26
@scop scop requested a review from a team as a code owner February 9, 2025 12:26
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