Projects
openEuler:Mainline
erlang-getopt
Sign Up
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
Expand all
Collapse all
Changes of Revision 5
View file
_service:tar_scm:erlang-getopt.spec
Changed
@@ -2,8 +2,8 @@ %global upstream jcomellas %global debug_package %{nil} Name: erlang-%{realname} -Version: 1.0.1 -Release: 1 +Version: 1.0.2 +Release: 2 Summary: Erlang module to parse command line arguments using the GNU getopt syntax License: BSD URL: https://github.com/%{upstream}/%{realname} @@ -32,5 +32,11 @@ %{erlang_appdir}/ %changelog +* Tue Jun 20 2023 wangkai <13474090681@163.com> - 1.0.2-2 +- Enable test + +* Tue Jun 20 2023 wangkai <13474090681@163.com> - 1.0.2-1 +- Update to 1.0.2 + * Mon Aug 31 2020 wangyue <wangyue92@huawei.com> - 1.0.1-1 - package init
View file
_service:tar_scm:getopt-1.0.2.tar.gz/.gitignore
Added
@@ -0,0 +1,1 @@ +/_build
View file
_service:tar_scm:getopt-1.0.2.tar.gz/.travis.yml
Added
@@ -0,0 +1,11 @@ +language: erlang + +otp_release: + - R13B04 + - R14B04 + - R15B03 + - R16B03 + - 17.5 + - 18.3 + - 19.3 + - 20.0
View file
_service:tar_scm:getopt-1.0.1.tar.gz/LICENSE.txt -> _service:tar_scm:getopt-1.0.2.tar.gz/LICENSE.txt
Changed
@@ -1,19 +1,18 @@ -Copyright (c) 2009 Juan Jose Comellas -All rights reserved. +Copyright 2009 Juan Jose Comellas -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: - - Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. +1. Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. +2. Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation +and/or other materials provided with the distribution. - - Neither the name of Juan Jose Comellas nor the names of its contributors may - be used to endorse or promote products derived from this software without - specific prior written permission. +3. Neither the name of the copyright holder nor the names of its contributors +may be used to endorse or promote products derived from this software without +specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
View file
_service:tar_scm:getopt-1.0.1.tar.gz/README.md -> _service:tar_scm:getopt-1.0.2.tar.gz/README.md
Changed
@@ -24,10 +24,10 @@ To use getopt in your project you can just add it as a dependency in your `rebar.config` file in the following way: -```sh +```erlang {deps, - {getopt, "1.0.1"} + {getopt, "1.0.2"} } ``` @@ -57,7 +57,7 @@ specifications. The type specification for the tuple is: ```erlang --type arg_type() :: 'atom' | 'binary' | 'boolean' | 'float' | 'integer' | 'string'. +-type arg_type() :: 'atom' | 'binary' | 'utf8_binary' | 'boolean' | 'float' | 'integer' | 'string'. -type arg_value() :: atom() | binary() | boolean() | float() | integer() | string(). @@ -244,7 +244,8 @@ Argument Types -------------- -The arguments allowed for options are: *atom*; *binary*; *boolean*; *float*; *integer*; *string*. +The arguments allowed for options are: *atom*; *binary*; *utf8_binary*; *boolean*; +*float*; *integer*; *string*. The `getopt` module checks every argument to see if it can be converted to its correct type. @@ -256,6 +257,17 @@ e.g. `--increment=-100` is a valid expression; whereas `--increment -100` is invalid +Arguments of `utf8_binary` type allow proper binary encoding of arguments containing +code points greater than 255. The resulting value is a normalized UTF-8 binary. + +As of Erlang/20, `standard_error` device has `unicode` option set to `false`. +It prevents correct printing of usage for arguments containing unicode +binaries/strings as default values. To fix this, one needs to enable unicode: + +```erlang +io:setopts(standard_error, {unicode, true}). +``` + Implicit Arguments ------------------
View file
_service:tar_scm:getopt-1.0.1.tar.gz/src/getopt.app.src -> _service:tar_scm:getopt-1.0.2.tar.gz/src/getopt.app.src
Changed
@@ -1,10 +1,9 @@ -%% -*- mode: Erlang; fill-column: 75; comment-column: 50; -*- -{application, getopt, - {description, "Command-line options parser for Erlang"}, - {vsn, "1.0.1"}, - {modules, }, - {registered, }, - {maintainers, "Juan Jose Comellas"}, - {licenses, "BSD"}, - {links, {"GitHub", "https://github.com/jcomellas/getopt"}}, - {applications, kernel, stdlib}}. +{application,getopt, + {description,"Command-line options parser for Erlang"}, + {vsn,"1.0.2"}, + {modules,}, + {registered,}, + {maintainers,"Juan Jose Comellas"}, + {licenses,"BSD"}, + {links,{"GitHub","https://github.com/jcomellas/getopt"}}, + {applications,kernel,stdlib}}.
View file
_service:tar_scm:getopt-1.0.1.tar.gz/src/getopt.erl -> _service:tar_scm:getopt-1.0.2.tar.gz/src/getopt.erl
Changed
@@ -13,7 +13,7 @@ -export(parse/2, check/2, parse_and_check/2, format_error/2, usage/2, usage/3, usage/4, usage/6, tokenize/1). --export(usage_cmd_line/2). +-export(usage_cmd_line/2, usage_options/1). -define(LINE_LENGTH, 75). -define(MIN_USAGE_COMMAND_LINE_OPTION_LENGTH, 25). @@ -30,7 +30,7 @@ (Char) =:= $\n orelse (Char) =:= $\r)). %% Atom indicating the data type that an argument can be converted to. --type arg_type() :: 'atom' | 'binary' | 'boolean' | 'float' | 'integer' | 'string'. +-type arg_type() :: 'atom' | 'binary' | 'utf8_binary' | 'boolean' | 'float' | 'integer' | 'string'. %% Data type that an argument can be converted to. -type arg_value() :: atom() | binary() | boolean() | float() | integer() | string(). %% Argument specification. @@ -149,12 +149,7 @@ format_error(OptSpecList, {error, Reason}) -> format_error(OptSpecList, Reason); format_error(OptSpecList, {missing_required_option, Name}) -> - OptStr = case lists:keyfind(Name, 1, OptSpecList) of - {Name, undefined, undefined, _Type, _Help} -> "<", to_string(Name), ">"; - {_Name, undefined, Long, _Type, _Help} -> "--", Long; - {_Name, Short, undefined, _Type, _Help} -> "-", Short; - {_Name, Short, Long, _Type, _Help} -> "-", Short, " (", Long, ")" - end, + OptStr = opt_to_list(lists:keyfind(Name, 1, OptSpecList)), lists:flatten("missing required option: ", OptStr); format_error(_OptSpecList, {invalid_option, OptStr}) -> lists:flatten("invalid option: ", to_string(OptStr)); @@ -162,9 +157,21 @@ lists:flatten("option \'", to_string(Name) ++ "\' has invalid argument: ", to_string(Arg)); format_error(_OptSpecList, {invalid_option_arg, OptStr}) -> lists:flatten("invalid option argument: ", to_string(OptStr)); +format_error(OptSpecList, {missing_option_arg, Name}) -> + OptStr = opt_to_list(lists:keyfind(Name, 1, OptSpecList)), + lists:flatten("missing option argument: ", OptStr, " <", to_string(Name), $>); format_error(_OptSpecList, {Reason, Data}) -> lists:flatten(to_string(Reason), " ", to_string(Data)). +opt_to_list({Name, undefined, undefined, _Type, _Help}) -> + $<, to_string(Name), $>; +opt_to_list({_Name, undefined, Long, _Type, _Help}) -> + $-, $-, Long; +opt_to_list({_Name, Short, undefined, _Type, _Help}) -> + $-, Short; +opt_to_list({_Name, Short, Long, _Type, _Help}) -> + $-, Short, $\s, $(, Long, $). + %% @doc Parse a long option, add it to the option accumulator and continue %% parsing the rest of the arguments recursively. @@ -435,6 +442,8 @@ to_type(Type, Arg); to_type(binary, Arg) -> list_to_binary(Arg); +to_type(utf8_binary, Arg) -> + unicode:characters_to_binary(Arg); to_type(atom, Arg) -> list_to_atom(Arg); to_type(integer, Arg) -> @@ -730,8 +739,8 @@ -spec usage_help_text(option_spec()) -> string(). -usage_help_text({_Name, _Short, _Long, {_ArgType, ArgValue}, _ | _ = Help}) -> - Help ++ " default: " ++ default_arg_value_to_string(ArgValue) ++ ""; +usage_help_text({_Name, _Short, _Long, {ArgType, ArgValue}, _ | _ = Help}) -> + Help ++ " default: " ++ default_arg_value_to_string(ArgType, ArgValue) ++ ""; usage_help_text({_Name, _Short, _Long, _ArgSpec, Help}) -> Help. @@ -804,15 +813,17 @@ lists:reverse(Acc). -default_arg_value_to_string(Value) when is_atom(Value) -> +default_arg_value_to_string(_, Value) when is_atom(Value) -> atom_to_list(Value); -default_arg_value_to_string(Value) when is_binary(Value) -> +default_arg_value_to_string(binary, Value) when is_binary(Value) -> binary_to_list(Value); -default_arg_value_to_string(Value) when is_integer(Value) -> +default_arg_value_to_string(utf8_binary, Value) when is_binary(Value) -> + unicode:characters_to_list(Value); +default_arg_value_to_string(_, Value) when is_integer(Value) -> integer_to_list(Value); -default_arg_value_to_string(Value) when is_float(Value) -> +default_arg_value_to_string(_, Value) when is_float(Value) -> lists:flatten(io_lib:format("~w", Value)); -default_arg_value_to_string(Value) -> +default_arg_value_to_string(_, Value) -> Value.
View file
_service:tar_scm:getopt-1.0.1.tar.gz/test/getopt_test.erl -> _service:tar_scm:getopt-1.0.2.tar.gz/test/getopt_test.erl
Changed
@@ -298,6 +298,19 @@ ?_assertEqual({error, {missing_required_option, arg}}, check(OptSpecList, Opts))}, {"Parse arguments and check required options", ?_assertEqual({error, {missing_required_option, arg}}, parse_and_check(OptSpecList, ""))}, + {"Parse arguments and check required option args", + ?_assertEqual({error, {missing_option_arg, arg}}, + parse_and_check(OptSpecList, "-a"))}. + +format_error_test_() -> + OptSpecList = + + { arg, $a, "arg", string, "Required arg"}, + { short, $s, undefined, string, "short option"}, + { long, undefined, "long", string, "long option"}, + { other, undefined, undefined, string, "task"} + , + {"Format missing option error test 1", ?_assertEqual("missing required option: -a (arg)", format_error(OptSpecList, {error, {missing_required_option, arg}}))}, @@ -321,5 +334,34 @@ format_error(OptSpecList, {error, {invalid_option_arg, "arg_value"}}))}, {"Format invalid option argument error test 2", ?_assertEqual("option 'verbose' has invalid argument: 100", - format_error(OptSpecList, {error, {invalid_option_arg, {verbose, "100"}}}))} + format_error(OptSpecList, {error, {invalid_option_arg, {verbose, "100"}}}))}, + {"Format missing option argument error test 1", + ?_assertEqual("missing option argument: -a (arg) <arg>", + format_error(OptSpecList, {error, {missing_option_arg, arg}}))}, + {"Format missing option argument error test 2", + ?_assertEqual("missing option argument: -a (arg) <arg>", + format_error(OptSpecList, {missing_option_arg, arg}))}, + {"Format missing option argument error test 3", + ?_assertEqual("missing option argument: -s <short>", + format_error(OptSpecList, {missing_option_arg, short}))}, + {"Format missing option argument error test 4", + ?_assertEqual("missing option argument: --long <long>", + format_error(OptSpecList, {missing_option_arg, long}))}, + {"Format missing option argument error test 5", + ?_assertError(_, format_error(OptSpecList, {missing_option_arg, unknown}))} . + +utf8_binary_test_() -> + OptSpecList = {utf8, undefined, "utf8", utf8_binary, "UTF-8 arg"}, + Unicode = 228, 220, 223, 1455, + Utf8 = unicode:characters_to_binary(Unicode), + io:setopts(standard_error, {encoding, utf8}), + OptSpecsWithDefault = {utf8, undefined, "utf8", {utf8_binary, Utf8}, "UTF-8 arg"}, + {"Empty utf8_binary argument", + ?_assertEqual({ok, {{utf8, <<>>}, }}, parse(OptSpecList, "--utf8", ""))}, + {"Non empty utf8_binary argument", + ?_assertEqual({ok, {{utf8, Utf8}, }}, parse(OptSpecList, "--utf8", Unicode))}, + {"Default utf8_binary argument", + ?_assertEqual({ok, {{utf8, Utf8}, }}, parse(OptSpecsWithDefault, ))}, + {"Default utf8_binary argument usage", + ?_assert(is_list(string:find(getopt:usage_options(OptSpecsWithDefault), Unicode)))}.
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.
浙ICP备2022010568号-2