Skip to content

Commit 62e69ed

Browse files
Merge pull request #2680 from emillon/cmdliner2-compat
Cmdliner 2.0.0 compat
2 parents 9c8ccd9 + efb3f32 commit 62e69ed

27 files changed

+63
-59
lines changed

CHANGES.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ profile. This started with version 0.26.0.
66

77
## unreleased
88

9+
### Deprecated
10+
11+
- Starting in this release, ocamlformat can use cmdliner >= 2.0.0. When that is
12+
the case, the tool no longer accepts unambiguous option names prefixes. For
13+
example, `--max-iter` is not accepted anymore, you have to pass the full
14+
option `--max-iters`. This does not apply to the keys in the `.ocamlformat`
15+
configuration files, which have always required the full name.
16+
See dbuenzli/cmdliner#200.
17+
(#2680, @emillon)
18+
919
### Fixed
1020

1121
- Fixed `wrap-comments=true` not working with the janestreet profile (#2645, @Julow)

lib/Conf_decl.ml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,6 @@
1111

1212
module Error = Conf_t.Error
1313

14-
let ocaml_version_conv =
15-
let parse x =
16-
match Ocaml_version.of_string x with
17-
| Ok x -> `Ok x
18-
| Error (`Msg x) -> `Error x
19-
in
20-
(parse, Ocaml_version.pp)
21-
2214
type typ = Int | Bool | Ocaml_version | Choice of string list
2315

2416
module UI = struct
@@ -31,6 +23,8 @@ end
3123

3224
open Cmdliner
3325

26+
let ocaml_version_conv = Arg.conv (Ocaml_version.of_string, Ocaml_version.pp)
27+
3428
type kind = Formatting | Operational
3529
(* type from = [ `Default | `Profile of string * updated_from | `Updated of
3630
updated_from * from option (* when redundant definition *) ] *)

