Skip to content

Commit 84b8ada

Browse files
committed
deps(opam): Upgrade cmdliner dependency to 1.1.0 version
The new version of cmdliner has added support for UTF-8 encoded characters within man pages. At the same time, a new module has been added, whose functionalities will replace deprecated `Term.eval*` evaluation functions and `Term.info`. To see more : https://github.com/dbuenzli/cmdliner/blob/master/CHANGES.md.
1 parent d833f6e commit 84b8ada

File tree

8 files changed

+117
-87
lines changed

8 files changed

+117
-87
lines changed

learn-ocaml-client.opam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ depends: [
2020
"asak"
2121
"base64"
2222
"base" {>= "v0.9.4"}
23-
"cmdliner"
23+
"cmdliner" {>= "1.1.0"}
2424
"cohttp" {>= "2.0.0"}
2525
"cohttp-lwt-unix" {>= "2.0.0"}
2626
"cstruct" {>= "3.3.0"}

learn-ocaml-client.opam.locked

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ depends: [
3232
"bigarray-compat" {= "1.0.0"}
3333
"bigstringaf" {= "0.8.0"}
3434
"biniou" {= "1.2.1"}
35-
"cmdliner" {= "1.0.4"}
35+
"cmdliner" {= "1.1.0"}
3636
"cohttp" {= "4.0.0"}
3737
"cohttp-lwt" {= "4.0.0"}
3838
"cohttp-lwt-unix" {= "4.0.0"}

learn-ocaml.opam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ depends: [
2020
"asak"
2121
"base64"
2222
"base" {>= "v0.9.4"}
23-
"cmdliner"
23+
"cmdliner" {>= "1.1.0"}
2424
"cohttp" {>= "2.0.0"}
2525
"cohttp-lwt" {>= "2.0.0"}
2626
"cohttp-lwt-unix" {>= "2.0.0"}

learn-ocaml.opam.locked

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ depends: [
3030
"bigstringaf" {= "0.8.0"}
3131
"biniou" {= "1.2.1"}
3232
"checkseum" {= "0.3.1"}
33-
"cmdliner" {= "1.0.4"}
33+
"cmdliner" {= "1.1.0"}
3434
"cohttp" {= "4.0.0"}
3535
"cohttp-lwt" {= "4.0.0"}
3636
"cohttp-lwt-unix" {= "4.0.0"}

src/main/learnocaml_client.ml

Lines changed: 95 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ module Args_server = struct
4343
value & opt (some url_conv) None &
4444
info ["s";"server"] ~docv:"URL" ~doc:
4545
"The URL of the learn-ocaml server."
46-
~env:(Term.env_info "LEARNOCAML_SERVER" ~doc:
46+
~env:(Cmd.Env.info "LEARNOCAML_SERVER" ~doc:
4747
"Sets the learn-ocaml server URL. Overridden by $(b,--server).")
4848
let local =
4949
value & flag & info ["local"] ~doc:
@@ -71,14 +71,14 @@ module Args_global = struct
7171
value & opt (some url_conv) None &
7272
info ["s";"server"] ~docv:"URL" ~doc:
7373
"The URL of the learn-ocaml server."
74-
~env:(Term.env_info "LEARNOCAML_SERVER" ~doc:
74+
~env:(Cmd.Env.info "LEARNOCAML_SERVER" ~doc:
7575
"Sets the learn-ocaml server URL. Overridden by $(b,--server).")
7676

7777
let token =
7878
value & opt (some token_conv) None & info ["token";"t"] ~docv:"TOKEN" ~doc:
7979
"Your token on the learn-ocaml server. This is required when submitting \
8080
solutions or interacting with the server."
81-
~env:(Term.env_info "LEARNOCAML_TOKEN" ~doc:
81+
~env:(Cmd.Env.info "LEARNOCAML_TOKEN" ~doc:
8282
"Sets the learn-ocaml user token on the sever. Overridden by \
8383
$(b,--token).")
8484

@@ -163,7 +163,7 @@ module Args_exercises = struct
163163
let when_enum = ["always", Some true; "never", Some false; "auto", None] in
164164
value & opt (enum when_enum) None & info ["color"] ~docv:"WHEN" ~doc:
165165
("Colorise the output, and also allows use of UTF-8 characters. $(docv) \
166-
must be "^doc_alts_enum when_enum ^".")
166+
must be "^doc_alts_enum ~quoted:true when_enum ^".")
167167

168168
let verbose =
169169
value & flag_all & info ["v";"verbose"] ~doc:
@@ -727,13 +727,16 @@ module Init = struct
727727
let man = man "Initialize the configuration file with the server, and \
728728
a token or a nickname+secret pair"
729729

730-
let cmd =
731-
Term.(
732-
const (fun go co -> Stdlib.exit (Lwt_main.run (init go co)))
733-
$ Args_global.term $ Args_create_token.term),
734-
Term.info ~man
730+
let info =
731+
Cmd.info
732+
~man
735733
~doc:"Initialize the configuration file."
736734
"init"
735+
736+
let term =
737+
Term.(
738+
const (fun go co -> Stdlib.exit (Lwt_main.run (init go co)))
739+
$ Args_global.term $ Args_create_token.term)
737740
end
738741

739742
module Grade = struct
@@ -813,13 +816,16 @@ module Grade = struct
813816
"Grades an OCaml exercise using a learn-ocaml server, and submits \
814817
solutions."
815818

816-
let cmd =
819+
let info =
820+
Cmd.info
821+
~man
822+
~doc:"Learn-ocaml grading client."
823+
"grade"
824+
825+
let term =
817826
Term.(
818827
const (fun go eo -> Stdlib.exit (Lwt_main.run (grade go eo)))
819-
$ Args_global.term $ Args_exercises.term),
820-
Term.info ~man
821-
~doc:"Learn-ocaml grading client."
822-
"grade"
828+
$ Args_global.term $ Args_exercises.term)
823829
end
824830

825831
let use_global f =
@@ -840,9 +846,9 @@ module Print_token = struct
840846

841847
let man = man explanation
842848

843-
let cmd =
844-
use_global print_tok,
845-
Term.info ~man ~doc:explanation "print-token"
849+
let info = Cmd.info ~man ~doc:explanation "print-token"
850+
851+
let term = use_global print_tok
846852
end
847853

848854
module Print_server = struct
@@ -856,9 +862,9 @@ module Print_server = struct
856862

857863
let man = man explanation
858864

859-
let cmd =
860-
use_global print_server,
861-
Term.info ~man ~doc:explanation "print-server"
865+
let info = Cmd.info ~man ~doc:explanation "print-server"
866+
867+
let term = use_global print_server
862868

863869
end
864870

@@ -935,19 +941,20 @@ module Server_version = struct
935941
let man = man explanation
936942

937943
let exits =
938-
let open Term in
939-
[ exit_info ~doc:"Default exit." exit_status_success
940-
; exit_info ~doc:"Unable to reach the server." 1
941-
; exit_info ~doc:"Input error: unable to find a server URL." 2
942-
; exit_info ~doc:"The client's version is incompatible (too old?) w.r.t. the server." 70
944+
let open Cmd.Exit in
945+
[ info ~doc:"Default exit." ok
946+
; info ~doc:"Unable to reach the server." 1
947+
; info ~doc:"Input error: unable to find a server URL." 2
948+
; info ~doc:"The client's version is incompatible (too old?) w.r.t. the server." 70
943949
]
944950

951+
let info = Cmd.info ~man ~exits ~doc:explanation "server-version"
952+
945953
(* TODO: Generalize & Use [use_global] *)
946-
let cmd =
954+
let term =
947955
Term.(
948956
const (fun o l -> Stdlib.exit (Lwt_main.run (server_version o l)))
949-
$ Args_server.term $ Args_server_version.term),
950-
Term.info ~man ~exits ~doc:explanation "server-version"
957+
$ Args_server.term $ Args_server_version.term)
951958
end
952959

953960
module Set_options = struct
@@ -960,11 +967,13 @@ module Set_options = struct
960967
"Overwrite the configuration file with the command-line options \
961968
($(b,--server), $(b,--token))."
962969

963-
let cmd =
964-
use_global set_opts,
965-
Term.info ~man
970+
let info =
971+
Cmd.info
972+
~man
966973
~doc:"Set configuration."
967974
"set-options"
975+
976+
let term = use_global set_opts
968977
end
969978

970979
let write_exercise_file id str =
@@ -1034,19 +1043,23 @@ module Fetch = struct
10341043
"Fetch the user's solutions on the server to the current directory."
10351044

10361045
let exits =
1037-
let open Term in
1038-
[ exit_info ~doc:"Default exit." exit_status_success
1039-
; exit_info ~doc:"There was a file already present on the local side." 1
1040-
; exit_info ~doc:"A specified exercise was not found on the server." 2
1041-
; exit_info ~doc:"Both of 1 and 2." 3 ]
1046+
let open Cmd.Exit in
1047+
[ info ~doc:"Default exit." ok
1048+
; info ~doc:"There was a file already present on the local side." 1
1049+
; info ~doc:"A specified exercise was not found on the server." 2
1050+
; info ~doc:"Both of 1 and 2." 3 ]
1051+
1052+
let info =
1053+
Cmd.info
1054+
~man
1055+
~exits
1056+
~doc:"Fetch the user's solutions."
1057+
"fetch"
10421058

1043-
let cmd =
1059+
let term =
10441060
Term.(
10451061
const (fun o l -> Stdlib.exit (Lwt_main.run (fetch o l)))
1046-
$ Args_global.term $ Args_fetch.term),
1047-
Term.info ~man ~exits
1048-
~doc:"Fetch the user's solutions."
1049-
"fetch"
1062+
$ Args_global.term $ Args_fetch.term)
10501063
end
10511064

10521065
module Create_token = struct
@@ -1072,13 +1085,16 @@ module Create_token = struct
10721085
let man = man "Create a token on the server with the desired nickname.\
10731086
Prodiving a token will test if it exists on the server."
10741087

1075-
let cmd =
1076-
Term.(
1077-
const (fun go co -> Stdlib.exit (Lwt_main.run (create_tok go co)))
1078-
$ Args_global.term_server $ Args_create_token.term),
1079-
Term.info ~man
1088+
let info =
1089+
Cmd.info
1090+
~man
10801091
~doc:"Create a token."
10811092
"create-token"
1093+
1094+
let term =
1095+
Term.(
1096+
const (fun go co -> Stdlib.exit (Lwt_main.run (create_tok go co)))
1097+
$ Args_global.term_server $ Args_create_token.term)
10821098
end
10831099

10841100
module Template = struct
@@ -1102,13 +1118,16 @@ module Template = struct
11021118

11031119
let man = man "Get the template of a given exercise"
11041120

1105-
let cmd =
1106-
Term.(
1107-
const (fun o id -> Stdlib.exit (Lwt_main.run (template o id)))
1108-
$ Args_global.term $ Args_exercise_id.term),
1109-
Term.info ~man
1121+
let info =
1122+
Cmd.info
1123+
~man
11101124
~doc:"Get the template of a given exercise."
11111125
"template"
1126+
1127+
let term =
1128+
Term.(
1129+
const (fun o id -> Stdlib.exit (Lwt_main.run (template o id)))
1130+
$ Args_global.term $ Args_exercise_id.term)
11121131
end
11131132

11141133
module Exercise_list = struct
@@ -1133,38 +1152,44 @@ module Exercise_list = struct
11331152
Lwt.return 0;)
11341153

11351154
let man = man doc
1136-
1137-
let cmd =
1138-
use_global exercise_list,
1139-
Term.info ~man ~doc:doc "exercise-list"
1155+
1156+
let info = Cmd.info ~man ~doc:doc "exercise-list"
1157+
1158+
let term = use_global exercise_list
11401159
end
11411160

11421161
module Main = struct
11431162
let man =
11441163
man
11451164
"Learn-ocaml-client, default command is grade."
11461165

1147-
let cmd = fst Grade.cmd,
1148-
Term.info ~version ~man
1166+
let info =
1167+
Cmd.info
1168+
~version
1169+
~man
11491170
~doc:"Learn-ocaml grading client."
11501171
"learn-ocaml-client"
1172+
1173+
let term = Grade.term
1174+
11511175
end
11521176

11531177
let () =
1154-
match Term.eval_choice ~catch:false Main.cmd
1155-
[ Init.cmd
1156-
; Grade.cmd
1157-
; Print_token.cmd
1158-
; Set_options.cmd
1159-
; Fetch.cmd
1160-
; Print_server.cmd
1161-
; Server_version.cmd
1162-
; Template.cmd
1163-
; Create_token.cmd
1164-
; Exercise_list.cmd]
1165-
with
1178+
let open Cmd in
1179+
let cmd = group ~default:Main.term Main.info
1180+
[ v Init.info Init.term
1181+
; v Grade.info Grade.term
1182+
; v Print_token.info Print_token.term
1183+
; v Set_options.info Set_options.term
1184+
; v Fetch.info Fetch.term
1185+
; v Print_server.info Print_server.term
1186+
; v Server_version.info Server_version.term
1187+
; v Template.info Template.term
1188+
; v Create_token.info Create_token.term
1189+
; v Exercise_list.info Exercise_list.term ] in
1190+
match Cmd.eval_value ~catch:false cmd with
11661191
| exception Failure msg ->
11671192
Printf.eprintf "[ERROR] %s\n" msg;
11681193
exit 1
1169-
| `Error _ -> exit 2
1194+
| Error _ -> exit 2
11701195
| _ -> exit 0

src/main/learnocaml_main.ml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -453,20 +453,22 @@ let man = [
453453
$(i,https://github.com/ocaml-sf/learn-ocaml/issues)";
454454
]
455455

456-
let main_cmd =
457-
Cmdliner.Term.(const main $ Args.term),
458-
Cmdliner.Term.info
459-
~man
456+
let main_info =
457+
Cmdliner.Cmd.info
458+
~man
460459
~doc:"Learn-ocaml web-app manager"
461-
~version:Learnocaml_api.version
460+
~version:Learnocaml_api.version
462461
"learn-ocaml"
463462

463+
let main_term = Cmdliner.Term.(const main $ Args.term)
464+
464465
let () =
466+
let open Cmdliner in
465467
match
466-
Cmdliner.Term.eval ~catch:false main_cmd
468+
Cmd.eval_value ~catch:false (Cmd.v main_info main_term)
467469
with
468470
| exception Failure msg ->
469471
Printf.eprintf "[ERROR] %s\n" msg;
470472
exit 1
471-
| `Error _ -> exit 2
473+
| Error _ -> exit 2
472474
| _ -> exit 0

src/main/learnocaml_server_main.ml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,20 +80,23 @@ let base_url =
8080
Mandatory for '$(b,learn-ocaml build)' if the site is not hosted in path '/', \
8181
which typically occurs for static deployment."
8282

83-
let main_cmd =
84-
Cmdliner.Term.(const main $ Learnocaml_server_args.term app_dir base_url),
85-
Cmdliner.Term.info
83+
let main_info =
84+
Cmdliner.Cmd.info
8685
~man
8786
~doc:"Learn-ocaml web-app manager"
8887
~version:Learnocaml_api.version
8988
"learn-ocaml"
9089

90+
91+
let main_term = Cmdliner.Term.(const main $ Learnocaml_server_args.term app_dir base_url)
92+
9193
let () =
94+
let open Cmdliner in
9295
match
93-
Cmdliner.Term.eval ~catch:false main_cmd
96+
Cmd.eval_value ~catch:false (Cmd.v main_info main_term)
9497
with
9598
| exception Failure msg ->
9699
Printf.eprintf "[ERROR] %s\n" msg;
97100
exit 1
98-
| `Error _ -> exit 2
101+
| Error _ -> exit 2
99102
| _ -> exit 0

src/repo/learnocaml_exercise.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ module File = struct
238238
| Some id, None | None, Some id -> return id
239239
| Some id, Some id' ->
240240
if id = id' then return id else
241-
fail (Failure "Exercise.read: conficting ids")
241+
fail (Failure "Exercise.read: conflicting ids")
242242
end >>= fun ex_id ->
243243
ex := set id ex_id !ex ;
244244
(* read_field meta.key >>=

0 commit comments

Comments
 (0)