Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Optparse handle missing arg #24

Merged
1 commit merged into from

1 participant

@jlouis

Handle missing args in option parsing.

@jlouis jlouis Improve error handling, be meaningful on missing opt args.
When missing an option argument, the system normally died. This prints
out a helpful error message in the event. It also slightly reorders
the option parsing, so it takes place before the start()/stop()
sequence. In principle this lets us bail out faster.
9308415
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 28, 2011
  1. @jlouis

    Improve error handling, be meaningful on missing opt args.

    jlouis authored
    When missing an option argument, the system normally died. This prints
    out a helpful error message in the event. It also slightly reorders
    the option parsing, so it takes place before the start()/stop()
    sequence. In principle this lets us bail out faster.
This page is out of date. Refresh to see the latest.
Showing with 8 additions and 4 deletions.
  1. +8 −4 src/agner_main.erl
View
12 src/agner_main.erl
@@ -72,10 +72,14 @@ usage() ->
main(Args) ->
case parse_args(Args) of
{arg, Command, ExtraArgs, OptSpec} ->
- start(),
- {ok, {Opts, _}} = getopt:parse(OptSpec, ExtraArgs),
- handle_command(Command, Opts),
- stop();
+ case getopt:parse(OptSpec, ExtraArgs) of
+ {ok, {Opts, _}} ->
+ start(),
+ handle_command(Command, Opts),
+ stop();
+ {error, {missing_option_arg, Arg}} ->
+ io:format("Error: Missing option argument for '~p'~n", [Arg])
+ end;
no_parse ->
usage()
end.
Something went wrong with that request. Please try again.