Added edoc comments.

This commit is contained in:
Juan Jose Comellas 2009-10-05 17:09:04 -03:00
parent 35395b82e8
commit cc6bf5810a

View File

@ -2,27 +2,34 @@
%%% @author Juan Jose Comellas <jcomellas@novamens.com> %%% @author Juan Jose Comellas <jcomellas@novamens.com>
%%% @copyright (C) 2009, Novamens SA (http://www.novamens.com) %%% @copyright (C) 2009, Novamens SA (http://www.novamens.com)
%%% @doc Parses command line options with a format similar to that of GNU getopt. %%% @doc Parses command line options with a format similar to that of GNU getopt.
%%% @end
%%%------------------------------------------------------------------- %%%-------------------------------------------------------------------
-module(getopt). -module(getopt).
%% @headerfile getopt.hrl
-include("getopt.hrl"). -include("getopt.hrl").
-define(TAB_LENGTH, 8). -define(TAB_LENGTH, 8).
-define(HELP_INDENTATION, 4 * ?TAB_LENGTH). -define(HELP_INDENTATION, 4 * ?TAB_LENGTH).
-type option() :: atom() | {atom(), any()}. %% @type option() = atom() | {atom(), getopt_arg()}. Option type and optional default argument.
-type option_spec() :: [#option{}]. -type option() :: atom() | {atom(), getopt_arg()}.
-type option_list() :: [option()]. %% @type option_spec() = [#option{}]. Command line options specification.
-type arg_list() :: [atom() | binary() | boolean() | float() | integer() | string()]. -type option_spec() :: [#option{}].
%% @type option_list() = [option()]. List of option types.
-type option_list() :: [option()].
%% @type arg_list() = [getopt_arg()]. List of arguments returned to the calling function.
-type arg_list() :: [getopt_arg()].
-export([parse/2, usage/2]). -export([parse/2, usage/2]).
-spec parse(option_spec(), [string()]) -> option_list(). -spec parse(option_spec(), [string()]) -> option_list().
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc Parse the command line options and arguments returning a list of tuples %% @spec parse(OptSpec::option_spec(), Args::[string()]) -> option_list().
%% and/or atoms using the Erlang convention for sending options to a %% @doc Parse the command line options and arguments returning a list of tuples
%% function. %% and/or atoms using the Erlang convention for sending options to a
%% function.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
parse(OptSpec, Args) -> parse(OptSpec, Args) ->
catch parse(OptSpec, [], [], Args). catch parse(OptSpec, [], [], Args).
@ -157,8 +164,9 @@ to_type(_Type, Arg) ->
-spec usage(option_spec(), string()) -> ok. -spec usage(option_spec(), string()) -> ok.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc Show a message on stdout indicating the command line options and %% @spec usage(OptSpec :: option_spec(), ProgramName :: string()) -> ok.
%% arguments that are supported by the program. %% @doc Show a message on stdout indicating the command line options and
%% arguments that are supported by the program.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
usage(OptSpec, ProgramName) -> usage(OptSpec, ProgramName) ->
io:format("Usage: ~s~s~n~n~s~n", [ProgramName, usage_cmd_line(OptSpec), usage_options(OptSpec)]). io:format("Usage: ~s~s~n~n~s~n", [ProgramName, usage_cmd_line(OptSpec), usage_options(OptSpec)]).