From a09500bb4d597d6c345f266bb1e9195bb7391a85 Mon Sep 17 00:00:00 2001 From: Kevin Wittek Date: Fri, 6 Jul 2018 12:51:12 +0200 Subject: [PATCH] Fix broken flag parsing and add compat for multiple smart cards --- hello.go | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/hello.go b/hello.go index d265fe8..0563228 100644 --- a/hello.go +++ b/hello.go @@ -297,8 +297,15 @@ func getCode() (string, error) { return "", err } - // Use the first reader - reader := readers[0] + // Use the first reader with "yubi" in its name + var reader string + for _, r := range readers { + if strings.Contains(strings.ToLower(r), "yubi") { + reader = r + break + } + } + fmt.Println("Using reader:", reader) // Connect to the card @@ -571,29 +578,18 @@ func connectIfNotConnectedAndYubikeyPresent(connectionName string, usbChecker fu type Options struct { ConnectionName string `required:"yes" short:"c" long:"connection" description:"The name of the connection as shown by 'nmcli c show'"` -} - -type MetaOptions struct { ShowVersion bool `required:"no" short:"v" long:"version" description:"Show version and exit"` } func main() { - var metaOpts MetaOptions - - args, err := flags.Parse(&metaOpts) - if err != nil { - panic(err) - } + var opts Options - if metaOpts.ShowVersion { + args, err := flags.Parse(&opts) + if opts.ShowVersion { showVersion() os.Exit(0) } - var opts Options - - args, err = flags.Parse(&opts) - if err != nil { panic(err) }