jawher / mow.cli

A versatile library for building CLI applications in Go
MIT License
871 stars 55 forks source link

Fix infinite loop case for envvar backed opts #50

Closed jawher closed 7 years ago

jawher commented 7 years ago

This is a regression introduced by the feature "Allow required options to be satisfied by an nev var".

The bug lies in optsMatcher, which iterates over its options, and keeps looping until no more options can match or there is no more input to feed them.

If one of the options can be satsified from an en var, it doesn't consume any input, and returns true, causing an inifinite loop.

The proposed fix is to exclude an option (in optsMatcher) whenever it has been satisfied by an env var.

gwatts commented 7 years ago

This approach is similar to the first version of the fix i had.. in the end I liked that i could replace the valueSetFromEnv hackery with something more explicit, but this is also a pretty clean solution.

Works for me with the tests I've done so far so 👍

Thanks!