Repository navigation
Expand file tree
/
Copy pathroot.go
More file actions
77 lines (62 loc) · 1.8 KB
/
Copy pathroot.go
File metadata and controls
77 lines (62 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package cmd
import (
"fmt"
"github.com/spf13/cobra"
)
var version = "0.1.6"
var (
versionFlag bool
jsonOutput bool
)
var rootCmd = &cobra.Command{
Use: "cert",
Short: "A user-friendly CLI tool for certificate management",
Long: `cert (from certwiz) is a user-friendly CLI tool for certificate management.
Similar to HTTPie but for certificates.
Examples:
# Inspect a certificate file
cert inspect cert.pem
cert inspect cert.der --full
# Inspect a website's certificate
cert inspect google.com
cert inspect https://example.com:8443
# Generate a self-signed certificate
cert generate --cn example.com
cert generate --cn myserver --san example.com --san *.example.com --san IP:192.168.1.1
# Convert certificate formats
cert convert cert.pem cert.der --format der
cert convert cert.der cert.pem --format pem
# Verify a certificate
cert verify cert.pem
cert verify cert.pem --host example.com`,
Run: func(cmd *cobra.Command, args []string) {
if versionFlag {
fmt.Printf("cert version %s\n", version)
return
}
_ = cmd.Help()
},
}
// Execute adds all child commands to the root command and sets flags appropriately.
func Execute() error {
return rootCmd.Execute()
}
func init() {
// Add global flags
rootCmd.PersistentFlags().BoolVar(&jsonOutput, "json", false, "Output in JSON format")
// Add version flag
rootCmd.Flags().BoolVarP(&versionFlag, "version", "v", false, "Print version information")
// Add subcommands
rootCmd.AddCommand(inspectCmd)
rootCmd.AddCommand(generateCmd)
rootCmd.AddCommand(convertCmd)
rootCmd.AddCommand(verifyCmd)
rootCmd.AddCommand(versionCmd)
}
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version of cert",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("cert version %s\n", version)
},
}