We truncated the diff of some files because they were too big.
If you want to see the full diff for every file, click here.
Changes of Revision 3
erlang-getopt.spec
Changed
x
1
2
3
4
Name: erlang-%{realname}
5
-Version: 0.8.2
6
-Release: 2%{?dist}
7
+Version: 1.0.1
8
+Release: 1%{?dist}
9
Summary: Erlang module to parse command line arguments using the GNU getopt syntax
10
Group: Development/Libraries
11
License: BSD
12
13
14
15
%changelog
16
+* Thu Jul 19 2018 Jeroen van Meeuwen <vanmeeuwen@kolabsys.com> - 1.0.1-1
17
+- Check in version 1.0.1
18
+
19
* Wed Jun 17 2015 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 0.8.2-2
20
- Rebuilt for https://fedoraproject.org/wiki/Fedora_23_Mass_Rebuild
21
22
debian.changelog
Changed
11
1
2
+erlang-getopt (1.0.1-1) unstable; urgency=low
3
+
4
+ * Check in version 1.0.1
5
+
6
+ -- Jeroen van Meeuwen <vanmeeuwen@kolabsys.com> Thu, 19 Jul 2018 23:33:46 +0900
7
+
8
erlang-getopt (0.8.2+dfsg-1) unstable; urgency=low
9
10
* Initial release. (Closes: #800565)
11
erlang-getopt.dsc
Changed
17
1
2
Source: erlang-getopt
3
Binary: erlang-getopt
4
Architecture: any
5
-Version: 0.8.2+dfsg-1
6
+Version: 1.0.1-1
7
Maintainer: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>
8
Uploaders: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>
9
Homepage: https://github.com/jcomellas/getopt
10
11
Package-List:
12
erlang-getopt deb devel optional arch=any
13
Files:
14
- 00000000000000000000000000000000 0 getopt-0.8.2.tar.gz
15
+ 00000000000000000000000000000000 0 getopt-1.0.1.tar.gz
16
00000000000000000000000000000000 0 debian.tar.gz
17
getopt-0.8.2.tar.gz/rebar
Deleted
getopt-0.8.2.tar.gz/Makefile -> getopt-1.0.1.tar.gz/Makefile
Changed
44
1
2
APPLICATION := getopt
3
4
-REBAR=$(shell which rebar || echo ./rebar)
5
-ERL := erl
6
-EPATH := -pa ebin
7
-
8
-DIALYZER=dialyzer
9
-DIALYZER_OPTS=-Wno_return -Wrace_conditions -Wunderspecs -Wno_undefined_callbacks --fullpath
10
-
11
-.PHONY: all clean compile console dialyze doc test
12
+.PHONY: all clean compile dialyzer edoc shell test
13
14
all: compile
15
16
clean:
17
- @$(REBAR) clean
18
+ @rebar3 clean
19
20
compile:
21
- @$(REBAR) compile
22
+ @rebar3 compile
23
24
-console:
25
- $(ERL) -sname $(APPLICATION) $(EPATH)
26
+dialyzer: compile
27
+ @rebar3 dialyzer
28
29
-dialyze: compile
30
- @$(DIALYZER) $(DIALYZER_OPTS) -r ./
31
+edoc:
32
+ @rebar3 edoc
33
34
-doc:
35
- @$(REBAR) doc
36
+shell:
37
+ @rebar3 shell
38
39
test:
40
- @erl -make
41
- @$(ERL) -sname $(APPLICATION) $(EPATH) -noinput -s getopt_test test -s init stop
42
+ @rebar3 eunit
43
44
getopt-0.8.2.tar.gz/README.md -> getopt-1.0.1.tar.gz/README.md
Changed
201
1
2
------------
3
4
You should only need a somewhat recent version of Erlang/OTP. The module has
5
-been tested with Erlang R13B, R14B, R15B and R16B.
6
-
7
-You also need a recent version of rebar(http://github.com/basho/rebar) in
8
-the system path. If you're going to run the unit tests you need the latest
9
-version of rebar to make sure that the latest version of *getopt* is being
10
-used. rebar already includes a compiled copy of the ``getopt`` module in its
11
-own binary file and will give precedence to its own modules over the ones in
12
-the project.
13
+been tested with all versions of Erlang starting with R13B and ending with 20.
14
15
+You also need a recent version of rebar3(http://www.rebar3.org/) in
16
+the system path.
17
18
Installation
19
------------
20
21
-To compile the module you simply run ``make``.
22
-
23
-To run the unit tests run ``make test``.
24
-
25
-To run the example module run ``make example``.
26
+To compile the module you simply run `rebar3 compile`.
27
28
-To build the (very) limited documentation run ``make doc``.
29
+To run the unit tests run `rebar3 eunit`.
30
31
-After the module is compiled with ``make``, insert getopt into the Erlang lib directory (e.g. by soft link or copying).
32
+To build the (very) limited documentation run `rebar edoc`.
33
34
+To use getopt in your project you can just add it as a dependency in your
35
+`rebar.config` file in the following way:
36
```sh
37
-ln -s . /usr/local/lib/erlang/lib/getopt-0.8.2
38
+{deps,
39
+
40
+ {getopt, "1.0.1"}
41
+
42
+}
43
```
44
45
46
Usage
47
-----
48
49
-The *getopt* module provides four functions:
50
+The `getopt` module provides four functions:
51
52
-``` erlang
53
+```erlang
54
parse({Name, Short, Long, ArgSpec, Help}, Args :: string() | string()) ->
55
{ok, {Options, NonOptionArgs}} | {error, {Reason, Data}}
56
57
58
CmdLineTail :: string(), OptionsTail :: {string(), string}) -> ok
59
```
60
61
-The ``parse/2`` function receives a list of tuples with the command line option
62
+The `parse/2` function receives a list of tuples with the command line option
63
specifications. The type specification for the tuple is:
64
65
-``` erlang
66
+```erlang
67
-type arg_type() :: 'atom' | 'binary' | 'boolean' | 'float' | 'integer' | 'string'.
68
69
-type arg_value() :: atom() | binary() | boolean() | float() | integer() | string().
70
71
72
The elements of the tuple are:
73
74
- - ``Name``: name of the option.
75
- - ``Short``: character for the short option (e.g. $i for -i).
76
- - ``Long``: string for the long option (e.g. "info" for --info).
77
- - ``ArgSpec``: data type and optional default value the argument will be converted to.
78
- - ``Help``: help message that is shown for the option when ``usage/2`` is called.
79
+ - `Name`: name of the option.
80
+ - `Short`: character for the short option (e.g. $i for -i).
81
+ - `Long`: string for the long option (e.g. "info" for --info).
82
+ - `ArgSpec`: data type and optional default value the argument will be converted to.
83
+ - `Help`: help message that is shown for the option when `usage/2` is called.
84
85
e.g.
86
87
-``` erlang
88
+```erlang
89
{port, $p, "port", {integer, 5432}, "Database server port"}
90
```
91
92
-The second parameter receives the list of arguments as passed to the ``main/1``
93
+The second parameter receives the list of arguments as passed to the `main/1`
94
function in escripts or the unparsed command line as a string.
95
96
If the function is successful parsing the command line arguments it will return
97
a tuple containing the parsed options and the non-option arguments. The options
98
-will be represented by a list of key-value pairs with the ``Name`` of the
99
+will be represented by a list of key-value pairs with the `Name` of the
100
option as *key* and the argument from the command line as *value*. If the option
101
-doesn't have an argument, only the atom corresponding to its ``Name`` will be
102
+doesn't have an argument, only the atom corresponding to its `Name` will be
103
added to the list of options. For the example given above we could get something
104
-like ``{port, 5432}``. The non-option arguments are just a list of strings with
105
+like `{port, 5432}`. The non-option arguments are just a list of strings with
106
all the arguments that did not have corresponding options.
107
108
e.g. Given the following option specifications:
109
110
-``` erlang
111
+```erlang
112
OptSpecList =
113
114
{host, $h, "host", {string, "localhost"}, "Database server host"},
115
116
117
And this command line:
118
119
-``` erlang
120
+```erlang
121
Args = "-h myhost --port=1000 -x myfile.txt -vvv dummy1 dummy2"
122
```
123
124
-Which could also be passed in the format the ``main/1`` function receives the arguments in escripts:
125
+Which could also be passed in the format the `main/1` function receives the arguments in escripts:
126
127
-``` erlang
128
+```erlang
129
Args = "-h", "myhost", "--port=1000", "-x", "file.txt", "-vvv", "dummy1", "dummy2".
130
```
131
132
-The call to ``getopt:parse/2``:
133
+The call to `getopt:parse/2`:
134
135
-``` erlang
136
+```erlang
137
getopt:parse(OptSpecList, Args).
138
```
139
140
Will return:
141
142
-``` erlang
143
+```erlang
144
{ok,{{host,"myhost"},
145
{port,1000},
146
xml,
147
148
"dummy1","dummy2"}}
149
```
150
151
-The ``tokenize/1`` function will separate a command line string into
152
+The `tokenize/1` function will separate a command line string into
153
tokens, taking into account whether an argument is single or double
154
quoted, a character is escaped or if there are environment variables to
155
be expanded. e.g.:
156
157
-``` erlang
158
+```erlang
159
getopt:tokenize(" --name John\\ Smith --path \"John's Files\" -u ${USER}").
160
```
161
162
Will return something like:
163
164
-``` erlang
165
+```erlang
166
"--name","John Smith","--path","John's Files","-u","jsmith"
167
```
168
169
-The other functions exported by the ``getopt`` module (``usage/2``, ``usage/3``
170
-and ``usage/4``) are used to show the command line syntax for the program.
171
+The other functions exported by the `getopt` module (`usage/2`, `usage/3`
172
+and `usage/4`) are used to show the command line syntax for the program.
173
For example, given the above-mentioned option specifications, the call to
174
-``getopt:usage/2``:
175
+`getopt:usage/2`:
176
177
-``` erlang
178
+```erlang
179
getopt:usage(OptSpecList, "ex1").
180
```
181
182
183
-v Verbosity level
184
<file> Output file
185
186
-This call to ``getopt:usage/3`` will add a string after the usage command line:
187
+This call to `getopt:usage/3` will add a string after the usage command line:
188
189
-``` erlang
190
- getopt:usage(OptSpecList, "ex1", "var=value ... command ...").
191
+```erlang
192
+getopt:usage(OptSpecList, "ex1", "var=value ... command ...").
193
```
194
195
Will show (on *standard_error*):
196
197
-v, --verbose Verbosity level
198
<file> Output file
199
200
-Whereas this call to ``getopt:usage/3`` will also add some lines to the options
201
getopt-0.8.2.tar.gz/rebar.config -> getopt-1.0.1.tar.gz/rebar.config
Changed
23
1
2
warn_export_vars,
3
warn_exported_vars,
4
warn_missing_spec,
5
- warn_untyped_record, debug_info}.
6
+ warn_untyped_record, debug_info,
7
+ {platform_define, "^2", unicode_str}
8
+}.
9
+
10
+{dialyzer,
11
+
12
+ {warnings, no_return, no_undefined_callbacks, no_unused},
13
+ {get_warnings, true},
14
+ {plt_apps, top_level_deps},
15
+ {plt_location, local},
16
+ {base_plt_apps, kernel, stdlib, sasl, inets, crypto, public_key, ssl,
17
+ runtime_tools, erts, compiler, tools, syntax_tools, hipe,
18
+ mnesia},
19
+ {base_plt_location, global}
20
+ }.
21
+
22
{xref_checks, undefined_function_calls}.
23
getopt-1.0.1.tar.gz/rebar.lock
Added
3
1
2
+.
3
getopt-0.8.2.tar.gz/src/getopt.app.src -> getopt-1.0.1.tar.gz/src/getopt.app.src
Changed
13
1
2
%% -*- mode: Erlang; fill-column: 75; comment-column: 50; -*-
3
{application, getopt,
4
{description, "Command-line options parser for Erlang"},
5
- {vsn, "0.8.2"},
6
+ {vsn, "1.0.1"},
7
{modules, },
8
{registered, },
9
+ {maintainers, "Juan Jose Comellas"},
10
+ {licenses, "BSD"},
11
+ {links, {"GitHub", "https://github.com/jcomellas/getopt"}},
12
{applications, kernel, stdlib}}.
13
getopt-0.8.2.tar.gz/src/getopt.erl -> getopt-1.0.1.tar.gz/src/getopt.erl
Changed
135
1
2
%%%-------------------------------------------------------------------
3
%%% @author Juan Jose Comellas <juanjo@comellas.org>
4
-%%% @copyright (C) 2009 Juan Jose Comellas
5
+%%% @copyright (C) 2009-2017 Juan Jose Comellas
6
%%% @doc Parses command line options with a format similar to that of GNU getopt.
7
%%% @end
8
%%%
9
10
-author('juanjo@comellas.org').
11
12
-export(parse/2, check/2, parse_and_check/2, format_error/2,
13
- usage/2, usage/3, usage/4, tokenize/1).
14
+ usage/2, usage/3, usage/4, usage/6, tokenize/1).
15
-export(usage_cmd_line/2).
16
17
-define(LINE_LENGTH, 75).
18
19
format_error(OptSpecList, {error, Reason}) ->
20
format_error(OptSpecList, Reason);
21
format_error(OptSpecList, {missing_required_option, Name}) ->
22
- {_Name, Short, Long, _Type, _Help} = lists:keyfind(Name, 1, OptSpecList),
23
- lists:flatten("missing required option: -", Short, " (", to_string(Long), ")");
24
+ OptStr = case lists:keyfind(Name, 1, OptSpecList) of
25
+ {Name, undefined, undefined, _Type, _Help} -> "<", to_string(Name), ">";
26
+ {_Name, undefined, Long, _Type, _Help} -> "--", Long;
27
+ {_Name, Short, undefined, _Type, _Help} -> "-", Short;
28
+ {_Name, Short, Long, _Type, _Help} -> "-", Short, " (", Long, ")"
29
+ end,
30
+ lists:flatten("missing required option: ", OptStr);
31
format_error(_OptSpecList, {invalid_option, OptStr}) ->
32
lists:flatten("invalid option: ", to_string(OptStr));
33
format_error(_OptSpecList, {invalid_option_arg, {Name, Arg}}) ->
34
35
to_type(float, Arg) ->
36
list_to_float(Arg);
37
to_type(boolean, Arg) ->
38
- LowerArg = string:to_lower(Arg),
39
+ LowerArg = lowercase(Arg),
40
case is_arg_true(LowerArg) of
41
true ->
42
true;
43
44
45
-spec is_boolean_arg(string()) -> boolean().
46
is_boolean_arg(Arg) ->
47
- LowerArg = string:to_lower(Arg),
48
+ LowerArg = lowercase(Arg),
49
is_arg_true(LowerArg) orelse is_arg_false(LowerArg).
50
51
52
53
%% arguments that are supported by the program.
54
-spec usage(option_spec(), string(), output_stream() | string()) -> ok.
55
usage(OptSpecList, ProgramName, OutputStream) when is_atom(OutputStream) ->
56
- io:format(OutputStream, "~s~n~n~s~n",
57
- usage_cmd_line(ProgramName, OptSpecList), usage_options(OptSpecList));
58
+ io:format(OutputStream, "~ts~n~n~ts~n",
59
+ unicode:characters_to_list(usage_cmd_line(ProgramName, OptSpecList)), unicode:characters_to_list(usage_options(OptSpecList)));
60
%% @doc Show a message on standard_error indicating the command line options and
61
%% arguments that are supported by the program. The CmdLineTail argument
62
%% is a string that is added to the end of the usage command line.
63
64
%% is a string that is added to the end of the usage command line.
65
-spec usage(option_spec(), ProgramName :: string(), CmdLineTail :: string(), output_stream() | {string(), string()}) -> ok.
66
usage(OptSpecList, ProgramName, CmdLineTail, OutputStream) when is_atom(OutputStream) ->
67
- io:format(OutputStream, "~s~n~n~s~n",
68
- usage_cmd_line(ProgramName, OptSpecList, CmdLineTail), usage_options(OptSpecList));
69
+ io:format(OutputStream, "~ts~n~n~ts~n",
70
+ unicode:characters_to_list(usage_cmd_line(ProgramName, OptSpecList, CmdLineTail)), unicode:characters_to_list(usage_options(OptSpecList)));
71
%% @doc Show a message on standard_error indicating the command line options and
72
%% arguments that are supported by the program. The CmdLineTail and OptionsTail
73
%% arguments are a string that is added to the end of the usage command line
74
75
-spec usage(option_spec(), ProgramName :: string(), CmdLineTail :: string(),
76
{OptionName :: string(), Help :: string()}, output_stream()) -> ok.
77
usage(OptSpecList, ProgramName, CmdLineTail, OptionsTail, OutputStream) ->
78
- io:format(OutputStream, "~s~n~n~s~n",
79
- usage_cmd_line(ProgramName, OptSpecList, CmdLineTail), usage_options(OptSpecList, OptionsTail)).
80
+ io:format(OutputStream, "~ts~n~n~ts~n",
81
+ unicode:characters_to_list(usage_cmd_line(ProgramName, OptSpecList, CmdLineTail)), unicode:characters_to_list(usage_options(OptSpecList, OptionsTail))).
82
+
83
+%% @doc Show a message on standard_error or standard_io indicating the
84
+%% command line options and arguments that are supported by the
85
+%% program. The Description allows for structured command line usage
86
+%% that works in addition to the standard options, and appears between
87
+%% the usage_cmd_line and usage_options sections. The CmdLineTail and
88
+%% OptionsTail arguments are a string that is added to the end of the
89
+%% usage command line and a list of tuples that are added to the end of
90
+%% the options' help lines.
91
+-spec usage(option_spec(), ProgramName :: string(), CmdLineTail :: string(),
92
+ Description :: string(),
93
+ {OptionName :: string(), Help :: string()},
94
+ output_stream()) -> ok.
95
+usage(OptSpecList, ProgramName, CmdLineTail, Description, OptionsTail, OutputStream) ->
96
+ io:format(OutputStream, "~ts~n~n~ts~n~n~ts~n",
97
+ unicode:characters_to_list(usage_cmd_line(ProgramName, OptSpecList, CmdLineTail)), Description, unicode:characters_to_list(usage_options(OptSpecList, OptionsTail))).
98
99
100
-spec usage_cmd_line(ProgramName :: string(), option_spec()) -> iolist().
101
102
%% already wrapped according to the maximum MaxLineLength.
103
-spec usage_cmd_line_options(MaxLineLength :: non_neg_integer(), option_spec(), CmdLineTail :: string()) -> iolist().
104
usage_cmd_line_options(MaxLineLength, OptSpecList, CmdLineTail) ->
105
- usage_cmd_line_options(MaxLineLength, OptSpecList ++ string:tokens(CmdLineTail, " "), , 0, ).
106
+ usage_cmd_line_options(MaxLineLength, OptSpecList ++ lexemes(CmdLineTail, " "), , 0, ).
107
108
usage_cmd_line_options(MaxLineLength, OptSpec | Tail, LineAcc, LineAccLength, Acc) ->
109
Option = $\s | lists:flatten(usage_cmd_line_option(OptSpec)),
110
111
%% Look for the first whitespace character in the current (reversed) line
112
%% buffer to get a wrapped line. If there is no whitespace just cut the
113
%% line at the position corresponding to the maximum length.
114
- {NextLineAcc, WrappedLine} = case string:cspan(CurrentLineAcc, " \t") of
115
+ {NextLineAcc, WrappedLine} = case cspan(CurrentLineAcc, " \t") of
116
WhitespacePos when WhitespacePos < Count ->
117
lists:split(WhitespacePos, CurrentLineAcc);
118
_ ->
119
120
atom_to_list(Atom);
121
to_string(Value) ->
122
io_lib:format("~p", Value).
123
+
124
+%% OTP-20/21 conversion to unicode string module
125
+-ifdef(unicode_str).
126
+lowercase(Str) -> string:lowercase(Str).
127
+lexemes(Str, Separators) -> string:lexemes(Str, Separators).
128
+cspan(Str, Chars) -> length(element(1,string:take(Str, Chars, true))).
129
+-else.
130
+lowercase(Str) -> string:to_lower(Str).
131
+lexemes(Str, Separators) -> string:tokens(Str, Separators).
132
+cspan(Str, Chars) -> string:cspan(Str, Chars).
133
+-endif.
134
+
135
getopt-0.8.2.tar.gz/test/getopt_test.erl -> getopt-1.0.1.tar.gz/test/getopt_test.erl
Changed
29
1
2
check_test_() ->
3
OptSpecList =
4
5
- {arg, $a, "arg", string, "Required arg"}
6
+ { arg, $a, "arg", string, "Required arg"},
7
+ {short, $s, undefined, string, "short option"},
8
+ { long, undefined, "long", string, "long option"},
9
+ {other, undefined, undefined, string, "task"}
10
,
11
{ok, {Opts, _}} = parse(OptSpecList, ""),
12
13
14
{"Format missing option error test 2",
15
?_assertEqual("missing required option: -a (arg)",
16
format_error(OptSpecList, {missing_required_option, arg}))},
17
+ {"Format missing option error test 3",
18
+ ?_assertEqual("missing required option: -s",
19
+ format_error(OptSpecList, {missing_required_option, short}))},
20
+ {"Format missing option error test 4",
21
+ ?_assertEqual("missing required option: --long",
22
+ format_error(OptSpecList, {missing_required_option, long}))},
23
+ {"Format missing option error test 5",
24
+ ?_assertEqual("missing required option: <other>",
25
+ format_error(OptSpecList, {missing_required_option, other}))},
26
{"Format invalid option error test 1",
27
?_assertEqual("invalid option: --verbose",
28
format_error(OptSpecList, {error, {invalid_option, "--verbose"}}))},
29