Skip to content

Commit

Permalink
Fix broken flag parsing and add compat for multiple smart cards
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Wittek authored and MeneDev committed Jul 10, 2018
1 parent 5d2e30d commit a09500b
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions hello.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit a09500b

Please sign in to comment.