Skip to content

Commit ac0b3d0

Browse files
committed
Add PEM output mode
1 parent bcaa29c commit ac0b3d0

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

cmd/export.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import (
66
"context"
77
"encoding/hex"
88
"encoding/json"
9+
"encoding/pem"
910
"fmt"
11+
"os"
1012
"time"
1113

1214
"github.com/fatih/color"
@@ -119,6 +121,13 @@ func newExport(ctx context.Context) *cobra.Command {
119121
}
120122

121123
fmt.Println(string(m))
124+
} else if outOpts.Mode == options.OutputModePEM {
125+
for _, cert := range parsedCertificates.Found {
126+
pem.Encode(os.Stdout, &pem.Block{
127+
Type: "CERTIFICATE",
128+
Bytes: cert.Certificate.Raw,
129+
})
130+
}
122131
}
123132

124133
return nil

cmd/options/outputs.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,15 @@ const (
1313
OutputModePretty = "pretty"
1414
OutputModeJSON = "json"
1515
OutputModeWide = "wide"
16+
OutputModePEM = "pem"
1617
)
1718

18-
var outputModes = []string{OutputModePretty, OutputModeJSON, OutputModeWide}
19+
var outputModes = []string{
20+
OutputModePretty,
21+
OutputModeJSON,
22+
OutputModeWide,
23+
OutputModePEM,
24+
}
1925

2026
// Output are options for configuring command outputs.
2127
type Output struct {

0 commit comments

Comments
 (0)