lib/bin_conf/Bin_conf.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,17 +166,17 @@ let check =
166166
let inputs =
167167
let docv = "SRC" in
168168
let file_or_dash =
169-
let parse, print = Arg.non_dir_file in
169+
let parse = Arg.conv_parser Arg.non_dir_file in
170+
let print = Arg.conv_printer Arg.non_dir_file in
170171
let print fmt = function
171172
| Stdin -> print fmt "<standard input>"
172173
| File x -> print fmt x
173174
in
174175
let parse = function
175-
| "-" -> `Ok Stdin
176-
| s -> (
177-
match parse s with `Ok x -> `Ok (File x) | `Error x -> `Error x )
176+
| "-" -> Ok Stdin
177+
| s -> parse s |> Result.map ~f:(fun x -> File x)
178178
in
179-
(parse, print)
179+
Arg.conv (parse, print)
180180
in
181181
let doc =
182182
"Input files. At least one is required, and exactly one without \

test/passing/gen/dune.inc

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@
443443
(action
444444
(with-stdout-to break_cases-toplevel.ml.stdout
445445
(with-stderr-to break_cases-toplevel.ml.stderr
446-
(run %{bin:ocamlformat} --name break_cases-toplevel.ml --margin-check --break-cases=toplevel --max-iter=4 %{dep:../tests/break_cases.ml})))))
446+
(run %{bin:ocamlformat} --name break_cases-toplevel.ml --margin-check --break-cases=toplevel --max-iters=4 %{dep:../tests/break_cases.ml})))))
447447

448448
(rule
449449
(alias runtest)
@@ -482,7 +482,7 @@
482482
(action
483483
(with-stdout-to break_cases.ml.stdout
484484
(with-stderr-to break_cases.ml.stderr
485-
(run %{bin:ocamlformat} --name break_cases.ml --margin-check --break-cases=fit --max-iter=4 %{dep:../tests/break_cases.ml})))))
485+
(run %{bin:ocamlformat} --name break_cases.ml --margin-check --break-cases=fit --max-iters=4 %{dep:../tests/break_cases.ml})))))
486486

487487
(rule
488488
(alias runtest)
@@ -716,7 +716,7 @@
716716
(action
717717
(with-stdout-to break_separators-after.ml.stdout
718718
(with-stderr-to break_separators-after.ml.stderr
719-
(run %{bin:ocamlformat} --name break_separators-after.ml --margin-check --break-separators=after --max-iter=3 %{dep:../tests/break_separators.ml})))))
719+
(run %{bin:ocamlformat} --name break_separators-after.ml --margin-check --break-separators=after --max-iters=3 %{dep:../tests/break_separators.ml})))))
720720

721721
(rule
722722
(alias runtest)
@@ -734,7 +734,7 @@
734734
(action
735735
(with-stdout-to break_separators-after_docked.ml.stdout
736736
(with-stderr-to break_separators-after_docked.ml.stderr
737-
(run %{bin:ocamlformat} --name break_separators-after_docked.ml --margin-check --break-separators=after --dock-collection-brackets --max-iter=3 %{dep:../tests/break_separators.ml})))))
737+
(run %{bin:ocamlformat} --name break_separators-after_docked.ml --margin-check --break-separators=after --dock-collection-brackets --max-iters=3 %{dep:../tests/break_separators.ml})))))
738738

739739
(rule
740740
(alias runtest)
@@ -752,7 +752,7 @@
752752
(action
753753
(with-stdout-to break_separators-before_docked.ml.stdout
754754
(with-stderr-to break_separators-before_docked.ml.stderr
755-
(run %{bin:ocamlformat} --name break_separators-before_docked.ml --margin-check --break-separators=before --dock-collection-brackets --max-iter=3 %{dep:../tests/break_separators.ml})))))
755+
(run %{bin:ocamlformat} --name break_separators-before_docked.ml --margin-check --break-separators=before --dock-collection-brackets --max-iters=3 %{dep:../tests/break_separators.ml})))))
756756

757757
(rule
758758
(alias runtest)
@@ -770,7 +770,7 @@
770770
(action
771771
(with-stdout-to break_separators.ml.stdout
772772
(with-stderr-to break_separators.ml.stderr
773-
(run %{bin:ocamlformat} --name break_separators.ml --margin-check --break-separators=before --max-iter=3 %{dep:../tests/break_separators.ml})))))
773+
(run %{bin:ocamlformat} --name break_separators.ml --margin-check --break-separators=before --max-iters=3 %{dep:../tests/break_separators.ml})))))
774774

775775
(rule
776776
(alias runtest)
@@ -1136,7 +1136,7 @@
11361136
(action
11371137
(with-stdout-to comments-no-wrap.ml.stdout
11381138
(with-stderr-to comments-no-wrap.ml.stderr
1139-
(run %{bin:ocamlformat} --name comments-no-wrap.ml --margin-check --no-wrap-comments --max-iter=4 %{dep:../tests/comments.ml})))))
1139+
(run %{bin:ocamlformat} --name comments-no-wrap.ml --margin-check --no-wrap-comments --max-iters=4 %{dep:../tests/comments.ml})))))
11401140

11411141
(rule
11421142
(alias runtest)
@@ -1154,7 +1154,7 @@
11541154
(action
11551155
(with-stdout-to comments.ml.stdout
11561156
(with-stderr-to comments.ml.stderr
1157-
(run %{bin:ocamlformat} --name comments.ml --margin-check --max-iter=4 %{dep:../tests/comments.ml})))))
1157+
(run %{bin:ocamlformat} --name comments.ml --margin-check --max-iters=4 %{dep:../tests/comments.ml})))))
11581158

11591159
(rule
11601160
(alias runtest)
@@ -1190,7 +1190,7 @@
11901190
(action
11911191
(with-stdout-to comments_args.ml.stdout
11921192
(with-stderr-to comments_args.ml.stderr
1193-
(run %{bin:ocamlformat} --name comments_args.ml --margin-check --max-iter=4 %{dep:../tests/comments_args.ml})))))
1193+
(run %{bin:ocamlformat} --name comments_args.ml --margin-check --max-iters=4 %{dep:../tests/comments_args.ml})))))
11941194

11951195
(rule
11961196
(alias runtest)
@@ -1244,7 +1244,7 @@
12441244
(action
12451245
(with-stdout-to comments_in_record-break_separator-after.ml.stdout
12461246
(with-stderr-to comments_in_record-break_separator-after.ml.stderr
1247-
(run %{bin:ocamlformat} --name comments_in_record-break_separator-after.ml --margin-check --break-separator=after %{dep:../tests/comments_in_record.ml})))))
1247+
(run %{bin:ocamlformat} --name comments_in_record-break_separator-after.ml --margin-check --break-separators=after %{dep:../tests/comments_in_record.ml})))))
12481248

12491249
(rule
12501250
(alias runtest)
@@ -1262,7 +1262,7 @@
12621262
(action
12631263
(with-stdout-to comments_in_record-break_separator-before.ml.stdout
12641264
(with-stderr-to comments_in_record-break_separator-before.ml.stderr
1265-
(run %{bin:ocamlformat} --name comments_in_record-break_separator-before.ml --margin-check --break-separator=before %{dep:../tests/comments_in_record.ml})))))
1265+
(run %{bin:ocamlformat} --name comments_in_record-break_separator-before.ml --margin-check --break-separators=before %{dep:../tests/comments_in_record.ml})))))
12661266

12671267
(rule
12681268
(alias runtest)
@@ -2246,7 +2246,7 @@
22462246
(action
22472247
(with-stdout-to fun_function.ml.stdout
22482248
(with-stderr-to fun_function.ml.stderr
2249-
(run %{bin:ocamlformat} --name fun_function.ml --margin-check --max-iter=3 %{dep:../tests/fun_function.ml})))))
2249+
(run %{bin:ocamlformat} --name fun_function.ml --margin-check --max-iters=3 %{dep:../tests/fun_function.ml})))))
22502250

22512251
(rule
22522252
(alias runtest)
@@ -3167,7 +3167,7 @@
31673167
(action
31683168
(with-stdout-to js_args.ml.stdout
31693169
(with-stderr-to js_args.ml.stderr
3170-
(run %{bin:ocamlformat} --name js_args.ml --margin-check --max-iter=3 %{dep:../tests/js_args.ml})))))
3170+
(run %{bin:ocamlformat} --name js_args.ml --margin-check --max-iters=3 %{dep:../tests/js_args.ml})))))
31713171

31723172
(rule
31733173
(alias runtest)
@@ -3221,7 +3221,7 @@
32213221
(action
32223222
(with-stdout-to js_fun.ml.stdout
32233223
(with-stderr-to js_fun.ml.stderr
3224-
(run %{bin:ocamlformat} --name js_fun.ml --margin-check --max-iter=3 %{dep:../tests/js_fun.ml})))))
3224+
(run %{bin:ocamlformat} --name js_fun.ml --margin-check --max-iters=3 %{dep:../tests/js_fun.ml})))))
32253225

32263226
(rule
32273227
(alias runtest)
@@ -3239,7 +3239,7 @@
32393239
(action
32403240
(with-stdout-to js_map.ml.stdout
32413241
(with-stderr-to js_map.ml.stderr
3242-
(run %{bin:ocamlformat} --name js_map.ml --margin-check --max-iter=3 %{dep:../tests/js_map.ml})))))
3242+
(run %{bin:ocamlformat} --name js_map.ml --margin-check --max-iters=3 %{dep:../tests/js_map.ml})))))
32433243

32443244
(rule
32453245
(alias runtest)
@@ -3275,7 +3275,7 @@
32753275
(action
32763276
(with-stdout-to js_poly.ml.stdout
32773277
(with-stderr-to js_poly.ml.stderr
3278-
(run %{bin:ocamlformat} --name js_poly.ml --margin-check --max-iter=3 %{dep:../tests/js_poly.ml})))))
3278+
(run %{bin:ocamlformat} --name js_poly.ml --margin-check --max-iters=3 %{dep:../tests/js_poly.ml})))))
32793279

32803280
(rule
32813281
(alias runtest)
@@ -3293,7 +3293,7 @@
32933293
(action
32943294
(with-stdout-to js_record.ml.stdout
32953295
(with-stderr-to js_record.ml.stderr
3296-
(run %{bin:ocamlformat} --name js_record.ml --margin-check --max-iter=3 %{dep:../tests/js_record.ml})))))
3296+
(run %{bin:ocamlformat} --name js_record.ml --margin-check --max-iters=3 %{dep:../tests/js_record.ml})))))
32973297

32983298
(rule
32993299
(alias runtest)
@@ -3999,7 +3999,7 @@
39993999
(action
40004000
(with-stdout-to module_item_spacing-preserve.ml.stdout
40014001
(with-stderr-to module_item_spacing-preserve.ml.stderr
4002-
(run %{bin:ocamlformat} --name module_item_spacing-preserve.ml --margin-check --max-iter=3 --module-item-spacing=preserve %{dep:../tests/module_item_spacing.ml})))))
4002+
(run %{bin:ocamlformat} --name module_item_spacing-preserve.ml --margin-check --max-iters=3 --module-item-spacing=preserve %{dep:../tests/module_item_spacing.ml})))))
40034003

40044004
(rule
40054005
(alias runtest)
@@ -4017,7 +4017,7 @@
40174017
(action
40184018
(with-stdout-to module_item_spacing-sparse.ml.stdout
40194019
(with-stderr-to module_item_spacing-sparse.ml.stderr
4020-
(run %{bin:ocamlformat} --name module_item_spacing-sparse.ml --margin-check --max-iter=3 --module-item-spacing=sparse %{dep:../tests/module_item_spacing.ml})))))
4020+
(run %{bin:ocamlformat} --name module_item_spacing-sparse.ml --margin-check --max-iters=3 --module-item-spacing=sparse %{dep:../tests/module_item_spacing.ml})))))
40214021

40224022
(rule
40234023
(alias runtest)
@@ -4035,7 +4035,7 @@
40354035
(action
40364036
(with-stdout-to module_item_spacing.ml.stdout
40374037
(with-stderr-to module_item_spacing.ml.stderr
4038-
(run %{bin:ocamlformat} --name module_item_spacing.ml --margin-check --max-iter=3 --module-item-spacing=compact %{dep:../tests/module_item_spacing.ml})))))
4038+
(run %{bin:ocamlformat} --name module_item_spacing.ml --margin-check --max-iters=3 --module-item-spacing=compact %{dep:../tests/module_item_spacing.ml})))))
40394039

40404040
(rule
40414041
(alias runtest)
@@ -4053,7 +4053,7 @@
40534053
(action
40544054
(with-stdout-to module_item_spacing.mli.stdout
40554055
(with-stderr-to module_item_spacing.mli.stderr
4056-
(run %{bin:ocamlformat} --name module_item_spacing.mli --margin-check --max-iter=3 %{dep:../tests/module_item_spacing.mli})))))
4056+
(run %{bin:ocamlformat} --name module_item_spacing.mli --margin-check --max-iters=3 %{dep:../tests/module_item_spacing.mli})))))
40574057

40584058
(rule
40594059
(alias runtest)
@@ -4829,7 +4829,7 @@
48294829
(action
48304830
(with-stdout-to reformat_string.ml.stdout
48314831
(with-stderr-to reformat_string.ml.stderr
4832-
(run %{bin:ocamlformat} --name reformat_string.ml --margin-check --max-iter=3 %{dep:../tests/reformat_string.ml})))))
4832+
(run %{bin:ocamlformat} --name reformat_string.ml --margin-check --max-iters=3 %{dep:../tests/reformat_string.ml})))))
48334833

48344834
(rule
48354835
(alias runtest)
@@ -4957,7 +4957,7 @@
49574957
(action
49584958
(with-stdout-to sequence-preserve.ml.stdout
49594959
(with-stderr-to sequence-preserve.ml.stderr
4960-
(run %{bin:ocamlformat} --name sequence-preserve.ml --margin-check --sequence-blank-line=preserve-one --max-iter=3 %{dep:../tests/sequence.ml})))))
4960+
(run %{bin:ocamlformat} --name sequence-preserve.ml --margin-check --sequence-blank-line=preserve-one --max-iters=3 %{dep:../tests/sequence.ml})))))
49614961

49624962
(rule
49634963
(alias runtest)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
--break-cases=toplevel
2-
--max-iter=4
2+
--max-iters=4
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
--break-cases=fit
2-
--max-iter=4
2+
--max-iters=4
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
--break-separators=after
2-
--max-iter=3
2+
--max-iters=3
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
--break-separators=after
22
--dock-collection-brackets
3-
--max-iter=3
3+
--max-iters=3
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
--break-separators=before
22
--dock-collection-brackets
3-
--max-iter=3
3+
--max-iters=3
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
--break-separators=before
2-
--max-iter=3
2+
--max-iters=3

0 commit comments

Comments
 (0)