Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Changed

- Quote some values in error messages (#24)

## 0.8.4

### Changed
Expand Down
6 changes: 3 additions & 3 deletions src/climate/error.ml
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,20 @@ module Parse_error = struct
| None -> sprintf "Failed to parse the argument: %s" message)
| Too_many_positional_arguments { max = 0; first_excess_argument } ->
sprintf
"This command does not accept any positional arguments. First excess argument: %s"
"This command does not accept any positional arguments. First excess argument: %S"
first_excess_argument
| Too_many_positional_arguments { max; first_excess_argument } ->
sprintf
"Too many positional arguments. At most %d positional arguments may be passed. \
First excess argument: %s"
First excess argument: %S"
max
first_excess_argument
| Invalid_char_in_argument_name { attempted_argument_name; invalid_char } ->
sprintf
"Invalid character %C in argument name %S"
invalid_char
attempted_argument_name
| No_such_subcommand subcommand -> sprintf "No such subcommand: %s" subcommand
| No_such_subcommand subcommand -> sprintf "No such subcommand: %S" subcommand
;;

let exit_code = 124
Expand Down
12 changes: 9 additions & 3 deletions tests/unit_tests/parse_error_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@ let%expect_test "no args to empty parser" =
let%expect_test "positional args passed to command with no positional args" =
run (Command.singleton (Arg_parser.const ())) [ "foo"; "bar"; "baz" ];
[%expect
{| This command does not accept any positional arguments. First excess argument: foo |}]
{| This command does not accept any positional arguments. First excess argument: "foo" |}]
;;

let%expect_test "empty string passed to command with no positional args" =
run (Command.singleton (Arg_parser.const ())) [ "" ];
[%expect
{| This command does not accept any positional arguments. First excess argument: "" |}]
;;

let%expect_test "positional args passed to command with no positional args" =
let term = Arg_parser.(pos_req 0 string) in
run (Command.singleton term) [ "foo"; "bar"; "baz" ];
[%expect
{| Too many positional arguments. At most 1 positional arguments may be passed. First excess argument: bar |}]
{| Too many positional arguments. At most 1 positional arguments may be passed. First excess argument: "bar" |}]
;;

let%expect_test "unknown argument name" =
Expand Down Expand Up @@ -119,5 +125,5 @@ let%expect_test "no such subcommand" =
group [ subcommand "foo" (group [ subcommand "bar" (singleton term) ]) ]
in
run command [ "foo"; "baz" ];
[%expect {| No such subcommand: baz |}]
[%expect {| No such subcommand: "baz" |}]
;;
Loading