22// Use of this source code is governed by a BSD-style
33// license that can be found in the LICENSE file.
44
5- // +build ignore
6-
75// Generate a self-signed X.509 certificate for a TLS server. Outputs to
86// 'cert.pem' and 'key.pem' and will overwrite existing files.
97
8+ // Adapted to be used as a sub-command.
9+
1010package main
1111
1212import (
@@ -26,15 +26,17 @@ import (
2626)
2727
2828var (
29- host = flag .String ("host" , "" , "Comma-separated hostnames and IPs to generate a certificate for" )
30- validFrom = flag .String ("start-date" , "" , "Creation date formatted as Jan 1 15:04:05 2011" )
31- validFor = flag .Duration ("duration" , 365 * 24 * time .Hour , "Duration that certificate is valid for" )
32- isCA = flag .Bool ("ca" , false , "whether this cert should be its own Certificate Authority" )
33- rsaBits = flag .Int ("rsa-bits" , 2048 , "Size of RSA key to generate" )
29+ flagset = flag .NewFlagSet ("generate-cert" , flag .ExitOnError )
30+
31+ host = flagset .String ("host" , "" , "Comma-separated hostnames and IPs to generate a certificate for" )
32+ validFrom = flagset .String ("start-date" , "" , "Creation date formatted as Jan 1 15:04:05 2011" )
33+ validFor = flagset .Duration ("duration" , 365 * 24 * time .Hour , "Duration that certificate is valid for" )
34+ isCA = flagset .Bool ("ca" , false , "whether this cert should be its own Certificate Authority" )
35+ rsaBits = flagset .Int ("rsa-bits" , 2048 , "Size of RSA key to generate" )
3436)
3537
36- func main ( ) {
37- flag .Parse ()
38+ func GenerateCertMain ( args [] string ) {
39+ flagset .Parse (args )
3840
3941 if len (* host ) == 0 {
4042 log .Fatalf ("Missing required --host parameter" )
0 commit comments