From 4dfb29f2e07fe6fb90544ba66cf0a3df187072d9 Mon Sep 17 00:00:00 2001 From: Niall Sheridan Date: Sat, 28 May 2016 22:30:42 +0100 Subject: Use flags as defaults, allow them to override config file --- cmd/cashier/main.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'cmd/cashier/main.go') diff --git a/cmd/cashier/main.go b/cmd/cashier/main.go index 564664c..768ebcd 100644 --- a/cmd/cashier/main.go +++ b/cmd/cashier/main.go @@ -4,7 +4,6 @@ import ( "bytes" "crypto/tls" "encoding/json" - "flag" "fmt" "io/ioutil" "log" @@ -17,13 +16,18 @@ import ( "github.com/nsheridan/cashier/lib" "github.com/pkg/browser" + "github.com/spf13/pflag" "golang.org/x/crypto/ssh" "golang.org/x/crypto/ssh/agent" ) var ( - u, _ = user.Current() - cfg = flag.String("config", path.Join(u.HomeDir, ".cashier.cfg"), "Path to config file") + u, _ = user.Current() + cfg = pflag.String("config", path.Join(u.HomeDir, ".cashier.conf"), "Path to config file") + ca = pflag.String("ca", "http://localhost:10000", "CA server") + keysize = pflag.Int("key_size", 2048, "Key size. Ignored for ed25519 keys") + validity = pflag.Duration("validity", time.Hour*24, "Key validity") + keytype = pflag.String("key_type", "rsa", "Type of private key to generate - rsa, ecdsa or ed25519") ) func installCert(a agent.Agent, cert *ssh.Certificate, key key) error { @@ -102,7 +106,8 @@ func sign(pub ssh.PublicKey, token string, conf *config) (*ssh.Certificate, erro } func main() { - flag.Parse() + pflag.Parse() + c, err := readConfig(*cfg) if err != nil { log.Fatalf("Error parsing config file: %v\n", err) -- cgit v1.2.3