-
Notifications
You must be signed in to change notification settings - Fork 86
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
refactor: extract inspect rendering logic to be display handlers #1150
base: main
Are you sure you want to change the base?
refactor: extract inspect rendering logic to be display handlers #1150
Conversation
Signed-off-by: Junjie Gao <junjiegao@microsoft.com>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1150 +/- ##
==========================================
+ Coverage 73.30% 74.48% +1.18%
==========================================
Files 53 60 +7
Lines 3240 3363 +123
==========================================
+ Hits 2375 2505 +130
+ Misses 671 664 -7
Partials 194 194 ☔ View full report in Codecov by Sentry. |
Signed-off-by: Junjie Gao <junjiegao@microsoft.com>
Signed-off-by: Junjie Gao <junjiegao@microsoft.com>
Signed-off-by: Junjie Gao <junjiegao@microsoft.com>
Signed-off-by: Junjie Gao <junjiegao@microsoft.com>
Signed-off-by: Junjie Gao <junjiegao@microsoft.com>
Signed-off-by: Junjie Gao <junjiegao@microsoft.com>
Signed-off-by: Junjie Gao <junjiegao@microsoft.com>
Signed-off-by: Junjie Gao <junjiegao@microsoft.com>
Signed-off-by: Junjie Gao <junjiegao@microsoft.com>
Signed-off-by: Junjie Gao <junjiegao@microsoft.com>
Signed-off-by: Junjie Gao <junjiegao@microsoft.com>
"github.com/spf13/pflag" | ||
) | ||
|
||
type FormatType string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code style: require docs on exposed type
func (f *Format) ApplyFlags(fs *pflag.FlagSet) { | ||
var quotedAllowedTypes []string | ||
for _, t := range f.allowedTypes { | ||
quotedAllowedTypes = append(quotedAllowedTypes, fmt.Sprintf("'%s'", t)) | ||
} | ||
usage := fmt.Sprintf("output format, options: %s", strings.Join(quotedAllowedTypes, ", ")) | ||
// apply flags | ||
fs.StringVar(&f.FormatFlag, "output", f.FormatFlag, usage) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: we need to enhance this later in v2
// Common option struct. | ||
type Common struct { | ||
Printer *output.Printer | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will you refactor --debug
in later PRs?
if err := opts.Format.Parse(cmd); err != nil { | ||
return err | ||
} | ||
if err := opts.Common.Parse(cmd); err != nil { | ||
return err | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OnReferenceResolved(reference, mediaType string) | ||
|
||
// InspectSignature inspects a signature to get it ready to be rendered. | ||
InspectSignature(digest string, envelopeMediaType string, sigEnvelope signature.Envelope) error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is not updated as expected as #1150 (comment)
Note: It is OK to pass the related object which is not fully printed.
printer *output.Printer | ||
|
||
root *tree.Node | ||
cncfSigNode *tree.Node |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The field name cncfSigNode
is confusing. Let's consider a better name.
// mediaType is a no-op for this handler. | ||
func (h *InspectHandler) OnReferenceResolved(reference, mediaType string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// mediaType is a no-op for this handler. | |
func (h *InspectHandler) OnReferenceResolved(reference, mediaType string) { | |
func (h *InspectHandler) OnReferenceResolved(reference, _ string) { |
if h.root == nil || h.cncfSigNode == nil { | ||
return fmt.Errorf("artifact reference is not set") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are not reachable, aren't they?
if h.root == nil { | ||
return fmt.Errorf("artifact reference is not set") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are not reachable, aren't they?
// | ||
// mediaType is a no-op for this handler. | ||
func (h *InspectHandler) OnReferenceResolved(reference, mediaType string) { | ||
if h.root == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is unnecessary to check h.root
.
Refactor:
json
andtree
inspect handlers.Fix:
tree
output, make the key names with multiple words separated by space characters rather than capitalizing the words, which is defined in the inspect command spec.json
output, default to rendering time in RFC3339 with nanoseconds (Notation expiry, signing time and certificate expiry are accurate to 1 second. Timestamp RFC 3161 can have fraction-of-second time value).Test:
Resolves part of #1151