Skip to content

Commit 302c4eb

Browse files
Add wide output mode for export (#48)
2 parents adade5a + 69e3455 commit 302c4eb

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

cmd/export.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,28 @@ func newExport(ctx context.Context) *cobra.Command {
4747
return err
4848
}
4949

50-
if outOpts.Mode == options.OutputModePretty {
50+
if outOpts.Mode == options.OutputModePretty || outOpts.Mode == options.OutputModeWide {
51+
wide := outOpts.Mode == options.OutputModeWide
5152
headerFmt := color.New(color.FgGreen, color.Underline).SprintfFunc()
5253
columnFmt := color.New(color.FgYellow).SprintfFunc()
5354

54-
tbl := table.New("File Location", "Parser", "Subject", "Not Before", "Not After", "SHA-256")
55+
var tbl table.Table
56+
if wide {
57+
tbl = table.New("File Location", "Parser", "Subject", "Not Before", "Not After", "SHA-256")
58+
} else {
59+
tbl = table.New("File Location", "Subject")
60+
}
5561
tbl.WithHeaderFormatter(headerFmt).WithFirstColumnFormatter(columnFmt)
5662

5763
for _, cert := range parsedCertificates.Found {
58-
tbl.AddRow(cert.Location, cert.Parser, cert.Certificate.Subject,
59-
cert.Certificate.NotBefore.Format(time.RFC3339),
60-
cert.Certificate.NotAfter.Format(time.RFC3339),
61-
hex.EncodeToString(cert.FingerprintSha256[:]))
64+
if wide {
65+
tbl.AddRow(cert.Location, cert.Parser, cert.Certificate.Subject,
66+
cert.Certificate.NotBefore.Format(time.RFC3339),
67+
cert.Certificate.NotAfter.Format(time.RFC3339),
68+
hex.EncodeToString(cert.FingerprintSha256[:]))
69+
} else {
70+
tbl.AddRow(cert.Location, cert.Certificate.Subject)
71+
}
6272
}
6373

6474
tbl.Print()

cmd/options/outputs.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ import (
1212
const (
1313
OutputModePretty = "pretty"
1414
OutputModeJSON = "json"
15+
OutputModeWide = "wide"
1516
)
1617

17-
var outputModes = []string{OutputModePretty, OutputModeJSON}
18+
var outputModes = []string{OutputModePretty, OutputModeJSON, OutputModeWide}
1819

1920
// Output are options for configuring command outputs.
2021
type Output struct {

cmd/validate.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
func newValidation(ctx context.Context) *cobra.Command {
2020
var (
2121
imgOpts *options.Image
22-
outOpts *options.Output
2322
valOpts *options.Validation
2423
)
2524

@@ -34,7 +33,7 @@ paranoia validate alpine:latest --config some-config.yaml`,
3433
if err := options.MustSingleImageArgs(args); err != nil {
3534
return err
3635
}
37-
return outOpts.Validate()
36+
return nil
3837
},
3938
RunE: func(cmd *cobra.Command, args []string) error {
4039
validateConfig, err := validate.LoadConfig(valOpts.Config)
@@ -117,7 +116,6 @@ paranoia validate alpine:latest --config some-config.yaml`,
117116
}
118117

119118
imgOpts = options.RegisterImage(cmd)
120-
outOpts = options.RegisterOutputs(cmd)
121119
valOpts = options.RegisterValidation(cmd)
122120

123121
return cmd

0 commit comments

Comments
 (0)