From d01892150eed9d58210eb40b7c005d5fa8e93238 Mon Sep 17 00:00:00 2001 From: Gibheer Date: Sat, 1 Oct 2016 21:56:29 +0200 Subject: rework program flow This commit is a complete rebuild of pkictl. Before everything was all over the place and adding new commands was kind of a hassle. Now each command has its own file and can be adjusted on a command basis. Options are still used by the same name, but can now use different descriptions. --- create_public_key.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 create_public_key.go (limited to 'create_public_key.go') diff --git a/create_public_key.go b/create_public_key.go new file mode 100644 index 0000000..93c0677 --- /dev/null +++ b/create_public_key.go @@ -0,0 +1,26 @@ +package main + +import ( + "flag" +) + +func CreatePublicKey(args []string) error { + fs := flag.NewFlagSet("pkictl create-public-key", flag.ExitOnError) + flagPrivate := fs.String("private-key", "", "path to the private key or read from stdin") + flagOutput := fs.String("output", "stdout", "write private key to file") + fs.Parse(args) + + pk, err := loadPrivateKey(*flagPrivate) + if err != nil { + return err + } + + out, err := openOutput(*flagOutput) + if err != nil { + return err + } + defer out.Close() + + pub := pk.Public() + return writePem(pub, out) +} -- cgit v1.2.3-70-g09d2