File 0125-parse-and-run-accept-either-string-OR-unicode-charda.patch of Package erlang
From 693b9cf731b43fc262d06aed04a9c6187f25a2d7 Mon Sep 17 00:00:00 2001
From: Julian Doherty <julian@juliandoherty.com>
Date: Sat, 12 Oct 2024 16:30:31 +1100
Subject: [PATCH 3/3] parse and run accept either string() OR
unicode:chardata()
---
lib/stdlib/src/argparse.erl | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/lib/stdlib/src/argparse.erl b/lib/stdlib/src/argparse.erl
index 293850d657..59343a9634 100644
--- a/lib/stdlib/src/argparse.erl
+++ b/lib/stdlib/src/argparse.erl
@@ -498,6 +498,11 @@ corresponding key is not present in the resulting map.
-type arg_map() :: #{argument_name() => term()}.
%% Arguments map: argument name to a term, produced by parser. Supplied to the command handler
+-doc """
+List of command line arguments to be parsed.
+""".
+-type args() :: [string() | unicode:chardata()].
+
-doc """
Command handler specification. Called by [`run/3` ](`run/3`)upon successful
parser return.
@@ -599,7 +604,7 @@ elements are nested command names.
%% Command path, for nested commands
-export_type([arg_type/0, argument_help/0, argument/0,
- command/0, handler/0, cmd_path/0, arg_map/0]).
+ command/0, handler/0, cmd_path/0, arg_map/0, args/0]).
-doc """
Returned from [`parse/2,3`](`parse/3`) when the user input cannot be parsed
@@ -703,7 +708,7 @@ validate(Command, Options) ->
%% @equiv parse(Args, Command, #{})
-doc(#{equiv => parse/3}).
-doc(#{since => <<"OTP 26.0">>}).
--spec parse(Args :: [string()], command()) -> parse_result().
+-spec parse(args(), command()) -> parse_result().
parse(Args, Command) ->
parse(Args, Command, #{}).
@@ -722,7 +727,7 @@ makes `parse/2,3` to return a tuple
This function does not call command handler.
""".
-doc(#{since => <<"OTP 26.0">>}).
--spec parse(Args :: [string()], command(), Options :: parser_options()) -> parse_result().
+-spec parse(args(), command(), Options :: parser_options()) -> parse_result().
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)
@@ -773,7 +778,7 @@ specification or user-provided command line input.
> may result in an unexpected shutdown of a remote node.
""".
-doc(#{since => <<"OTP 26.0">>}).
--spec run(Args :: [string()], command(), parser_options()) -> term().
+-spec run(args(), command(), parser_options()) -> term().
run(Args, Command, Options) ->
try parse(Args, Command, Options) of
{ok, ArgMap, Path, SubCmd} ->
--
2.43.0