Update to the latest git snapshot
Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
This commit is contained in:
parent
3111af8041
commit
f41c5eb8fa
|
@ -1 +1,2 @@
|
||||||
/basho-rebar-RELEASE-1-327-g90058c7.tar.gz
|
/basho-rebar-RELEASE-1-327-g90058c7.tar.gz
|
||||||
|
/basho-rebar-RELEASE-1-821-g635d1a9.tar.gz
|
||||||
|
|
|
@ -1,17 +1,19 @@
|
||||||
%global realname rebar
|
%global realname rebar
|
||||||
|
%global upstream basho
|
||||||
%global debug_package %{nil}
|
%global debug_package %{nil}
|
||||||
%global git_tag 90058c7
|
%global git_tag 635d1a9
|
||||||
|
%global patchnumber 821
|
||||||
|
|
||||||
|
|
||||||
Name: erlang-%{realname}
|
Name: erlang-%{realname}
|
||||||
Version: 2
|
Version: 2
|
||||||
Release: 5.20101120git%{git_tag}%{?dist}
|
Release: 6.20120514git%{git_tag}%{?dist}
|
||||||
Summary: Erlang Build Tools
|
Summary: Erlang Build Tools
|
||||||
Group: Development/Tools
|
Group: Development/Tools
|
||||||
License: MIT
|
License: MIT
|
||||||
URL: https://github.com/basho/rebar
|
URL: https://github.com/basho/rebar
|
||||||
# wget --no-check-certificate https://github.com/basho/rebar/tarball/90058c7
|
# wget --no-check-certificate --content-disposition https://github.com/basho/rebar/zipball/635d1a9
|
||||||
Source0: basho-%{realname}-RELEASE-1-327-g%{git_tag}.tar.gz
|
Source0: %{upstream}-%{realname}-RELEASE-1-%{patchnumber}-g%{git_tag}.tar.gz
|
||||||
Source1: rebar.escript
|
Source1: rebar.escript
|
||||||
Patch1: rebar-0001-No-need-to-create-bundle.patch
|
Patch1: rebar-0001-No-need-to-create-bundle.patch
|
||||||
Patch2: rebar-0002-Remove-bundled-mustache.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-erts >= R13B-03
|
||||||
BuildRequires: erlang-getopt
|
BuildRequires: erlang-getopt
|
||||||
BuildRequires: erlang-reltool
|
BuildRequires: erlang-reltool
|
||||||
|
#Requires: erlang-abnfc
|
||||||
Requires: erlang-asn1
|
Requires: erlang-asn1
|
||||||
Requires: erlang-compiler
|
Requires: erlang-compiler
|
||||||
Requires: erlang-crypto
|
Requires: erlang-crypto
|
||||||
|
@ -47,7 +50,7 @@ Erlang Build Tools.
|
||||||
|
|
||||||
|
|
||||||
%prep
|
%prep
|
||||||
%setup -q -n basho-%{realname}-%{git_tag}
|
%setup -q -n %{upstream}-%{realname}-%{git_tag}
|
||||||
%patch1 -p1 -b .no_bundle
|
%patch1 -p1 -b .no_bundle
|
||||||
%patch2 -p1 -b .remove_bundled_mustache
|
%patch2 -p1 -b .remove_bundled_mustache
|
||||||
%patch3 -p1 -b .remove_bundled_getopt
|
%patch3 -p1 -b .remove_bundled_getopt
|
||||||
|
@ -80,6 +83,9 @@ rm -rf $RPM_BUILD_ROOT
|
||||||
|
|
||||||
|
|
||||||
%changelog
|
%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
|
* 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
|
- 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>
|
From: Peter Lemenkov <lemenkov@gmail.com>
|
||||||
Date: Tue, 28 Sep 2010 23:04:36 +0400
|
Date: Tue, 28 Sep 2010 23:04:36 +0400
|
||||||
Subject: [PATCH 1/3] No need to create bundle
|
Subject: [PATCH 1/3] No need to create bundle
|
||||||
|
|
||||||
Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
|
Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
|
||||||
---
|
---
|
||||||
bootstrap | 38 +-------------------------------------
|
bootstrap | 40 ----------------------------------------
|
||||||
1 files changed, 1 insertions(+), 37 deletions(-)
|
1 file changed, 40 deletions(-)
|
||||||
|
|
||||||
diff --git a/bootstrap b/bootstrap
|
diff --git a/bootstrap b/bootstrap
|
||||||
index 5be3183..634e1f6 100755
|
index e86ad8e..c4992a7 100755
|
||||||
--- a/bootstrap
|
--- a/bootstrap
|
||||||
+++ b/bootstrap
|
+++ b/bootstrap
|
||||||
@@ -51,43 +51,7 @@ main(Args) ->
|
@@ -52,46 +52,6 @@ main(Args) ->
|
||||||
true = code:add_path("ebin"),
|
|
||||||
|
|
||||||
%% Run rebar to do proper .app validation and such
|
%% Run rebar to do proper .app validation and such
|
||||||
- rebar:main(["compile"] ++ Args),
|
rebar:main(["compile"] ++ Args),
|
||||||
-
|
|
||||||
- %% Read the contents of the files in ebin and templates; note that we place
|
- %% Read the contents of the files in ebin and templates; note that we
|
||||||
- %% all the beam files at the top level of the code archive so that code loading
|
- %% place all the beam files at the top level of the code archive so
|
||||||
- %% works properly.
|
- %% that code loading works properly.
|
||||||
- Files = load_files("*", "ebin") ++ load_files("priv/templates/*", "."),
|
- Files = load_files("*", "ebin") ++ load_files("priv/templates/*", "."),
|
||||||
-
|
-
|
||||||
- case zip:create("mem", Files, [memory]) of
|
- case zip:create("mem", Files, [memory]) of
|
||||||
- {ok, {"mem", ZipBin}} ->
|
- {ok, {"mem", ZipBin}} ->
|
||||||
- %% Archive was successfully created. Prefix that binary with our
|
- %% Archive was successfully created. Prefix that binary with our
|
||||||
- %% header and write to "rebar" file
|
- %% header and write to "rebar" file.
|
||||||
- Script = <<"#!/usr/bin/env escript\n%%! -noshell -noinput\n", ZipBin/binary>>,
|
- %% 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
|
- case file:write_file("rebar", Script) of
|
||||||
- ok ->
|
- ok ->
|
||||||
- ok;
|
- ok;
|
||||||
- {error, WriteError} ->
|
- {error, WriteError} ->
|
||||||
- io:format("Failed to write rebar script: ~p\n", [WriteError]),
|
- io:format("Failed to write rebar script: ~p\n",
|
||||||
|
- [WriteError]),
|
||||||
- halt(1)
|
- halt(1)
|
||||||
- end;
|
- end;
|
||||||
- {error, ZipError} ->
|
- {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)
|
- halt(1)
|
||||||
- end,
|
- 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
|
- case os:type() of
|
||||||
- {unix,_} ->
|
- {unix,_} ->
|
||||||
- [] = os:cmd("chmod u+x rebar"),
|
- [] = os:cmd("chmod u+x rebar"),
|
||||||
- ok;
|
- ok;
|
||||||
|
- {win32,_} ->
|
||||||
|
- write_windows_scripts(),
|
||||||
|
- ok;
|
||||||
- _ ->
|
- _ ->
|
||||||
- ok
|
- ok
|
||||||
- end,
|
- end,
|
||||||
-
|
-
|
||||||
- %% Add a helpful message
|
%% Add a helpful message
|
||||||
- io:format("Congratulations! You now have a self-contained script called \"rebar\" in\n"
|
io:format("Congratulations! You now have a self-contained script called"
|
||||||
- "your current working directory. Place this script anywhere in your path\n"
|
" \"rebar\" in\n"
|
||||||
- "and you can use rebar to build OTP-compliant apps.\n").
|
|
||||||
+ rebar:main(["compile"] ++ Args).
|
|
||||||
|
|
||||||
rm(Path) ->
|
|
||||||
NativePath = filename:nativename(Path),
|
|
||||||
--
|
--
|
||||||
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>
|
From: Peter Lemenkov <lemenkov@gmail.com>
|
||||||
Date: Sat, 20 Nov 2010 16:36:45 +0300
|
Date: Sat, 20 Nov 2010 16:36:45 +0300
|
||||||
Subject: [PATCH 2/3] Remove bundled mustache
|
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>
|
Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
|
||||||
---
|
---
|
||||||
ebin/rebar.app | 3 +-
|
ebin/rebar.app | 3 +-
|
||||||
src/mustache.erl | 219 ------------------------------------------------------
|
src/mustache.erl | 234 ------------------------------------------------------
|
||||||
2 files changed, 1 insertions(+), 221 deletions(-)
|
2 files changed, 1 insertion(+), 236 deletions(-)
|
||||||
delete mode 100644 src/mustache.erl
|
delete mode 100644 src/mustache.erl
|
||||||
|
|
||||||
diff --git a/ebin/rebar.app b/ebin/rebar.app
|
diff --git a/ebin/rebar.app b/ebin/rebar.app
|
||||||
index 6f9b6f5..75aaec1 100644
|
index 0c6e4c3..0836c7c 100644
|
||||||
--- a/ebin/rebar.app
|
--- a/ebin/rebar.app
|
||||||
+++ b/ebin/rebar.app
|
+++ b/ebin/rebar.app
|
||||||
@@ -33,8 +33,7 @@
|
@@ -35,8 +35,7 @@
|
||||||
rebar_templater,
|
rebar_upgrade,
|
||||||
rebar_utils,
|
rebar_utils,
|
||||||
rebar_xref,
|
rebar_xref,
|
||||||
- getopt,
|
- getopt,
|
||||||
|
@ -26,24 +26,24 @@ index 6f9b6f5..75aaec1 100644
|
||||||
stdlib,
|
stdlib,
|
||||||
diff --git a/src/mustache.erl b/src/mustache.erl
|
diff --git a/src/mustache.erl b/src/mustache.erl
|
||||||
deleted file mode 100644
|
deleted file mode 100644
|
||||||
index df81aed..0000000
|
index ac501a0..0000000
|
||||||
--- a/src/mustache.erl
|
--- a/src/mustache.erl
|
||||||
+++ /dev/null
|
+++ /dev/null
|
||||||
@@ -1,219 +0,0 @@
|
@@ -1,234 +0,0 @@
|
||||||
-%% The MIT License
|
-%% The MIT License
|
||||||
-%%
|
-%%
|
||||||
-%% Copyright (c) 2009 Tom Preston-Werner <tom@mojombo.com>
|
-%% Copyright (c) 2009 Tom Preston-Werner <tom@mojombo.com>
|
||||||
-%%
|
-%%
|
||||||
-%% Permission is hereby granted, free of charge, to any person obtaining a copy
|
-%% Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
-%% of this software and associated documentation files (the "Software"), to deal
|
-%% of this software and associated documentation files (the "Software"), to deal
|
||||||
-%% in the Software without restriction, including without limitation the rights
|
-%% in the Software without restriction, including without limitation the rights
|
||||||
-%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
-%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
-%% copies of the Software, and to permit persons to whom the Software is
|
-%% copies of the Software, and to permit persons to whom the Software is
|
||||||
-%% furnished to do so, subject to the following conditions:
|
-%% furnished to do so, subject to the following conditions:
|
||||||
-%%
|
-%%
|
||||||
-%% The above copyright notice and this permission notice shall be included in
|
-%% The above copyright notice and this permission notice shall be included in
|
||||||
-%% all copies or substantial portions of the Software.
|
-%% all copies or substantial portions of the Software.
|
||||||
-%%
|
-%%
|
||||||
-%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
-%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
-%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
-%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
-%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
-%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
@ -63,6 +63,10 @@ index df81aed..0000000
|
||||||
- section_re = undefined,
|
- section_re = undefined,
|
||||||
- tag_re = undefined}).
|
- tag_re = undefined}).
|
||||||
-
|
-
|
||||||
|
--ifdef(TEST).
|
||||||
|
--include_lib("eunit/include/eunit.hrl").
|
||||||
|
--endif.
|
||||||
|
-
|
||||||
-compile(Body) when is_list(Body) ->
|
-compile(Body) when is_list(Body) ->
|
||||||
- State = #mstate{},
|
- State = #mstate{},
|
||||||
- CompiledTemplate = pre_compile(Body, State),
|
- CompiledTemplate = pre_compile(Body, State),
|
||||||
|
@ -161,8 +165,8 @@ index df81aed..0000000
|
||||||
- Content = string:substr(T, C0 + 1, C1),
|
- Content = string:substr(T, C0 + 1, C1),
|
||||||
- Kind = tag_kind(T, K),
|
- Kind = tag_kind(T, K),
|
||||||
- Result = compile_tag(Kind, Content, State),
|
- Result = compile_tag(Kind, Content, State),
|
||||||
- "[\"" ++ Front ++
|
- "[\"" ++ Front ++
|
||||||
- "\" | [" ++ Result ++
|
- "\" | [" ++ Result ++
|
||||||
- " | " ++ compile_tags(Back, State) ++ "]]";
|
- " | " ++ compile_tags(Back, State) ++ "]]";
|
||||||
- nomatch ->
|
- nomatch ->
|
||||||
- "[\"" ++ T ++ "\"]"
|
- "[\"" ++ T ++ "\"]"
|
||||||
|
@ -222,8 +226,6 @@ index df81aed..0000000
|
||||||
- integer_to_list(Val);
|
- integer_to_list(Val);
|
||||||
-to_s(Val) when is_float(Val) ->
|
-to_s(Val) when is_float(Val) ->
|
||||||
- io_lib:format("~.2f", [Val]);
|
- io_lib:format("~.2f", [Val]);
|
||||||
-to_s(Val) when is_boolean(Val) ->
|
|
||||||
- Val;
|
|
||||||
-to_s(Val) when is_atom(Val) ->
|
-to_s(Val) when is_atom(Val) ->
|
||||||
- atom_to_list(Val);
|
- atom_to_list(Val);
|
||||||
-to_s(Val) ->
|
-to_s(Val) ->
|
||||||
|
@ -248,7 +250,20 @@ index df81aed..0000000
|
||||||
-start([T]) ->
|
-start([T]) ->
|
||||||
- Out = render(list_to_atom(T)),
|
- Out = render(list_to_atom(T)),
|
||||||
- io:format(Out ++ "~n", []).
|
- 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>
|
From: Peter Lemenkov <lemenkov@gmail.com>
|
||||||
Date: Sat, 20 Nov 2010 16:40:15 +0300
|
Date: Sat, 20 Nov 2010 16:40:15 +0300
|
||||||
Subject: [PATCH 3/3] Remove bundled getopt
|
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>
|
Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
|
||||||
---
|
---
|
||||||
ebin/rebar.app | 3 +-
|
ebin/rebar.app | 3 +-
|
||||||
src/getopt.erl | 501 --------------------------------------------------------
|
src/getopt.erl | 621 --------------------------------------------------------
|
||||||
2 files changed, 1 insertions(+), 503 deletions(-)
|
2 files changed, 1 insertion(+), 623 deletions(-)
|
||||||
delete mode 100644 src/getopt.erl
|
delete mode 100644 src/getopt.erl
|
||||||
|
|
||||||
diff --git a/ebin/rebar.app b/ebin/rebar.app
|
diff --git a/ebin/rebar.app b/ebin/rebar.app
|
||||||
index 75aaec1..8589819 100644
|
index 0836c7c..a9dc46d 100644
|
||||||
--- a/ebin/rebar.app
|
--- a/ebin/rebar.app
|
||||||
+++ b/ebin/rebar.app
|
+++ b/ebin/rebar.app
|
||||||
@@ -32,8 +32,7 @@
|
@@ -34,8 +34,7 @@
|
||||||
rebar_subdirs,
|
|
||||||
rebar_templater,
|
rebar_templater,
|
||||||
|
rebar_upgrade,
|
||||||
rebar_utils,
|
rebar_utils,
|
||||||
- rebar_xref,
|
- rebar_xref,
|
||||||
- getopt ]},
|
- getopt ]},
|
||||||
+ rebar_xref ]},
|
+ rebar_xref]},
|
||||||
{registered, []},
|
{registered, []},
|
||||||
{applications, [kernel,
|
{applications, [kernel,
|
||||||
stdlib,
|
stdlib,
|
||||||
diff --git a/src/getopt.erl b/src/getopt.erl
|
diff --git a/src/getopt.erl b/src/getopt.erl
|
||||||
deleted file mode 100644
|
deleted file mode 100644
|
||||||
index bb7fae2..0000000
|
index 175b7a5..0000000
|
||||||
--- a/src/getopt.erl
|
--- a/src/getopt.erl
|
||||||
+++ /dev/null
|
+++ /dev/null
|
||||||
@@ -1,501 +0,0 @@
|
@@ -1,621 +0,0 @@
|
||||||
-%%%-------------------------------------------------------------------
|
-%%%-------------------------------------------------------------------
|
||||||
-%%% @author Juan Jose Comellas <juanjo@comellas.org>
|
-%%% @author Juan Jose Comellas <juanjo@comellas.org>
|
||||||
-%%% @copyright (C) 2009 Juan Jose Comellas
|
-%%% @copyright (C) 2009 Juan Jose Comellas
|
||||||
|
@ -45,6 +45,13 @@ index bb7fae2..0000000
|
||||||
-
|
-
|
||||||
--export([parse/2, usage/2, usage/3, usage/4]).
|
--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).
|
--define(TAB_LENGTH, 8).
|
||||||
-%% Indentation of the help messages in number of tabs.
|
-%% Indentation of the help messages in number of tabs.
|
||||||
|
@ -78,6 +85,8 @@ index bb7fae2..0000000
|
||||||
- ArgSpec :: arg_spec(),
|
- ArgSpec :: arg_spec(),
|
||||||
- Help :: string() | undefined
|
- 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
|
-%% @doc Parse the command line options and arguments returning a list of tuples
|
||||||
|
@ -104,26 +113,25 @@ index bb7fae2..0000000
|
||||||
- {ok, {[option()], [string()]}}.
|
- {ok, {[option()], [string()]}}.
|
||||||
-%% Process the option terminator.
|
-%% Process the option terminator.
|
||||||
-parse(OptSpecList, OptAcc, ArgAcc, _ArgPos, ["--" | Tail]) ->
|
-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)}};
|
- {ok, {lists:reverse(append_default_options(OptSpecList, OptAcc)), lists:reverse(ArgAcc, Tail)}};
|
||||||
-%% Process long options.
|
-%% Process long options.
|
||||||
-parse(OptSpecList, OptAcc, ArgAcc, ArgPos, [[$-, $- | OptArg] = OptStr | Tail]) ->
|
-parse(OptSpecList, OptAcc, ArgAcc, ArgPos, ["--" ++ OptArg = OptStr | Tail]) ->
|
||||||
- parse_option_long(OptSpecList, OptAcc, ArgAcc, ArgPos, Tail, OptStr, OptArg);
|
- parse_long_option(OptSpecList, OptAcc, ArgAcc, ArgPos, Tail, OptStr, OptArg);
|
||||||
-%% Process short options.
|
-%% Process short options.
|
||||||
-parse(OptSpecList, OptAcc, ArgAcc, ArgPos, [[$- | [_Char | _] = OptArg] = OptStr | Tail]) ->
|
-parse(OptSpecList, OptAcc, ArgAcc, ArgPos, ["-" ++ ([_Char | _] = OptArg) = OptStr | Tail]) ->
|
||||||
- parse_option_short(OptSpecList, OptAcc, ArgAcc, ArgPos, Tail, OptStr, OptArg);
|
- parse_short_option(OptSpecList, OptAcc, ArgAcc, ArgPos, Tail, OptStr, OptArg);
|
||||||
-%% Process non-option arguments.
|
-%% Process non-option arguments.
|
||||||
-parse(OptSpecList, OptAcc, ArgAcc, ArgPos, [Arg | Tail]) ->
|
-parse(OptSpecList, OptAcc, ArgAcc, ArgPos, [Arg | Tail]) ->
|
||||||
- case find_non_option_arg(OptSpecList, ArgPos) of
|
- case find_non_option_arg(OptSpecList, ArgPos) of
|
||||||
- {value, OptSpec} when ?IS_OPT_SPEC(OptSpec) ->
|
- {value, OptSpec} when ?IS_OPT_SPEC(OptSpec) ->
|
||||||
- parse(OptSpecList, [convert_option_arg(OptSpec, Arg) | OptAcc],
|
- parse(OptSpecList, add_option_with_arg(OptSpec, Arg, OptAcc), ArgAcc, ArgPos + 1, Tail);
|
||||||
- ArgAcc, ArgPos + 1, Tail);
|
|
||||||
- false ->
|
- false ->
|
||||||
- parse(OptSpecList, OptAcc, [Arg | ArgAcc], ArgPos, Tail)
|
- parse(OptSpecList, OptAcc, [Arg | ArgAcc], ArgPos, Tail)
|
||||||
- end;
|
- end;
|
||||||
-parse(OptSpecList, OptAcc, ArgAcc, _ArgPos, []) ->
|
-parse(OptSpecList, OptAcc, ArgAcc, _ArgPos, []) ->
|
||||||
- % Once we have completed gathering the options we add the ones that were
|
- %% Once we have completed gathering the options we add the ones that were
|
||||||
- % not present but had default arguments in the specification.
|
- %% not present but had default arguments in the specification.
|
||||||
- {ok, {lists:reverse(append_default_options(OptSpecList, OptAcc)), lists:reverse(ArgAcc)}}.
|
- {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 Single option 'foo', no argument
|
||||||
-%% --foo=bar Single option 'foo', argument "bar"
|
-%% --foo=bar Single option 'foo', argument "bar"
|
||||||
-%% --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()]}}.
|
- {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
|
- case split_assigned_arg(OptArg) of
|
||||||
- {Long, Arg} ->
|
- {Long, Arg} ->
|
||||||
- % Get option that has its argument within the same string
|
- %% Get option that has its argument within the same string
|
||||||
- % separated by an equal ('=') character (e.g. "--port=1000").
|
- %% separated by an equal ('=') character (e.g. "--port=1000").
|
||||||
- parse_option_assigned_arg(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptStr, Long, Arg);
|
- parse_long_option_assigned_arg(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptStr, Long, Arg);
|
||||||
-
|
-
|
||||||
- Long ->
|
- Long ->
|
||||||
- case lists:keysearch(Long, ?OPT_LONG, OptSpecList) of
|
- case lists:keyfind(Long, ?OPT_LONG, OptSpecList) of
|
||||||
- {value, {Name, _Short, Long, undefined, _Help}} ->
|
- {Name, _Short, Long, undefined, _Help} ->
|
||||||
- parse(OptSpecList, [Name | OptAcc], ArgAcc, ArgPos, Args);
|
- parse(OptSpecList, [Name | OptAcc], ArgAcc, ArgPos, Args);
|
||||||
-
|
-
|
||||||
- {value, {_Name, _Short, Long, _ArgSpec, _Help} = OptSpec} ->
|
- {_Name, _Short, Long, _ArgSpec, _Help} = OptSpec ->
|
||||||
- % The option argument string is empty, but the option requires
|
- %% The option argument string is empty, but the option requires
|
||||||
- % an argument, so we look into the next string in the list.
|
- %% an argument, so we look into the next string in the list.
|
||||||
- parse_option_next_arg(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptSpec);
|
- %% e.g ["--port", "1000"]
|
||||||
|
- parse_long_option_next_arg(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptSpec);
|
||||||
- false ->
|
- false ->
|
||||||
- throw({error, {invalid_option, OptStr}})
|
- throw({error, {invalid_option, OptStr}})
|
||||||
- end
|
- end
|
||||||
|
@ -160,17 +169,17 @@ index bb7fae2..0000000
|
||||||
-%% @doc Parse an option where the argument is 'assigned' in the same string using
|
-%% @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
|
-%% 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.
|
-%% rest of the arguments recursively. This syntax is only valid for long options.
|
||||||
--spec parse_option_assigned_arg([option_spec()], [option()], [string()], integer(),
|
--spec parse_long_option_assigned_arg([option_spec()], [option()], [string()], integer(),
|
||||||
- [string()], string(), string(), string()) ->
|
- [string()], string(), string(), string()) ->
|
||||||
- {ok, {[option()], [string()]}}.
|
- {ok, {[option()], [string()]}}.
|
||||||
-parse_option_assigned_arg(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptStr, Long, Arg) ->
|
-parse_long_option_assigned_arg(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptStr, Long, Arg) ->
|
||||||
- case lists:keysearch(Long, ?OPT_LONG, OptSpecList) of
|
- case lists:keyfind(Long, ?OPT_LONG, OptSpecList) of
|
||||||
- {value, {_Name, _Short, Long, ArgSpec, _Help} = OptSpec} ->
|
- {_Name, _Short, Long, ArgSpec, _Help} = OptSpec ->
|
||||||
- case ArgSpec of
|
- case ArgSpec of
|
||||||
- undefined ->
|
- undefined ->
|
||||||
- throw({error, {invalid_option_arg, OptStr}});
|
- 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;
|
- end;
|
||||||
- false ->
|
- false ->
|
||||||
- throw({error, {invalid_option, OptStr}})
|
- throw({error, {invalid_option, OptStr}})
|
||||||
|
@ -183,7 +192,7 @@ index bb7fae2..0000000
|
||||||
-split_assigned_arg(OptStr) ->
|
-split_assigned_arg(OptStr) ->
|
||||||
- split_assigned_arg(OptStr, OptStr, []).
|
- split_assigned_arg(OptStr, OptStr, []).
|
||||||
-
|
-
|
||||||
-split_assigned_arg(_OptStr, [$= | Tail], Acc) ->
|
-split_assigned_arg(_OptStr, "=" ++ Tail, Acc) ->
|
||||||
- {lists:reverse(Acc), Tail};
|
- {lists:reverse(Acc), Tail};
|
||||||
-split_assigned_arg(OptStr, [Char | Tail], Acc) ->
|
-split_assigned_arg(OptStr, [Char | Tail], Acc) ->
|
||||||
- split_assigned_arg(OptStr, Tail, [Char | Acc]);
|
- split_assigned_arg(OptStr, Tail, [Char | Acc]);
|
||||||
|
@ -191,6 +200,25 @@ index bb7fae2..0000000
|
||||||
- OptStr.
|
- 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
|
-%% @doc Parse a short option, add it to the option accumulator and continue
|
||||||
-%% parsing the rest of the arguments recursively.
|
-%% parsing the rest of the arguments recursively.
|
||||||
-%% A short option can have the following syntax:
|
-%% A short option can have the following syntax:
|
||||||
|
@ -199,57 +227,64 @@ index bb7fae2..0000000
|
||||||
-%% -afoo Single option 'a', argument "foo"
|
-%% -afoo Single option 'a', argument "foo"
|
||||||
-%% -abc Multiple options: 'a'; 'b'; 'c'
|
-%% -abc Multiple options: 'a'; 'b'; 'c'
|
||||||
-%% -bcafoo Multiple options: 'b'; 'c'; 'a' with argument "foo"
|
-%% -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()]}}.
|
- {ok, {[option()], [string()]}}.
|
||||||
-parse_option_short(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptStr, [Short | Arg]) ->
|
-parse_short_option(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptStr, OptArg) ->
|
||||||
- case lists:keysearch(Short, ?OPT_SHORT, OptSpecList) of
|
- parse_short_option(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptStr, first, OptArg).
|
||||||
- {value, {Name, Short, _Long, undefined, _Help}} ->
|
|
||||||
- parse_option_short(OptSpecList, [Name | OptAcc], ArgAcc, ArgPos, Args, OptStr, Arg);
|
|
||||||
-
|
-
|
||||||
- {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
|
- case Arg of
|
||||||
- [] ->
|
- [] ->
|
||||||
- % The option argument string is empty, but the option requires
|
- %% The option argument string is empty, but the option requires
|
||||||
- % an argument, so we look into the next string in the list.
|
- %% an argument, so we look into the next string in the list.
|
||||||
- parse_option_next_arg(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptSpec);
|
- parse_short_option_next_arg(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptSpec, OptPos);
|
||||||
-
|
-
|
||||||
- _ ->
|
- _ ->
|
||||||
- case is_valid_arg(ArgSpec, Arg) of
|
- case is_valid_arg(ArgSpec, Arg) of
|
||||||
- true ->
|
- 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
|
||||||
- end;
|
- end;
|
||||||
-
|
-
|
||||||
- false ->
|
- false ->
|
||||||
- throw({error, {invalid_option, OptStr}})
|
- throw({error, {invalid_option, OptStr}})
|
||||||
- end;
|
- 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).
|
- parse(OptSpecList, OptAcc, ArgAcc, ArgPos, Args).
|
||||||
-
|
-
|
||||||
-
|
-
|
||||||
-%% @doc Retrieve the argument for an option from the next string in the list of
|
-%% @doc Retrieve the argument for an option from the next string in the list of
|
||||||
-%% command-line parameters.
|
-%% command-line parameters or set the value of the argument from the argument
|
||||||
-parse_option_next_arg(OptSpecList, OptAcc, ArgAcc, ArgPos, [Arg | Tail] = Args, {Name, _Short, _Long, ArgSpec, _Help} = OptSpec) ->
|
-%% specification (for boolean and integer arguments), if possible.
|
||||||
- % Special case for booleans: when the next string is an option we assume
|
-parse_short_option_next_arg(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, {Name, _Short, _Long, ArgSpec, _Help} = OptSpec, OptPos) ->
|
||||||
- % the value is 'true'.
|
- case Args =:= [] orelse is_implicit_arg(ArgSpec, hd(Args)) of
|
||||||
- case (arg_spec_type(ArgSpec) =:= boolean) andalso not is_boolean_arg(Arg) of
|
- true when OptPos =:= first ->
|
||||||
|
- parse(OptSpecList, add_option_with_implicit_arg(OptSpec, OptAcc), ArgAcc, ArgPos, Args);
|
||||||
- true ->
|
- true ->
|
||||||
- parse(OptSpecList, [{Name, true} | OptAcc], ArgAcc, ArgPos, Args);
|
- parse(OptSpecList, add_option_with_implicit_incrementable_arg(OptSpec, OptAcc), ArgAcc, ArgPos, Args);
|
||||||
- _ ->
|
- false ->
|
||||||
- parse(OptSpecList, [convert_option_arg(OptSpec, Arg) | OptAcc], ArgAcc, ArgPos, Tail)
|
- [Arg | Tail] = Args,
|
||||||
- end;
|
- try
|
||||||
-parse_option_next_arg(OptSpecList, OptAcc, ArgAcc, ArgPos, [] = Args, {Name, _Short, _Long, ArgSpec, _Help}) ->
|
- parse(OptSpecList, [{Name, to_type(ArgSpec, Arg)} | OptAcc], ArgAcc, ArgPos, Tail)
|
||||||
- % Special case for booleans: when the next string is missing we assume the
|
- catch
|
||||||
- % value is 'true'.
|
- error:_ ->
|
||||||
- case arg_spec_type(ArgSpec) of
|
- throw({error, {invalid_option_arg, {Name, Arg}}})
|
||||||
- boolean ->
|
- end
|
||||||
- parse(OptSpecList, [{Name, true} | OptAcc], ArgAcc, ArgPos, Args);
|
|
||||||
- _ ->
|
|
||||||
- throw({error, {missing_option_arg, Name}})
|
|
||||||
- end.
|
- end.
|
||||||
-
|
-
|
||||||
-
|
-
|
||||||
-%% @doc Find the option for the discrete argument in position specified in the
|
-%% @doc Find the option for the discrete argument in position specified in the
|
||||||
-%% Pos argument.
|
-%% Pos argument.
|
||||||
|
@ -282,29 +317,76 @@ index bb7fae2..0000000
|
||||||
- OptAcc.
|
- OptAcc.
|
||||||
-
|
-
|
||||||
-
|
-
|
||||||
--spec convert_option_no_arg(option_spec()) -> compound_option().
|
-%% @doc Add an option with argument converting it to the data type indicated by the
|
||||||
-convert_option_no_arg({Name, _Short, _Long, ArgSpec, _Help}) ->
|
-%% argument specification.
|
||||||
- case ArgSpec of
|
--spec add_option_with_arg(option_spec(), string(), [option()]) -> [option()].
|
||||||
- % Special case for booleans: if there is no argument we assume
|
-add_option_with_arg({Name, _Short, _Long, ArgSpec, _Help} = OptSpec, Arg, OptAcc) ->
|
||||||
- % the value is 'true'.
|
- case is_valid_arg(ArgSpec, Arg) of
|
||||||
- {boolean, _DefaultValue} ->
|
- true ->
|
||||||
- {Name, 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 ->
|
- 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}})
|
- throw({error, {missing_option_arg, Name}})
|
||||||
- end.
|
- end.
|
||||||
-
|
-
|
||||||
-
|
-
|
||||||
-%% @doc Convert the argument passed in the command line to the data type
|
-%% @doc Add an option with an implicit or assumed argument.
|
||||||
-%% indicated by the argument specification.
|
--spec add_option_with_implicit_incrementable_arg(option_spec() | arg_spec(), [option()]) -> [option()].
|
||||||
--spec convert_option_arg(option_spec(), string()) -> compound_option().
|
-add_option_with_implicit_incrementable_arg({Name, _Short, _Long, ArgSpec, _Help}, OptAcc) ->
|
||||||
-convert_option_arg({Name, _Short, _Long, ArgSpec, _Help}, Arg) ->
|
- case arg_spec_type(ArgSpec) of
|
||||||
- try
|
- boolean ->
|
||||||
- {Name, to_type(arg_spec_type(ArgSpec), Arg)}
|
- %% Special case for boolean arguments: if there is no argument we
|
||||||
- catch
|
- %% set the value to 'true'.
|
||||||
- error:_ ->
|
- [{Name, true} | OptAcc];
|
||||||
- throw({error, {invalid_option_arg, {Name, Arg}}})
|
- 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.
|
- end.
|
||||||
-
|
-
|
||||||
-
|
-
|
||||||
|
@ -317,7 +399,9 @@ index bb7fae2..0000000
|
||||||
-
|
-
|
||||||
-
|
-
|
||||||
-%% @doc Convert an argument string to its corresponding data type.
|
-%% @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) ->
|
-to_type(binary, Arg) ->
|
||||||
- list_to_binary(Arg);
|
- list_to_binary(Arg);
|
||||||
-to_type(atom, Arg) ->
|
-to_type(atom, Arg) ->
|
||||||
|
@ -350,7 +434,7 @@ index bb7fae2..0000000
|
||||||
- (Arg =:= "on") orelse (Arg =:= "enabled") orelse
|
- (Arg =:= "on") orelse (Arg =:= "enabled") orelse
|
||||||
- (Arg =:= "1").
|
- (Arg =:= "1").
|
||||||
-
|
-
|
||||||
-
|
-
|
||||||
--spec is_arg_false(string()) -> boolean().
|
--spec is_arg_false(string()) -> boolean().
|
||||||
-is_arg_false(Arg) ->
|
-is_arg_false(Arg) ->
|
||||||
- (Arg =:= "false") orelse (Arg =:= "f") orelse
|
- (Arg =:= "false") orelse (Arg =:= "f") orelse
|
||||||
|
@ -365,13 +449,24 @@ index bb7fae2..0000000
|
||||||
-is_valid_arg(boolean, Arg) ->
|
-is_valid_arg(boolean, Arg) ->
|
||||||
- is_boolean_arg(Arg);
|
- is_boolean_arg(Arg);
|
||||||
-is_valid_arg(integer, Arg) ->
|
-is_valid_arg(integer, Arg) ->
|
||||||
- is_integer_arg(Arg);
|
- is_non_neg_integer_arg(Arg);
|
||||||
-is_valid_arg(float, Arg) ->
|
-is_valid_arg(float, Arg) ->
|
||||||
- is_float_arg(Arg);
|
- is_non_neg_float_arg(Arg);
|
||||||
-is_valid_arg(_Type, _Arg) ->
|
-is_valid_arg(_Type, _Arg) ->
|
||||||
- true.
|
- 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().
|
--spec is_boolean_arg(string()) -> boolean().
|
||||||
-is_boolean_arg(Arg) ->
|
-is_boolean_arg(Arg) ->
|
||||||
- LowerArg = string:to_lower(Arg),
|
- LowerArg = string:to_lower(Arg),
|
||||||
|
@ -379,51 +474,76 @@ index bb7fae2..0000000
|
||||||
-
|
-
|
||||||
-
|
-
|
||||||
--spec is_integer_arg(string()) -> boolean().
|
--spec is_integer_arg(string()) -> boolean().
|
||||||
-is_integer_arg([Head | Tail]) when Head >= $0, Head =< $9 ->
|
-is_integer_arg("-" ++ Tail) ->
|
||||||
- is_integer_arg(Tail);
|
- is_non_neg_integer_arg(Tail);
|
||||||
-is_integer_arg([_Head | _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;
|
- false;
|
||||||
-is_integer_arg([]) ->
|
-is_non_neg_integer_arg([]) ->
|
||||||
- true.
|
- true.
|
||||||
-
|
-
|
||||||
-
|
-
|
||||||
--spec is_float_arg(string()) -> boolean().
|
--spec is_non_neg_float_arg(string()) -> boolean().
|
||||||
-is_float_arg([Head | Tail]) when (Head >= $0 andalso Head =< $9) orelse Head =:= $. ->
|
-is_non_neg_float_arg([Head | Tail]) when (Head >= $0 andalso Head =< $9) orelse Head =:= $. ->
|
||||||
- is_float_arg(Tail);
|
- is_non_neg_float_arg(Tail);
|
||||||
-is_float_arg([_Head | _Tail]) ->
|
-is_non_neg_float_arg([_Head | _Tail]) ->
|
||||||
- false;
|
- false;
|
||||||
-is_float_arg([]) ->
|
-is_non_neg_float_arg([]) ->
|
||||||
- true.
|
- 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.
|
-%% arguments that are supported by the program.
|
||||||
--spec usage([option_spec()], string()) -> ok.
|
--spec usage([option_spec()], string()) -> ok.
|
||||||
-usage(OptSpecList, ProgramName) ->
|
-usage(OptSpecList, ProgramName) ->
|
||||||
- io:format("Usage: ~s~s~n~n~s~n",
|
- usage(OptSpecList, ProgramName, standard_error).
|
||||||
- [ProgramName, usage_cmd_line(OptSpecList), usage_options(OptSpecList)]).
|
|
||||||
-
|
-
|
||||||
-
|
-
|
||||||
-%% @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
|
-%% arguments that are supported by the program. The CmdLineTail argument
|
||||||
-%% is a string that is added to the end of the usage command line.
|
-%% 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) ->
|
-usage(OptSpecList, ProgramName, CmdLineTail) ->
|
||||||
- io:format("Usage: ~s~s ~s~n~n~s~n",
|
- usage(OptSpecList, ProgramName, CmdLineTail, standard_error).
|
||||||
- [ProgramName, usage_cmd_line(OptSpecList), CmdLineTail, usage_options(OptSpecList)]).
|
|
||||||
-
|
-
|
||||||
-
|
-
|
||||||
-%% @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 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
|
-%% 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.
|
-%% 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) ->
|
||||||
|
- 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(
|
- UsageOptions = lists:foldl(
|
||||||
- fun ({Prefix, Help}, Acc) ->
|
- fun ({Prefix, Help}, Acc) ->
|
||||||
- add_option_help(Prefix, Help, Acc)
|
- add_option_help(Prefix, Help, Acc)
|
||||||
- end, usage_options_reverse(OptSpecList, []), OptionsTail),
|
- 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,
|
- [ProgramName, usage_cmd_line(OptSpecList), CmdLineTail,
|
||||||
- lists:flatten(lists:reverse(UsageOptions))]).
|
- lists:flatten(lists:reverse(UsageOptions))]).
|
||||||
-
|
-
|
||||||
|
@ -439,10 +559,10 @@ index bb7fae2..0000000
|
||||||
- case ArgSpec of
|
- case ArgSpec of
|
||||||
- undefined ->
|
- undefined ->
|
||||||
- if
|
- if
|
||||||
- % For options with short form and no argument.
|
- %% For options with short form and no argument.
|
||||||
- Short =/= undefined ->
|
- Short =/= undefined ->
|
||||||
- [$\s, $[, $-, Short, $]];
|
- [$\s, $[, $-, Short, $]];
|
||||||
- % For options with only long form and no argument.
|
- %% For options with only long form and no argument.
|
||||||
- Long =/= undefined ->
|
- Long =/= undefined ->
|
||||||
- [$\s, $[, $-, $-, Long, $]];
|
- [$\s, $[, $-, $-, Long, $]];
|
||||||
- true ->
|
- true ->
|
||||||
|
@ -450,13 +570,13 @@ index bb7fae2..0000000
|
||||||
- end;
|
- end;
|
||||||
- _ ->
|
- _ ->
|
||||||
- if
|
- if
|
||||||
- % For options with short form and argument.
|
- %% For options with short form and argument.
|
||||||
- Short =/= undefined ->
|
- Short =/= undefined ->
|
||||||
- [$\s, $[, $-, Short, $\s, $<, atom_to_list(Name), $>, $]];
|
- [$\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 ->
|
- Long =/= undefined ->
|
||||||
- [$\s, $[, $-, $-, Long, $\s, $<, atom_to_list(Name), $>, $]];
|
- [$\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 ->
|
- true ->
|
||||||
- [$\s, $<, atom_to_list(Name), $>]
|
- [$\s, $<, atom_to_list(Name), $>]
|
||||||
- end
|
- end
|
||||||
|
@ -473,23 +593,23 @@ index bb7fae2..0000000
|
||||||
- lists:flatten(lists:reverse(usage_options_reverse(OptSpecList, []))).
|
- lists:flatten(lists:reverse(usage_options_reverse(OptSpecList, []))).
|
||||||
-
|
-
|
||||||
-usage_options_reverse([{Name, Short, Long, _ArgSpec, Help} | Tail], Acc) ->
|
-usage_options_reverse([{Name, Short, Long, _ArgSpec, Help} | Tail], Acc) ->
|
||||||
- Prefix =
|
- Prefix =
|
||||||
- case Long of
|
- case Long of
|
||||||
- undefined ->
|
- undefined ->
|
||||||
- case Short of
|
- case Short of
|
||||||
- % Neither short nor long form (non-option argument).
|
- %% Neither short nor long form (non-option argument).
|
||||||
- undefined ->
|
- undefined ->
|
||||||
- [$<, atom_to_list(Name), $>];
|
- [$<, atom_to_list(Name), $>];
|
||||||
- % Only short form.
|
- %% Only short form.
|
||||||
- _ ->
|
- _ ->
|
||||||
- [$-, Short]
|
- [$-, Short]
|
||||||
- end;
|
- end;
|
||||||
- _ ->
|
- _ ->
|
||||||
- case Short of
|
- case Short of
|
||||||
- % Only long form.
|
- %% Only long form.
|
||||||
- undefined ->
|
- undefined ->
|
||||||
- [$-, $- | Long];
|
- [$-, $- | Long];
|
||||||
- % Both short and long form.
|
- %% Both short and long form.
|
||||||
- _ ->
|
- _ ->
|
||||||
- [$-, Short, $,, $\s, $-, $- | Long]
|
- [$-, Short, $,, $\s, $-, $- | Long]
|
||||||
- end
|
- end
|
||||||
|
@ -532,5 +652,5 @@ index bb7fae2..0000000
|
||||||
- T
|
- T
|
||||||
- end.
|
- end.
|
||||||
--
|
--
|
||||||
1.7.2.3
|
1.7.10.1
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue