Skip to content

Commit

Permalink
describeH3Error
Browse files Browse the repository at this point in the history
  • Loading branch information
dfellis committed Oct 10, 2024
1 parent f2131c0 commit e73f48b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/apps/filters/h3.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -2464,6 +2480,7 @@ SUBCOMMAND_INDEX(pentagonCount)
SUBCOMMAND_INDEX(greatCircleDistanceRads)
SUBCOMMAND_INDEX(greatCircleDistanceKm)
SUBCOMMAND_INDEX(greatCircleDistanceM)
SUBCOMMAND_INDEX(describeH3Error)

END_SUBCOMMANDS_INDEX

Expand Down
4 changes: 4 additions & 0 deletions tests/cli/describeH3Error.txt
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit e73f48b

Please sign in to comment.