Skip to content

Commit a09500b

Browse files
Kevin WittekMeneDev
authored andcommitted
Fix broken flag parsing and add compat for multiple smart cards
1 parent 5d2e30d commit a09500b

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

hello.go

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,15 @@ func getCode() (string, error) {
297297
return "", err
298298
}
299299

300-
// Use the first reader
301-
reader := readers[0]
300+
// Use the first reader with "yubi" in its name
301+
var reader string
302+
for _, r := range readers {
303+
if strings.Contains(strings.ToLower(r), "yubi") {
304+
reader = r
305+
break
306+
}
307+
}
308+
302309
fmt.Println("Using reader:", reader)
303310

304311
// Connect to the card
@@ -571,29 +578,18 @@ func connectIfNotConnectedAndYubikeyPresent(connectionName string, usbChecker fu
571578

572579
type Options struct {
573580
ConnectionName string `required:"yes" short:"c" long:"connection" description:"The name of the connection as shown by 'nmcli c show'"`
574-
}
575-
576-
type MetaOptions struct {
577581
ShowVersion bool `required:"no" short:"v" long:"version" description:"Show version and exit"`
578582
}
579583

580584
func main() {
581-
var metaOpts MetaOptions
582-
583-
args, err := flags.Parse(&metaOpts)
584-
if err != nil {
585-
panic(err)
586-
}
585+
var opts Options
587586

588-
if metaOpts.ShowVersion {
587+
args, err := flags.Parse(&opts)
588+
if opts.ShowVersion {
589589
showVersion()
590590
os.Exit(0)
591591
}
592592

593-
var opts Options
594-
595-
args, err = flags.Parse(&opts)
596-
597593
if err != nil {
598594
panic(err)
599595
}

0 commit comments

Comments
 (0)