From a3615a4b82159b1c0e31b6bee250269ebc66ae27 Mon Sep 17 00:00:00 2001 From: Tuncer Ayaz Date: Sun, 23 Jan 2011 16:05:25 +0100 Subject: Update getopt --- src/getopt.erl | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/getopt.erl b/src/getopt.erl index 5f9fe61..35e19ec 100644 --- a/src/getopt.erl +++ b/src/getopt.erl @@ -13,6 +13,13 @@ -export([parse/2, usage/2, usage/3, usage/4]). +-export_type([arg_type/0, + arg_value/0, + arg_spec/0, + simple_option/0, + compound_option/0, + option/0, + option_spec/0]). -define(TAB_LENGTH, 8). %% Indentation of the help messages in number of tabs. @@ -114,7 +121,7 @@ parse_option_long(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptStr, OptArg) -> case lists:keyfind(Long, ?OPT_LONG, OptSpecList) of {Name, _Short, Long, undefined, _Help} -> parse(OptSpecList, [Name | OptAcc], ArgAcc, ArgPos, Args); - + {_Name, _Short, Long, _ArgSpec, _Help} = OptSpec -> % The option argument string is empty, but the option requires % an argument, so we look into the next string in the list. @@ -217,7 +224,7 @@ parse_option_next_arg(OptSpecList, OptAcc, ArgAcc, ArgPos, [] = Args, {Name, _Sh _ -> throw({error, {missing_option_arg, Name}}) end. - + %% @doc Find the option for the discrete argument in position specified in the %% Pos argument. @@ -318,7 +325,7 @@ is_arg_true(Arg) -> (Arg =:= "on") orelse (Arg =:= "enabled") orelse (Arg =:= "1"). - + -spec is_arg_false(string()) -> boolean(). is_arg_false(Arg) -> (Arg =:= "false") orelse (Arg =:= "f") orelse @@ -362,7 +369,7 @@ is_float_arg([_Head | _Tail]) -> false; is_float_arg([]) -> true. - + %% @doc Show a message on stdout indicating the command line options and %% arguments that are supported by the program. @@ -441,8 +448,8 @@ usage_options(OptSpecList) -> lists:flatten(lists:reverse(usage_options_reverse(OptSpecList, []))). usage_options_reverse([{Name, Short, Long, _ArgSpec, Help} | Tail], Acc) -> - Prefix = - case Long of + Prefix = + case Long of undefined -> case Short of % Neither short nor long form (non-option argument). -- cgit v1.1