-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove redundant call of usage message #250
Conversation
9cd69e5
to
d460b29
Compare
lib/cli.ex
Outdated
working_dir = Keyword.get(switches, :working_dir, File.cwd!()) | ||
module.main(working_dir) | ||
else | ||
:error -> usage_message() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would question the order: OptionParser.parse
is first in the with
clause, followed by Map.fetch
. Yet the order In else
matches the Map.fetch
failure first and then the OptionParser.parse
ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Glutexo I had same idea today :D :D, yes it just a detail but could be nice
lib/cli.ex
Outdated
:error -> usage_message() | ||
{_, _, [_ | _]} -> usage_message() | ||
{_, argv, _} when length(argv) != 1 -> usage_message() | ||
_ -> usage_message() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we handle all cases then the not defined may not be catch
lib/cli.ex
Outdated
{_, _, [_ | _]} -> usage_message() | ||
{_, argv, _} when length(argv) != 1 -> usage_message() | ||
:error -> usage_message() | ||
_ -> usage_message() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now, all cases are covered by the explicit patterns
{_, _, [_ | _]}
(invalid switches),{_, argv, _} (invalid argument number)
,- and
:error
(invalid component).
Universal _
would silently swallow any unexpected value. In that case we rather want an error to be raised.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DRY if it is not necessary, then dont call function more than once.