From e73f48bd71836454fefbb06600229b6650dcc81d Mon Sep 17 00:00:00 2001 From: David Ellis Date: Wed, 9 Oct 2024 21:42:49 -0500 Subject: [PATCH] describeH3Error --- src/apps/filters/h3.c | 17 +++++++++++++++++ tests/cli/describeH3Error.txt | 4 ++++ 2 files changed, 21 insertions(+) create mode 100644 tests/cli/describeH3Error.txt diff --git a/src/apps/filters/h3.c b/src/apps/filters/h3.c index 52390b620..9e42288c5 100644 --- a/src/apps/filters/h3.c +++ b/src/apps/filters/h3.c @@ -2386,6 +2386,22 @@ SUBCOMMAND(greatCircleDistanceM, return E_SUCCESS; } +SUBCOMMAND(describeH3Error, + "Returns a description of the provided H3 error code number, or " + "indicates the number is itself invalid.") { + H3Error err = E_SUCCESS; + Arg errArg = {.names = {"-e", "--error"}, + .required = true, + .scanFormat = "%d", + .valueName = "CODE", + .value = &err, + .helpText = "H3 Error code to describe"}; + Arg *args[] = {&describeH3ErrorArg, &errArg, &helpArg}; + PARSE_SUBCOMMAND(argc, argv, args); + printf("%s\n", H3_EXPORT(describeH3Error)(err)); + return E_SUCCESS; +} + // TODO: Is there any way to avoid this particular piece of duplication? SUBCOMMANDS_INDEX @@ -2464,6 +2480,7 @@ SUBCOMMAND_INDEX(pentagonCount) SUBCOMMAND_INDEX(greatCircleDistanceRads) SUBCOMMAND_INDEX(greatCircleDistanceKm) SUBCOMMAND_INDEX(greatCircleDistanceM) +SUBCOMMAND_INDEX(describeH3Error) END_SUBCOMMANDS_INDEX diff --git a/tests/cli/describeH3Error.txt b/tests/cli/describeH3Error.txt new file mode 100644 index 000000000..fcc55b990 --- /dev/null +++ b/tests/cli/describeH3Error.txt @@ -0,0 +1,4 @@ +add_h3_cli_test(testCliDescribeH3Error0 "describeH3Error -e 0" "Success") +add_h3_cli_test(testCliDescribeH3Error10 "describeH3Error -e 10" "Duplicate input") +add_h3_cli_test(testCliDescribeH3Error13 "describeH3Error -e 13" "Memory allocation failed") +add_h3_cli_test(testCliDescribeH3Error100 "describeH3Error -e 100" "Invalid error code")