Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:24
erlang
6139-handle-args-passed-as-binaries.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 6139-handle-args-passed-as-binaries.patch of Package erlang
From 202695bc1a5b139e6b11a3374e1b955eb55d0988 Mon Sep 17 00:00:00 2001 From: Julian Doherty <julian@juliandoherty.com> Date: Sat, 12 Oct 2024 16:30:10 +1100 Subject: [PATCH 2/3] handle args passed as binaries --- lib/stdlib/src/argparse.erl | 3 ++- lib/stdlib/test/argparse_SUITE.erl | 25 +++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/lib/stdlib/src/argparse.erl b/lib/stdlib/src/argparse.erl index 93fbaa3b49..293850d657 100644 --- a/lib/stdlib/src/argparse.erl +++ b/lib/stdlib/src/argparse.erl @@ -727,8 +727,9 @@ parse(Args, Command, Options) -> Prog = validate(Command, Options), %% use maps and not sets v2, because sets:is_element/2 cannot be used in guards (unlike is_map_key) Prefixes = maps:from_list([{P, true} || P <- maps:get(prefixes, Options, [$-])]), + Args2 = [unicode:characters_to_list(Arg) || Arg <- Args], try - parse_impl(Args, merge_arguments(Prog, Command, init_parser(Prefixes, Command, Options))) + parse_impl(Args2, merge_arguments(Prog, Command, init_parser(Prefixes, Command, Options))) catch %% Parser error may happen at any depth, and bubbling the error is really %% cumbersome. Use exceptions and catch it before returning from `parse/2,3' instead. diff --git a/lib/stdlib/test/argparse_SUITE.erl b/lib/stdlib/test/argparse_SUITE.erl index 01f39ef540..db7e265eb4 100644 --- a/lib/stdlib/test/argparse_SUITE.erl +++ b/lib/stdlib/test/argparse_SUITE.erl @@ -23,6 +23,7 @@ -export([ readme/0, readme/1, basic/0, basic/1, + binary_args/0, binary_args/1, long_form_eq/0, long_form_eq/1, built_in_types/0, built_in_types/1, type_validators/0, type_validators/1, @@ -55,6 +56,7 @@ validator_exception_format/0, validator_exception_format/1, run_handle/0, run_handle/1, + run_handle_binary_args/0, run_handle_binary_args/1, run_args_ordering/0, run_args_ordering/1 ]). @@ -66,7 +68,7 @@ suite() -> groups() -> [ {parser, [parallel], [ - readme, basic, long_form_eq, built_in_types, type_validators, + readme, basic, binary_args, long_form_eq, built_in_types, type_validators, invalid_arguments, complex_command, unicode, parser_error, nargs, argparse, negative, nodigits, pos_mixed_with_opt, default_for_not_required, global_default, subcommand, @@ -80,7 +82,7 @@ groups() -> validator_exception, validator_exception_format ]}, {run, [parallel], [ - run_handle, run_args_ordering + run_handle, run_handle_binary_args, run_args_ordering ]} ]. @@ -228,6 +230,15 @@ basic(Config) when is_list(Config) -> ?assertEqual({ok, #{arg => [true, false]}, [Prog], ArgListCmd}, parse(["true false"], ArgListCmd)). +binary_args() -> + [{doc, "Args are provided as binarys"}]. + +binary_args(Config) when is_list(Config) -> + %% no command, just argument list + KernelCmd = #{arguments => [#{name => kernel, long => "kernel", type => atom, nargs => 2}]}, + ?assertEqual({ok, #{kernel => [port, dist]}, [prog()], KernelCmd}, + argparse:parse([<<"-kernel">>, <<"port">>, <<"dist">>], KernelCmd)). + long_form_eq() -> [{doc, "Tests that long form supports --arg=value"}]. @@ -1128,6 +1139,16 @@ run_handle(Config) when is_list(Config) -> arguments => [#{name => arg}]}}}, #{})). +run_handle_binary_args() -> + [{doc, "Verify that argparse:run/3, accepts binary args"}]. + +run_handle_binary_args(Config) when is_list(Config) -> + %% no subcommand, positional module-based function + ?assertEqual(6, + argparse:run([<<"2">>, <<"3">>], #{handler => {erlang, '*', undefined}, + arguments => [#{name => l, type => integer}, #{name => r, type => integer}]}, + #{})). + run_args_ordering() -> [{doc, "Test that positional arguments are parsed in the correct order"}]. -- 2.43.0
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor