Update to the latest git snapshot
Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
This commit is contained in:
parent
3111af8041
commit
f41c5eb8fa
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
||||
/basho-rebar-RELEASE-1-327-g90058c7.tar.gz
|
||||
/basho-rebar-RELEASE-1-821-g635d1a9.tar.gz
|
||||
|
@ -1,17 +1,19 @@
|
||||
%global realname rebar
|
||||
%global upstream basho
|
||||
%global debug_package %{nil}
|
||||
%global git_tag 90058c7
|
||||
%global git_tag 635d1a9
|
||||
%global patchnumber 821
|
||||
|
||||
|
||||
Name: erlang-%{realname}
|
||||
Version: 2
|
||||
Release: 5.20101120git%{git_tag}%{?dist}
|
||||
Release: 6.20120514git%{git_tag}%{?dist}
|
||||
Summary: Erlang Build Tools
|
||||
Group: Development/Tools
|
||||
License: MIT
|
||||
URL: https://github.com/basho/rebar
|
||||
# wget --no-check-certificate https://github.com/basho/rebar/tarball/90058c7
|
||||
Source0: basho-%{realname}-RELEASE-1-327-g%{git_tag}.tar.gz
|
||||
# wget --no-check-certificate --content-disposition https://github.com/basho/rebar/zipball/635d1a9
|
||||
Source0: %{upstream}-%{realname}-RELEASE-1-%{patchnumber}-g%{git_tag}.tar.gz
|
||||
Source1: rebar.escript
|
||||
Patch1: rebar-0001-No-need-to-create-bundle.patch
|
||||
Patch2: rebar-0002-Remove-bundled-mustache.patch
|
||||
@ -20,6 +22,7 @@ BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
|
||||
BuildRequires: erlang-erts >= R13B-03
|
||||
BuildRequires: erlang-getopt
|
||||
BuildRequires: erlang-reltool
|
||||
#Requires: erlang-abnfc
|
||||
Requires: erlang-asn1
|
||||
Requires: erlang-compiler
|
||||
Requires: erlang-crypto
|
||||
@ -47,7 +50,7 @@ Erlang Build Tools.
|
||||
|
||||
|
||||
%prep
|
||||
%setup -q -n basho-%{realname}-%{git_tag}
|
||||
%setup -q -n %{upstream}-%{realname}-%{git_tag}
|
||||
%patch1 -p1 -b .no_bundle
|
||||
%patch2 -p1 -b .remove_bundled_mustache
|
||||
%patch3 -p1 -b .remove_bundled_getopt
|
||||
@ -80,6 +83,9 @@ rm -rf $RPM_BUILD_ROOT
|
||||
|
||||
|
||||
%changelog
|
||||
* Wed May 16 2012 Peter Lemenkov <lemenkov@gmail.com> - 2-6.20120514git635d1a9
|
||||
- Updated to the latest git snapshot
|
||||
|
||||
* Fri Jan 13 2012 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 2-5.20101120git90058c7
|
||||
- Rebuilt for https://fedoraproject.org/wiki/Fedora_17_Mass_Rebuild
|
||||
|
||||
|
@ -1,62 +1,64 @@
|
||||
From 0b38555707bd90d102b538a0055925a7493c74d5 Mon Sep 17 00:00:00 2001
|
||||
From 6d7b6dca598f26fa5b46561b851e6b8286a50662 Mon Sep 17 00:00:00 2001
|
||||
From: Peter Lemenkov <lemenkov@gmail.com>
|
||||
Date: Tue, 28 Sep 2010 23:04:36 +0400
|
||||
Subject: [PATCH 1/3] No need to create bundle
|
||||
|
||||
Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
|
||||
---
|
||||
bootstrap | 38 +-------------------------------------
|
||||
1 files changed, 1 insertions(+), 37 deletions(-)
|
||||
bootstrap | 40 ----------------------------------------
|
||||
1 file changed, 40 deletions(-)
|
||||
|
||||
diff --git a/bootstrap b/bootstrap
|
||||
index 5be3183..634e1f6 100755
|
||||
index e86ad8e..c4992a7 100755
|
||||
--- a/bootstrap
|
||||
+++ b/bootstrap
|
||||
@@ -51,43 +51,7 @@ main(Args) ->
|
||||
true = code:add_path("ebin"),
|
||||
|
||||
@@ -52,46 +52,6 @@ main(Args) ->
|
||||
%% Run rebar to do proper .app validation and such
|
||||
- rebar:main(["compile"] ++ Args),
|
||||
-
|
||||
- %% Read the contents of the files in ebin and templates; note that we place
|
||||
- %% all the beam files at the top level of the code archive so that code loading
|
||||
- %% works properly.
|
||||
rebar:main(["compile"] ++ Args),
|
||||
|
||||
- %% Read the contents of the files in ebin and templates; note that we
|
||||
- %% place all the beam files at the top level of the code archive so
|
||||
- %% that code loading works properly.
|
||||
- Files = load_files("*", "ebin") ++ load_files("priv/templates/*", "."),
|
||||
-
|
||||
- case zip:create("mem", Files, [memory]) of
|
||||
- {ok, {"mem", ZipBin}} ->
|
||||
- %% Archive was successfully created. Prefix that binary with our
|
||||
- %% header and write to "rebar" file
|
||||
- Script = <<"#!/usr/bin/env escript\n%%! -noshell -noinput\n", ZipBin/binary>>,
|
||||
- %% header and write to "rebar" file.
|
||||
- %% Without -noshell -noinput escript consumes all input that would
|
||||
- %% otherwise go to the shell for the next command.
|
||||
- Script = <<"#!/usr/bin/env escript\n%%! -noshell -noinput\n",
|
||||
- ZipBin/binary>>,
|
||||
- case file:write_file("rebar", Script) of
|
||||
- ok ->
|
||||
- ok;
|
||||
- {error, WriteError} ->
|
||||
- io:format("Failed to write rebar script: ~p\n", [WriteError]),
|
||||
- io:format("Failed to write rebar script: ~p\n",
|
||||
- [WriteError]),
|
||||
- halt(1)
|
||||
- end;
|
||||
- {error, ZipError} ->
|
||||
- io:format("Failed to construct rebar script archive: ~p\n", [ZipError]),
|
||||
- io:format("Failed to construct rebar script archive: ~p\n",
|
||||
- [ZipError]),
|
||||
- halt(1)
|
||||
- end,
|
||||
-
|
||||
- %% Finally, update executable perms for our script
|
||||
- %% Finally, update executable perms for our script on *nix,
|
||||
- %% or write out script files on win32.
|
||||
- case os:type() of
|
||||
- {unix,_} ->
|
||||
- [] = os:cmd("chmod u+x rebar"),
|
||||
- ok;
|
||||
- {win32,_} ->
|
||||
- write_windows_scripts(),
|
||||
- ok;
|
||||
- _ ->
|
||||
- ok
|
||||
- end,
|
||||
-
|
||||
- %% Add a helpful message
|
||||
- io:format("Congratulations! You now have a self-contained script called \"rebar\" in\n"
|
||||
- "your current working directory. Place this script anywhere in your path\n"
|
||||
- "and you can use rebar to build OTP-compliant apps.\n").
|
||||
+ rebar:main(["compile"] ++ Args).
|
||||
|
||||
rm(Path) ->
|
||||
NativePath = filename:nativename(Path),
|
||||
%% Add a helpful message
|
||||
io:format("Congratulations! You now have a self-contained script called"
|
||||
" \"rebar\" in\n"
|
||||
--
|
||||
1.7.2.3
|
||||
1.7.10.1
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
From 3cb4ccb50a6f1175e3b2a6723641befd3b8cb444 Mon Sep 17 00:00:00 2001
|
||||
From 844182030976e868e7cd6aa67e891d55db749a65 Mon Sep 17 00:00:00 2001
|
||||
From: Peter Lemenkov <lemenkov@gmail.com>
|
||||
Date: Sat, 20 Nov 2010 16:36:45 +0300
|
||||
Subject: [PATCH 2/3] Remove bundled mustache
|
||||
@ -6,16 +6,16 @@ Subject: [PATCH 2/3] Remove bundled mustache
|
||||
Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
|
||||
---
|
||||
ebin/rebar.app | 3 +-
|
||||
src/mustache.erl | 219 ------------------------------------------------------
|
||||
2 files changed, 1 insertions(+), 221 deletions(-)
|
||||
src/mustache.erl | 234 ------------------------------------------------------
|
||||
2 files changed, 1 insertion(+), 236 deletions(-)
|
||||
delete mode 100644 src/mustache.erl
|
||||
|
||||
diff --git a/ebin/rebar.app b/ebin/rebar.app
|
||||
index 6f9b6f5..75aaec1 100644
|
||||
index 0c6e4c3..0836c7c 100644
|
||||
--- a/ebin/rebar.app
|
||||
+++ b/ebin/rebar.app
|
||||
@@ -33,8 +33,7 @@
|
||||
rebar_templater,
|
||||
@@ -35,8 +35,7 @@
|
||||
rebar_upgrade,
|
||||
rebar_utils,
|
||||
rebar_xref,
|
||||
- getopt,
|
||||
@ -26,10 +26,10 @@ index 6f9b6f5..75aaec1 100644
|
||||
stdlib,
|
||||
diff --git a/src/mustache.erl b/src/mustache.erl
|
||||
deleted file mode 100644
|
||||
index df81aed..0000000
|
||||
index ac501a0..0000000
|
||||
--- a/src/mustache.erl
|
||||
+++ /dev/null
|
||||
@@ -1,219 +0,0 @@
|
||||
@@ -1,234 +0,0 @@
|
||||
-%% The MIT License
|
||||
-%%
|
||||
-%% Copyright (c) 2009 Tom Preston-Werner <tom@mojombo.com>
|
||||
@ -63,6 +63,10 @@ index df81aed..0000000
|
||||
- section_re = undefined,
|
||||
- tag_re = undefined}).
|
||||
-
|
||||
--ifdef(TEST).
|
||||
--include_lib("eunit/include/eunit.hrl").
|
||||
--endif.
|
||||
-
|
||||
-compile(Body) when is_list(Body) ->
|
||||
- State = #mstate{},
|
||||
- CompiledTemplate = pre_compile(Body, State),
|
||||
@ -222,8 +226,6 @@ index df81aed..0000000
|
||||
- integer_to_list(Val);
|
||||
-to_s(Val) when is_float(Val) ->
|
||||
- io_lib:format("~.2f", [Val]);
|
||||
-to_s(Val) when is_boolean(Val) ->
|
||||
- Val;
|
||||
-to_s(Val) when is_atom(Val) ->
|
||||
- atom_to_list(Val);
|
||||
-to_s(Val) ->
|
||||
@ -249,6 +251,19 @@ index df81aed..0000000
|
||||
- Out = render(list_to_atom(T)),
|
||||
- io:format(Out ++ "~n", []).
|
||||
-
|
||||
--ifdef(TEST).
|
||||
-
|
||||
-simple_test() ->
|
||||
- Ctx = dict:from_list([{name, "world"}]),
|
||||
- Result = render("Hello {{name}}!", Ctx),
|
||||
- ?assertEqual("Hello world!", Result).
|
||||
-
|
||||
-integer_values_too_test() ->
|
||||
- Ctx = dict:from_list([{name, "Chris"}, {value, 10000}]),
|
||||
- Result = render("Hello {{name}}~nYou have just won ${{value}}!", Ctx),
|
||||
- ?assertEqual("Hello Chris~nYou have just won $10000!", Result).
|
||||
-
|
||||
--endif.
|
||||
--
|
||||
1.7.2.3
|
||||
1.7.10.1
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
From b2673b1ffc3b12652adef9f6453bca2b86247cad Mon Sep 17 00:00:00 2001
|
||||
From 0915eb1978ebca6d0f89421203d5be6d6b4fdd86 Mon Sep 17 00:00:00 2001
|
||||
From: Peter Lemenkov <lemenkov@gmail.com>
|
||||
Date: Sat, 20 Nov 2010 16:40:15 +0300
|
||||
Subject: [PATCH 3/3] Remove bundled getopt
|
||||
@ -6,30 +6,30 @@ Subject: [PATCH 3/3] Remove bundled getopt
|
||||
Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
|
||||
---
|
||||
ebin/rebar.app | 3 +-
|
||||
src/getopt.erl | 501 --------------------------------------------------------
|
||||
2 files changed, 1 insertions(+), 503 deletions(-)
|
||||
src/getopt.erl | 621 --------------------------------------------------------
|
||||
2 files changed, 1 insertion(+), 623 deletions(-)
|
||||
delete mode 100644 src/getopt.erl
|
||||
|
||||
diff --git a/ebin/rebar.app b/ebin/rebar.app
|
||||
index 75aaec1..8589819 100644
|
||||
index 0836c7c..a9dc46d 100644
|
||||
--- a/ebin/rebar.app
|
||||
+++ b/ebin/rebar.app
|
||||
@@ -32,8 +32,7 @@
|
||||
rebar_subdirs,
|
||||
@@ -34,8 +34,7 @@
|
||||
rebar_templater,
|
||||
rebar_upgrade,
|
||||
rebar_utils,
|
||||
- rebar_xref,
|
||||
- getopt ]},
|
||||
+ rebar_xref ]},
|
||||
+ rebar_xref]},
|
||||
{registered, []},
|
||||
{applications, [kernel,
|
||||
stdlib,
|
||||
diff --git a/src/getopt.erl b/src/getopt.erl
|
||||
deleted file mode 100644
|
||||
index bb7fae2..0000000
|
||||
index 175b7a5..0000000
|
||||
--- a/src/getopt.erl
|
||||
+++ /dev/null
|
||||
@@ -1,501 +0,0 @@
|
||||
@@ -1,621 +0,0 @@
|
||||
-%%%-------------------------------------------------------------------
|
||||
-%%% @author Juan Jose Comellas <juanjo@comellas.org>
|
||||
-%%% @copyright (C) 2009 Juan Jose Comellas
|
||||
@ -45,6 +45,13 @@ index bb7fae2..0000000
|
||||
-
|
||||
--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.
|
||||
@ -78,6 +85,8 @@ index bb7fae2..0000000
|
||||
- ArgSpec :: arg_spec(),
|
||||
- Help :: string() | undefined
|
||||
- }.
|
||||
-%% Output streams
|
||||
--type output_stream() :: 'standard_io' | 'standard_error'.
|
||||
-
|
||||
-
|
||||
-%% @doc Parse the command line options and arguments returning a list of tuples
|
||||
@ -104,26 +113,25 @@ index bb7fae2..0000000
|
||||
- {ok, {[option()], [string()]}}.
|
||||
-%% Process the option terminator.
|
||||
-parse(OptSpecList, OptAcc, ArgAcc, _ArgPos, ["--" | Tail]) ->
|
||||
- % Any argument present after the terminator is not considered an option.
|
||||
- %% Any argument present after the terminator is not considered an option.
|
||||
- {ok, {lists:reverse(append_default_options(OptSpecList, OptAcc)), lists:reverse(ArgAcc, Tail)}};
|
||||
-%% Process long options.
|
||||
-parse(OptSpecList, OptAcc, ArgAcc, ArgPos, [[$-, $- | OptArg] = OptStr | Tail]) ->
|
||||
- parse_option_long(OptSpecList, OptAcc, ArgAcc, ArgPos, Tail, OptStr, OptArg);
|
||||
-parse(OptSpecList, OptAcc, ArgAcc, ArgPos, ["--" ++ OptArg = OptStr | Tail]) ->
|
||||
- parse_long_option(OptSpecList, OptAcc, ArgAcc, ArgPos, Tail, OptStr, OptArg);
|
||||
-%% Process short options.
|
||||
-parse(OptSpecList, OptAcc, ArgAcc, ArgPos, [[$- | [_Char | _] = OptArg] = OptStr | Tail]) ->
|
||||
- parse_option_short(OptSpecList, OptAcc, ArgAcc, ArgPos, Tail, OptStr, OptArg);
|
||||
-parse(OptSpecList, OptAcc, ArgAcc, ArgPos, ["-" ++ ([_Char | _] = OptArg) = OptStr | Tail]) ->
|
||||
- parse_short_option(OptSpecList, OptAcc, ArgAcc, ArgPos, Tail, OptStr, OptArg);
|
||||
-%% Process non-option arguments.
|
||||
-parse(OptSpecList, OptAcc, ArgAcc, ArgPos, [Arg | Tail]) ->
|
||||
- case find_non_option_arg(OptSpecList, ArgPos) of
|
||||
- {value, OptSpec} when ?IS_OPT_SPEC(OptSpec) ->
|
||||
- parse(OptSpecList, [convert_option_arg(OptSpec, Arg) | OptAcc],
|
||||
- ArgAcc, ArgPos + 1, Tail);
|
||||
- parse(OptSpecList, add_option_with_arg(OptSpec, Arg, OptAcc), ArgAcc, ArgPos + 1, Tail);
|
||||
- false ->
|
||||
- parse(OptSpecList, OptAcc, [Arg | ArgAcc], ArgPos, Tail)
|
||||
- end;
|
||||
-parse(OptSpecList, OptAcc, ArgAcc, _ArgPos, []) ->
|
||||
- % Once we have completed gathering the options we add the ones that were
|
||||
- % not present but had default arguments in the specification.
|
||||
- %% Once we have completed gathering the options we add the ones that were
|
||||
- %% not present but had default arguments in the specification.
|
||||
- {ok, {lists:reverse(append_default_options(OptSpecList, OptAcc)), lists:reverse(ArgAcc)}}.
|
||||
-
|
||||
-
|
||||
@ -133,24 +141,25 @@ index bb7fae2..0000000
|
||||
-%% --foo Single option 'foo', no argument
|
||||
-%% --foo=bar Single option 'foo', argument "bar"
|
||||
-%% --foo bar Single option 'foo', argument "bar"
|
||||
--spec parse_option_long([option_spec()], [option()], [string()], integer(), [string()], string(), string()) ->
|
||||
--spec parse_long_option([option_spec()], [option()], [string()], integer(), [string()], string(), string()) ->
|
||||
- {ok, {[option()], [string()]}}.
|
||||
-parse_option_long(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptStr, OptArg) ->
|
||||
-parse_long_option(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptStr, OptArg) ->
|
||||
- case split_assigned_arg(OptArg) of
|
||||
- {Long, Arg} ->
|
||||
- % Get option that has its argument within the same string
|
||||
- % separated by an equal ('=') character (e.g. "--port=1000").
|
||||
- parse_option_assigned_arg(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptStr, Long, Arg);
|
||||
- %% Get option that has its argument within the same string
|
||||
- %% separated by an equal ('=') character (e.g. "--port=1000").
|
||||
- parse_long_option_assigned_arg(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptStr, Long, Arg);
|
||||
-
|
||||
- Long ->
|
||||
- case lists:keysearch(Long, ?OPT_LONG, OptSpecList) of
|
||||
- {value, {Name, _Short, Long, undefined, _Help}} ->
|
||||
- case lists:keyfind(Long, ?OPT_LONG, OptSpecList) of
|
||||
- {Name, _Short, Long, undefined, _Help} ->
|
||||
- parse(OptSpecList, [Name | OptAcc], ArgAcc, ArgPos, Args);
|
||||
-
|
||||
- {value, {_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.
|
||||
- parse_option_next_arg(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptSpec);
|
||||
- {_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.
|
||||
- %% e.g ["--port", "1000"]
|
||||
- parse_long_option_next_arg(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptSpec);
|
||||
- false ->
|
||||
- throw({error, {invalid_option, OptStr}})
|
||||
- end
|
||||
@ -160,17 +169,17 @@ index bb7fae2..0000000
|
||||
-%% @doc Parse an option where the argument is 'assigned' in the same string using
|
||||
-%% the '=' character, add it to the option accumulator and continue parsing the
|
||||
-%% rest of the arguments recursively. This syntax is only valid for long options.
|
||||
--spec parse_option_assigned_arg([option_spec()], [option()], [string()], integer(),
|
||||
- [string()], string(), string(), string()) ->
|
||||
- {ok, {[option()], [string()]}}.
|
||||
-parse_option_assigned_arg(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptStr, Long, Arg) ->
|
||||
- case lists:keysearch(Long, ?OPT_LONG, OptSpecList) of
|
||||
- {value, {_Name, _Short, Long, ArgSpec, _Help} = OptSpec} ->
|
||||
--spec parse_long_option_assigned_arg([option_spec()], [option()], [string()], integer(),
|
||||
- [string()], string(), string(), string()) ->
|
||||
- {ok, {[option()], [string()]}}.
|
||||
-parse_long_option_assigned_arg(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptStr, Long, Arg) ->
|
||||
- case lists:keyfind(Long, ?OPT_LONG, OptSpecList) of
|
||||
- {_Name, _Short, Long, ArgSpec, _Help} = OptSpec ->
|
||||
- case ArgSpec of
|
||||
- undefined ->
|
||||
- throw({error, {invalid_option_arg, OptStr}});
|
||||
- _ ->
|
||||
- parse(OptSpecList, [convert_option_arg(OptSpec, Arg) | OptAcc], ArgAcc, ArgPos, Args)
|
||||
- parse(OptSpecList, add_option_with_assigned_arg(OptSpec, Arg, OptAcc), ArgAcc, ArgPos, Args)
|
||||
- end;
|
||||
- false ->
|
||||
- throw({error, {invalid_option, OptStr}})
|
||||
@ -183,7 +192,7 @@ index bb7fae2..0000000
|
||||
-split_assigned_arg(OptStr) ->
|
||||
- split_assigned_arg(OptStr, OptStr, []).
|
||||
-
|
||||
-split_assigned_arg(_OptStr, [$= | Tail], Acc) ->
|
||||
-split_assigned_arg(_OptStr, "=" ++ Tail, Acc) ->
|
||||
- {lists:reverse(Acc), Tail};
|
||||
-split_assigned_arg(OptStr, [Char | Tail], Acc) ->
|
||||
- split_assigned_arg(OptStr, Tail, [Char | Acc]);
|
||||
@ -191,6 +200,25 @@ index bb7fae2..0000000
|
||||
- OptStr.
|
||||
-
|
||||
-
|
||||
-%% @doc Retrieve the argument for an option from the next string in the list of
|
||||
-%% command-line parameters or set the value of the argument from the argument
|
||||
-%% specification (for boolean and integer arguments), if possible.
|
||||
-parse_long_option_next_arg(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, {Name, _Short, _Long, ArgSpec, _Help} = OptSpec) ->
|
||||
- ArgSpecType = arg_spec_type(ArgSpec),
|
||||
- case Args =:= [] orelse is_implicit_arg(ArgSpecType, hd(Args)) of
|
||||
- true ->
|
||||
- parse(OptSpecList, add_option_with_implicit_arg(OptSpec, OptAcc), ArgAcc, ArgPos, Args);
|
||||
- false ->
|
||||
- [Arg | Tail] = Args,
|
||||
- try
|
||||
- parse(OptSpecList, [{Name, to_type(ArgSpecType, Arg)} | OptAcc], ArgAcc, ArgPos, Tail)
|
||||
- catch
|
||||
- error:_ ->
|
||||
- throw({error, {invalid_option_arg, {Name, Arg}}})
|
||||
- end
|
||||
- end.
|
||||
-
|
||||
-
|
||||
-%% @doc Parse a short option, add it to the option accumulator and continue
|
||||
-%% parsing the rest of the arguments recursively.
|
||||
-%% A short option can have the following syntax:
|
||||
@ -199,55 +227,62 @@ index bb7fae2..0000000
|
||||
-%% -afoo Single option 'a', argument "foo"
|
||||
-%% -abc Multiple options: 'a'; 'b'; 'c'
|
||||
-%% -bcafoo Multiple options: 'b'; 'c'; 'a' with argument "foo"
|
||||
--spec parse_option_short([option_spec()], [option()], [string()], integer(), [string()], string(), string()) ->
|
||||
-%% -aaa Multiple repetitions of option 'a' (only valid for options with integer arguments)
|
||||
--spec parse_short_option([option_spec()], [option()], [string()], integer(), [string()], string(), string()) ->
|
||||
- {ok, {[option()], [string()]}}.
|
||||
-parse_option_short(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptStr, [Short | Arg]) ->
|
||||
- case lists:keysearch(Short, ?OPT_SHORT, OptSpecList) of
|
||||
- {value, {Name, Short, _Long, undefined, _Help}} ->
|
||||
- parse_option_short(OptSpecList, [Name | OptAcc], ArgAcc, ArgPos, Args, OptStr, Arg);
|
||||
-parse_short_option(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptStr, OptArg) ->
|
||||
- parse_short_option(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptStr, first, OptArg).
|
||||
-
|
||||
- {value, {_Name, Short, _Long, ArgSpec, _Help} = OptSpec} ->
|
||||
-parse_short_option(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptStr, OptPos, [Short | Arg]) ->
|
||||
- case lists:keyfind(Short, ?OPT_SHORT, OptSpecList) of
|
||||
- {Name, Short, _Long, undefined, _Help} ->
|
||||
- parse_short_option(OptSpecList, [Name | OptAcc], ArgAcc, ArgPos, Args, OptStr, first, Arg);
|
||||
-
|
||||
- {_Name, Short, _Long, ArgSpec, _Help} = OptSpec ->
|
||||
- %% The option has a specification, so it requires an argument.
|
||||
- case Arg of
|
||||
- [] ->
|
||||
- % The option argument string is empty, but the option requires
|
||||
- % an argument, so we look into the next string in the list.
|
||||
- parse_option_next_arg(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptSpec);
|
||||
- %% The option argument string is empty, but the option requires
|
||||
- %% an argument, so we look into the next string in the list.
|
||||
- parse_short_option_next_arg(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptSpec, OptPos);
|
||||
-
|
||||
- _ ->
|
||||
- case is_valid_arg(ArgSpec, Arg) of
|
||||
- true ->
|
||||
- parse(OptSpecList, [convert_option_arg(OptSpec, Arg) | OptAcc], ArgAcc, ArgPos, Args);
|
||||
- parse(OptSpecList, add_option_with_arg(OptSpec, Arg, OptAcc), ArgAcc, ArgPos, Args);
|
||||
- _ ->
|
||||
- parse_option_short(OptSpecList, [convert_option_no_arg(OptSpec) | OptAcc], ArgAcc, ArgPos, Args, OptStr, Arg)
|
||||
- NewOptAcc = case OptPos of
|
||||
- first -> add_option_with_implicit_arg(OptSpec, OptAcc);
|
||||
- _ -> add_option_with_implicit_incrementable_arg(OptSpec, OptAcc)
|
||||
- end,
|
||||
- parse_short_option(OptSpecList, NewOptAcc, ArgAcc, ArgPos, Args, OptStr, next, Arg)
|
||||
- end
|
||||
- end;
|
||||
-
|
||||
- false ->
|
||||
- throw({error, {invalid_option, OptStr}})
|
||||
- end;
|
||||
-parse_option_short(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, _OptStr, []) ->
|
||||
-parse_short_option(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, _OptStr, _OptPos, []) ->
|
||||
- parse(OptSpecList, OptAcc, ArgAcc, ArgPos, Args).
|
||||
-
|
||||
-
|
||||
-%% @doc Retrieve the argument for an option from the next string in the list of
|
||||
-%% command-line parameters.
|
||||
-parse_option_next_arg(OptSpecList, OptAcc, ArgAcc, ArgPos, [Arg | Tail] = Args, {Name, _Short, _Long, ArgSpec, _Help} = OptSpec) ->
|
||||
- % Special case for booleans: when the next string is an option we assume
|
||||
- % the value is 'true'.
|
||||
- case (arg_spec_type(ArgSpec) =:= boolean) andalso not is_boolean_arg(Arg) of
|
||||
-%% command-line parameters or set the value of the argument from the argument
|
||||
-%% specification (for boolean and integer arguments), if possible.
|
||||
-parse_short_option_next_arg(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, {Name, _Short, _Long, ArgSpec, _Help} = OptSpec, OptPos) ->
|
||||
- case Args =:= [] orelse is_implicit_arg(ArgSpec, hd(Args)) of
|
||||
- true when OptPos =:= first ->
|
||||
- parse(OptSpecList, add_option_with_implicit_arg(OptSpec, OptAcc), ArgAcc, ArgPos, Args);
|
||||
- true ->
|
||||
- parse(OptSpecList, [{Name, true} | OptAcc], ArgAcc, ArgPos, Args);
|
||||
- _ ->
|
||||
- parse(OptSpecList, [convert_option_arg(OptSpec, Arg) | OptAcc], ArgAcc, ArgPos, Tail)
|
||||
- end;
|
||||
-parse_option_next_arg(OptSpecList, OptAcc, ArgAcc, ArgPos, [] = Args, {Name, _Short, _Long, ArgSpec, _Help}) ->
|
||||
- % Special case for booleans: when the next string is missing we assume the
|
||||
- % value is 'true'.
|
||||
- case arg_spec_type(ArgSpec) of
|
||||
- boolean ->
|
||||
- parse(OptSpecList, [{Name, true} | OptAcc], ArgAcc, ArgPos, Args);
|
||||
- _ ->
|
||||
- throw({error, {missing_option_arg, Name}})
|
||||
- parse(OptSpecList, add_option_with_implicit_incrementable_arg(OptSpec, OptAcc), ArgAcc, ArgPos, Args);
|
||||
- false ->
|
||||
- [Arg | Tail] = Args,
|
||||
- try
|
||||
- parse(OptSpecList, [{Name, to_type(ArgSpec, Arg)} | OptAcc], ArgAcc, ArgPos, Tail)
|
||||
- catch
|
||||
- error:_ ->
|
||||
- throw({error, {invalid_option_arg, {Name, Arg}}})
|
||||
- end
|
||||
- end.
|
||||
-
|
||||
-
|
||||
@ -282,29 +317,76 @@ index bb7fae2..0000000
|
||||
- OptAcc.
|
||||
-
|
||||
-
|
||||
--spec convert_option_no_arg(option_spec()) -> compound_option().
|
||||
-convert_option_no_arg({Name, _Short, _Long, ArgSpec, _Help}) ->
|
||||
- case ArgSpec of
|
||||
- % Special case for booleans: if there is no argument we assume
|
||||
- % the value is 'true'.
|
||||
- {boolean, _DefaultValue} ->
|
||||
- {Name, true};
|
||||
-%% @doc Add an option with argument converting it to the data type indicated by the
|
||||
-%% argument specification.
|
||||
--spec add_option_with_arg(option_spec(), string(), [option()]) -> [option()].
|
||||
-add_option_with_arg({Name, _Short, _Long, ArgSpec, _Help} = OptSpec, Arg, OptAcc) ->
|
||||
- case is_valid_arg(ArgSpec, Arg) of
|
||||
- true ->
|
||||
- try
|
||||
- [{Name, to_type(ArgSpec, Arg)} | OptAcc]
|
||||
- catch
|
||||
- error:_ ->
|
||||
- throw({error, {invalid_option_arg, {Name, Arg}}})
|
||||
- end;
|
||||
- false ->
|
||||
- add_option_with_implicit_arg(OptSpec, OptAcc)
|
||||
- end.
|
||||
-
|
||||
-
|
||||
-%% @doc Add an option with argument that was part of an assignment expression
|
||||
-%% (e.g. "--verbose=3") converting it to the data type indicated by the
|
||||
-%% argument specification.
|
||||
--spec add_option_with_assigned_arg(option_spec(), string(), [option()]) -> [option()].
|
||||
-add_option_with_assigned_arg({Name, _Short, _Long, ArgSpec, _Help}, Arg, OptAcc) ->
|
||||
- try
|
||||
- [{Name, to_type(ArgSpec, Arg)} | OptAcc]
|
||||
- catch
|
||||
- error:_ ->
|
||||
- throw({error, {invalid_option_arg, {Name, Arg}}})
|
||||
- end.
|
||||
-
|
||||
-
|
||||
-%% @doc Add an option that required an argument but did not have one. Some data
|
||||
-%% types (boolean, integer) allow implicit or assumed arguments.
|
||||
--spec add_option_with_implicit_arg(option_spec(), [option()]) -> [option()].
|
||||
-add_option_with_implicit_arg({Name, _Short, _Long, ArgSpec, _Help}, OptAcc) ->
|
||||
- case arg_spec_type(ArgSpec) of
|
||||
- boolean ->
|
||||
- {Name, true};
|
||||
- %% Special case for boolean arguments: if there is no argument we
|
||||
- %% set the value to 'true'.
|
||||
- [{Name, true} | OptAcc];
|
||||
- integer ->
|
||||
- %% Special case for integer arguments: if the option had not been set
|
||||
- %% before we set the value to 1. This is needed to support options like
|
||||
- %% "-v" to return something like {verbose, 1}.
|
||||
- [{Name, 1} | OptAcc];
|
||||
- _ ->
|
||||
- throw({error, {missing_option_arg, Name}})
|
||||
- end.
|
||||
-
|
||||
-
|
||||
-%% @doc Convert the argument passed in the command line to the data type
|
||||
-%% indicated by the argument specification.
|
||||
--spec convert_option_arg(option_spec(), string()) -> compound_option().
|
||||
-convert_option_arg({Name, _Short, _Long, ArgSpec, _Help}, Arg) ->
|
||||
- try
|
||||
- {Name, to_type(arg_spec_type(ArgSpec), Arg)}
|
||||
- catch
|
||||
- error:_ ->
|
||||
- throw({error, {invalid_option_arg, {Name, Arg}}})
|
||||
-%% @doc Add an option with an implicit or assumed argument.
|
||||
--spec add_option_with_implicit_incrementable_arg(option_spec() | arg_spec(), [option()]) -> [option()].
|
||||
-add_option_with_implicit_incrementable_arg({Name, _Short, _Long, ArgSpec, _Help}, OptAcc) ->
|
||||
- case arg_spec_type(ArgSpec) of
|
||||
- boolean ->
|
||||
- %% Special case for boolean arguments: if there is no argument we
|
||||
- %% set the value to 'true'.
|
||||
- [{Name, true} | OptAcc];
|
||||
- integer ->
|
||||
- %% Special case for integer arguments: if the option had not been set
|
||||
- %% before we set the value to 1; if not we increment the previous value
|
||||
- %% the option had. This is needed to support options like "-vvv" to
|
||||
- %% return something like {verbose, 3}.
|
||||
- case OptAcc of
|
||||
- [{Name, Count} | Tail] ->
|
||||
- [{Name, Count + 1} | Tail];
|
||||
- _ ->
|
||||
- [{Name, 1} | OptAcc]
|
||||
- end;
|
||||
- _ ->
|
||||
- throw({error, {missing_option_arg, Name}})
|
||||
- end.
|
||||
-
|
||||
-
|
||||
@ -317,7 +399,9 @@ index bb7fae2..0000000
|
||||
-
|
||||
-
|
||||
-%% @doc Convert an argument string to its corresponding data type.
|
||||
--spec to_type(arg_type(), string()) -> arg_value().
|
||||
--spec to_type(arg_spec() | arg_type(), string()) -> arg_value().
|
||||
-to_type({Type, _DefaultArg}, Arg) ->
|
||||
- to_type(Type, Arg);
|
||||
-to_type(binary, Arg) ->
|
||||
- list_to_binary(Arg);
|
||||
-to_type(atom, Arg) ->
|
||||
@ -365,13 +449,24 @@ index bb7fae2..0000000
|
||||
-is_valid_arg(boolean, Arg) ->
|
||||
- is_boolean_arg(Arg);
|
||||
-is_valid_arg(integer, Arg) ->
|
||||
- is_integer_arg(Arg);
|
||||
- is_non_neg_integer_arg(Arg);
|
||||
-is_valid_arg(float, Arg) ->
|
||||
- is_float_arg(Arg);
|
||||
- is_non_neg_float_arg(Arg);
|
||||
-is_valid_arg(_Type, _Arg) ->
|
||||
- true.
|
||||
-
|
||||
-
|
||||
--spec is_implicit_arg(arg_spec(), nonempty_string()) -> boolean().
|
||||
-is_implicit_arg({Type, _DefaultArg}, Arg) ->
|
||||
- is_implicit_arg(Type, Arg);
|
||||
-is_implicit_arg(boolean, Arg) ->
|
||||
- not is_boolean_arg(Arg);
|
||||
-is_implicit_arg(integer, Arg) ->
|
||||
- not is_integer_arg(Arg);
|
||||
-is_implicit_arg(_Type, _Arg) ->
|
||||
- false.
|
||||
-
|
||||
-
|
||||
--spec is_boolean_arg(string()) -> boolean().
|
||||
-is_boolean_arg(Arg) ->
|
||||
- LowerArg = string:to_lower(Arg),
|
||||
@ -379,51 +474,76 @@ index bb7fae2..0000000
|
||||
-
|
||||
-
|
||||
--spec is_integer_arg(string()) -> boolean().
|
||||
-is_integer_arg([Head | Tail]) when Head >= $0, Head =< $9 ->
|
||||
- is_integer_arg(Tail);
|
||||
-is_integer_arg([_Head | _Tail]) ->
|
||||
-is_integer_arg("-" ++ Tail) ->
|
||||
- is_non_neg_integer_arg(Tail);
|
||||
-is_integer_arg(Arg) ->
|
||||
- is_non_neg_integer_arg(Arg).
|
||||
-
|
||||
-
|
||||
--spec is_non_neg_integer_arg(string()) -> boolean().
|
||||
-is_non_neg_integer_arg([Head | Tail]) when Head >= $0, Head =< $9 ->
|
||||
- is_non_neg_integer_arg(Tail);
|
||||
-is_non_neg_integer_arg([_Head | _Tail]) ->
|
||||
- false;
|
||||
-is_integer_arg([]) ->
|
||||
-is_non_neg_integer_arg([]) ->
|
||||
- true.
|
||||
-
|
||||
-
|
||||
--spec is_float_arg(string()) -> boolean().
|
||||
-is_float_arg([Head | Tail]) when (Head >= $0 andalso Head =< $9) orelse Head =:= $. ->
|
||||
- is_float_arg(Tail);
|
||||
-is_float_arg([_Head | _Tail]) ->
|
||||
--spec is_non_neg_float_arg(string()) -> boolean().
|
||||
-is_non_neg_float_arg([Head | Tail]) when (Head >= $0 andalso Head =< $9) orelse Head =:= $. ->
|
||||
- is_non_neg_float_arg(Tail);
|
||||
-is_non_neg_float_arg([_Head | _Tail]) ->
|
||||
- false;
|
||||
-is_float_arg([]) ->
|
||||
-is_non_neg_float_arg([]) ->
|
||||
- true.
|
||||
-
|
||||
-
|
||||
-%% @doc Show a message on stdout indicating the command line options and
|
||||
-%% @doc Show a message on standard_error indicating the command line options and
|
||||
-%% arguments that are supported by the program.
|
||||
--spec usage([option_spec()], string()) -> ok.
|
||||
-usage(OptSpecList, ProgramName) ->
|
||||
- io:format("Usage: ~s~s~n~n~s~n",
|
||||
- [ProgramName, usage_cmd_line(OptSpecList), usage_options(OptSpecList)]).
|
||||
- usage(OptSpecList, ProgramName, standard_error).
|
||||
-
|
||||
-
|
||||
-%% @doc Show a message on stdout indicating the command line options and
|
||||
-%% @doc Show a message on standard_error or standard_io indicating the command line options and
|
||||
-%% arguments that are supported by the program.
|
||||
--spec usage([option_spec()], string(), output_stream() | string()) -> ok.
|
||||
-usage(OptSpecList, ProgramName, OutputStream) when is_atom(OutputStream) ->
|
||||
- io:format(OutputStream, "Usage: ~s~s~n~n~s~n",
|
||||
- [ProgramName, usage_cmd_line(OptSpecList), usage_options(OptSpecList)]);
|
||||
-%% @doc Show a message on standard_error indicating the command line options and
|
||||
-%% arguments that are supported by the program. The CmdLineTail argument
|
||||
-%% is a string that is added to the end of the usage command line.
|
||||
--spec usage([option_spec()], string(), string()) -> ok.
|
||||
-usage(OptSpecList, ProgramName, CmdLineTail) ->
|
||||
- io:format("Usage: ~s~s ~s~n~n~s~n",
|
||||
- [ProgramName, usage_cmd_line(OptSpecList), CmdLineTail, usage_options(OptSpecList)]).
|
||||
- usage(OptSpecList, ProgramName, CmdLineTail, standard_error).
|
||||
-
|
||||
-
|
||||
-%% @doc Show a message on stdout indicating the command line options and
|
||||
-%% @doc Show a message on standard_error or standard_io indicating the command line options and
|
||||
-%% arguments that are supported by the program. The CmdLineTail argument
|
||||
-%% is a string that is added to the end of the usage command line.
|
||||
--spec usage([option_spec()], string(), string(), output_stream() | [{string(), string()}]) -> ok.
|
||||
-usage(OptSpecList, ProgramName, CmdLineTail, OutputStream) when is_atom(OutputStream) ->
|
||||
- io:format(OutputStream, "Usage: ~s~s ~s~n~n~s~n",
|
||||
- [ProgramName, usage_cmd_line(OptSpecList), CmdLineTail, usage_options(OptSpecList)]);
|
||||
-%% @doc Show a message on standard_error indicating the command line options and
|
||||
-%% arguments that are supported by the program. The CmdLineTail and OptionsTail
|
||||
-%% arguments are a string that is added to the end of the usage command line
|
||||
-%% and a list of tuples that are added to the end of the options' help lines.
|
||||
--spec usage([option_spec()], string(), string(), [{string(), string()}]) -> ok.
|
||||
-usage(OptSpecList, ProgramName, CmdLineTail, OptionsTail) ->
|
||||
- usage(OptSpecList, ProgramName, CmdLineTail, OptionsTail, standard_error).
|
||||
-
|
||||
-
|
||||
-%% @doc Show a message on standard_error or standard_io indicating the command line options and
|
||||
-%% arguments that are supported by the program. The CmdLineTail and OptionsTail
|
||||
-%% arguments are a string that is added to the end of the usage command line
|
||||
-%% and a list of tuples that are added to the end of the options' help lines.
|
||||
--spec usage([option_spec()], string(), string(), [{string(), string()}], output_stream()) -> ok.
|
||||
-usage(OptSpecList, ProgramName, CmdLineTail, OptionsTail, OutputStream) ->
|
||||
- UsageOptions = lists:foldl(
|
||||
- fun ({Prefix, Help}, Acc) ->
|
||||
- add_option_help(Prefix, Help, Acc)
|
||||
- end, usage_options_reverse(OptSpecList, []), OptionsTail),
|
||||
- io:format("Usage: ~s~s ~s~n~n~s~n",
|
||||
- io:format(OutputStream, "Usage: ~s~s ~s~n~n~s~n",
|
||||
- [ProgramName, usage_cmd_line(OptSpecList), CmdLineTail,
|
||||
- lists:flatten(lists:reverse(UsageOptions))]).
|
||||
-
|
||||
@ -439,10 +559,10 @@ index bb7fae2..0000000
|
||||
- case ArgSpec of
|
||||
- undefined ->
|
||||
- if
|
||||
- % For options with short form and no argument.
|
||||
- %% For options with short form and no argument.
|
||||
- Short =/= undefined ->
|
||||
- [$\s, $[, $-, Short, $]];
|
||||
- % For options with only long form and no argument.
|
||||
- %% For options with only long form and no argument.
|
||||
- Long =/= undefined ->
|
||||
- [$\s, $[, $-, $-, Long, $]];
|
||||
- true ->
|
||||
@ -450,13 +570,13 @@ index bb7fae2..0000000
|
||||
- end;
|
||||
- _ ->
|
||||
- if
|
||||
- % For options with short form and argument.
|
||||
- %% For options with short form and argument.
|
||||
- Short =/= undefined ->
|
||||
- [$\s, $[, $-, Short, $\s, $<, atom_to_list(Name), $>, $]];
|
||||
- % For options with only long form and argument.
|
||||
- %% For options with only long form and argument.
|
||||
- Long =/= undefined ->
|
||||
- [$\s, $[, $-, $-, Long, $\s, $<, atom_to_list(Name), $>, $]];
|
||||
- % For options with neither short nor long form and argument.
|
||||
- %% For options with neither short nor long form and argument.
|
||||
- true ->
|
||||
- [$\s, $<, atom_to_list(Name), $>]
|
||||
- end
|
||||
@ -477,19 +597,19 @@ index bb7fae2..0000000
|
||||
- case Long of
|
||||
- undefined ->
|
||||
- case Short of
|
||||
- % Neither short nor long form (non-option argument).
|
||||
- %% Neither short nor long form (non-option argument).
|
||||
- undefined ->
|
||||
- [$<, atom_to_list(Name), $>];
|
||||
- % Only short form.
|
||||
- %% Only short form.
|
||||
- _ ->
|
||||
- [$-, Short]
|
||||
- end;
|
||||
- _ ->
|
||||
- case Short of
|
||||
- % Only long form.
|
||||
- %% Only long form.
|
||||
- undefined ->
|
||||
- [$-, $- | Long];
|
||||
- % Both short and long form.
|
||||
- %% Both short and long form.
|
||||
- _ ->
|
||||
- [$-, Short, $,, $\s, $-, $- | Long]
|
||||
- end
|
||||
@ -532,5 +652,5 @@ index bb7fae2..0000000
|
||||
- T
|
||||
- end.
|
||||
--
|
||||
1.7.2.3
|
||||
1.7.10.1
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user