Permalink
Browse files

Update getopt

  • Loading branch information...
1 parent ac5948d commit a3615a4b82159b1c0e31b6bee250269ebc66ae27 @tuncer tuncer committed Jan 23, 2011
Showing with 13 additions and 6 deletions.
  1. +13 −6 src/getopt.erl
View
@@ -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).

0 comments on commit a3615a4

Please sign in to comment.