@@ -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)
737740end
738741
739742module 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)
823829end
824830
825831let 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
846852end
847853
848854module 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
863869end
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)
951958end
952959
953960module 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
968977end
969978
970979let 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)
10501063end
10511064
10521065module 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)
10821098end
10831099
10841100module 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)
11121131end
11131132
11141133module 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
11401159end
11411160
11421161module 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+
11511175end
11521176
11531177let () =
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
0 commit comments