Skip to content
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

Merged
merged 6 commits into from
Dec 17, 2024

Conversation

nappex
Copy link
Collaborator

@nappex nappex commented Nov 9, 2024

DRY if it is not necessary, then dont call function more than once.

lib/cli.ex Outdated Show resolved Hide resolved
lib/cli.ex Show resolved Hide resolved
lib/cli.ex Outdated Show resolved Hide resolved
@nappex nappex force-pushed the remove-redundant-usage_msg branch from 9cd69e5 to d460b29 Compare November 30, 2024 17:20
lib/cli.ex Outdated
working_dir = Keyword.get(switches, :working_dir, File.cwd!())
module.main(working_dir)
else
:error -> usage_message()
Copy link
Owner

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.

Copy link
Collaborator Author

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 Show resolved Hide resolved
lib/cli.ex Show resolved Hide resolved
lib/cli.ex Outdated
:error -> usage_message()
{_, _, [_ | _]} -> usage_message()
{_, argv, _} when length(argv) != 1 -> usage_message()
_ -> usage_message()
Copy link
Collaborator Author

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()
Copy link
Owner

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.

Copy link
Owner

@Glutexo Glutexo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Glutexo Glutexo merged commit c0a743a into Glutexo:master Dec 17, 2024
1 check passed
@Glutexo Glutexo deleted the remove-redundant-usage_msg branch December 17, 2024 16:51
@Glutexo Glutexo restored the remove-redundant-usage_msg branch December 17, 2024 16:56
@nappex nappex deleted the remove-redundant-usage_msg branch December 17, 2024 16:56
@nappex nappex mentioned this pull request Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants