Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:23
erlang
7093-argparse-Make-formatting-of-argument-descr...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 7093-argparse-Make-formatting-of-argument-descriptions-le.patch of Package erlang
From cda7aef414abfcf43d025b1bd0c00a88c0890ac2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20H=C3=B6gberg?= <john@erlang.org> Date: Tue, 11 Jul 2023 10:09:14 +0200 Subject: [PATCH] argparse: Make formatting of argument descriptions less ambiguous --- lib/stdlib/src/argparse.erl | 12 ++++++++---- lib/stdlib/test/argparse_SUITE.erl | 8 ++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/stdlib/src/argparse.erl b/lib/stdlib/src/argparse.erl index a5fdd8d3d9..69b734a126 100644 --- a/lib/stdlib/src/argparse.erl +++ b/lib/stdlib/src/argparse.erl @@ -1252,17 +1252,21 @@ format_description(#{help := {_Short, Desc}} = Opt) -> String end, Desc ); -%% default format: "desc", "desc (type)", "desc (default)", "desc (type, default)" +%% default format: +%% "desc" +%% "desc (type)" +%% "desc, default: abc" +%% "desc (type), default: abc" format_description(#{name := Name} = Opt) -> NameStr = maps:get(help, Opt, io_lib:format("~ts", [Name])), case {NameStr, format_type(Opt), format_default(Opt)} of {"", "", Type} -> Type; {"", Default, ""} -> Default; {Desc, "", ""} -> Desc; - {Desc, "", Default} -> [Desc, " (", Default, ")"]; + {Desc, "", Default} -> [Desc, " , default: ", Default]; {Desc, Type, ""} -> [Desc, " (", Type, ")"]; - {"", Type, Default} -> [Type, ", ", Default]; - {Desc, Type, Default} -> [Desc, " (", Type, ", ", Default, ")"] + {"", Type, Default} -> [Type, ", default: ", Default]; + {Desc, Type, Default} -> [Desc, " (", Type, "), default: ", Default] end. %% option formatting helpers diff --git a/lib/stdlib/test/argparse_SUITE.erl b/lib/stdlib/test/argparse_SUITE.erl index fb7eaecda1..a63b8867d2 100644 --- a/lib/stdlib/test/argparse_SUITE.erl +++ b/lib/stdlib/test/argparse_SUITE.erl @@ -399,7 +399,7 @@ unicode(Config) when is_list(Config) -> Prog = [prog()], ?assertEqual({ok, Expected, Prog, Cmd}, argparse:parse([], Cmd)), %% default ?assertEqual({ok, Expected, Prog, Cmd}, argparse:parse(["★"], Cmd)), %% specified in the command line - ?assertEqual("Usage:\n " ++ prog() ++ " <text>\n\nArguments:\n text åäö (binary, ★)\n", + ?assertEqual("Usage:\n " ++ prog() ++ " <text>\n\nArguments:\n text åäö (binary), default: ★\n", unicode:characters_to_list(argparse:help(Cmd))), %% test command name and argument name in unicode Uni = #{commands => #{"åäö" => #{help => "öФ"}}, handler => optional, @@ -775,7 +775,7 @@ usage(Config) when is_list(Config) -> " -v verbosity level\n" " -i interval set (int >= 1)\n" " --req required optional, right?\n" - " --float floating-point long form argument (float, 3.14)\n", + " --float floating-point long form argument (float), default: 3.14\n", ?assertEqual(Usage, unicode:characters_to_list(argparse:help(Cmd, #{progname => "erl", command => ["start"]}))), FullCmd = "Usage:\n erl" @@ -790,7 +790,7 @@ usage(Config) when is_list(Config) -> " -v verbosity level\n" " -i interval set (int >= 1)\n" " --req required optional, right?\n" - " --float floating-point long form argument (float, 3.14)\n", + " --float floating-point long form argument (float), default: 3.14\n", ?assertEqual(FullCmd, unicode:characters_to_list(argparse:help(Cmd, #{progname => erl}))), CrawlerStatus = "Usage:\n erl status crawler [-rfv] [---extra <extra>] [--force] [-i <interval>]\n" @@ -799,7 +799,7 @@ usage(Config) when is_list(Config) -> " -f, --force force\n -v verbosity level\n" " -i interval set (int >= 1)\n" " --req required optional, right?\n" - " --float floating-point long form argument (float, 3.14)\n", + " --float floating-point long form argument (float), default: 3.14\n", ?assertEqual(CrawlerStatus, unicode:characters_to_list(argparse:help(Cmd, #{progname => "erl", command => ["status", "crawler"]}))), ok. -- 2.35.3
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