Skip to content

Commit 18c0e51

Browse files
committed
fix(src/main/*): Complete exit codes description in man for each command/subcommand
1 parent 6c6ac12 commit 18c0e51

File tree

3 files changed

+101
-13
lines changed

3 files changed

+101
-13
lines changed

src/main/learnocaml_client.ml

Lines changed: 76 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -729,9 +729,17 @@ module Init = struct
729729
let man = man "Initialize the configuration file with the server, and \
730730
a token or a nickname+secret pair"
731731

732+
let exits =
733+
let open Cmd.Exit in
734+
[ info ~doc:"Default exit." ok
735+
; info ~doc:"Input error: unable to find a server URL or connection token." 1
736+
; info ~doc:"The client's version is incompatible (too old?) w.r.t. the server." 70
737+
]
738+
732739
let info =
733740
Cmd.info
734741
~man
742+
~exits
735743
~sdocs:Manpage.s_options
736744
~doc:"Initialize the configuration file."
737745
"init"
@@ -819,9 +827,19 @@ module Grade = struct
819827
"Grades an OCaml exercise using a learn-ocaml server, and submits \
820828
solutions."
821829

830+
let exits =
831+
let open Cmd.Exit in
832+
[ info ~doc:"Default exit." ok
833+
; info ~doc:"Server-side error: either unable to reach the server or request has been failed." 1
834+
; info ~doc:"Input error: unable to find a file to grade or token isn't valid." 2
835+
; info ~doc:"Grading failed." 10
836+
; info ~doc:"The client's version is incompatible (too old?) w.r.t. the server." 70
837+
]
838+
822839
let info =
823840
Cmd.info
824841
~man
842+
~exits
825843
~sdocs:Manpage.s_options
826844
~doc:"Learn-ocaml grading client."
827845
"grade"
@@ -850,7 +868,14 @@ module Print_token = struct
850868

851869
let man = man explanation
852870

853-
let info = Cmd.info ~man ~doc:explanation ~sdocs:Manpage.s_options "print-token"
871+
let exits =
872+
let open Cmd.Exit in
873+
[ info ~doc:"Default exit." ok
874+
; info ~doc:"Server error: could not reach the server or config file wasn't found." 1
875+
; info ~doc:"The client's version is incompatible (too old?) w.r.t. the server." 70
876+
]
877+
878+
let info = Cmd.info ~man ~exits ~doc:explanation ~sdocs:Manpage.s_options "print-token"
854879

855880
let term = use_global print_tok
856881
end
@@ -865,8 +890,15 @@ module Print_server = struct
865890
let explanation = "Just print the configured server."
866891

867892
let man = man explanation
868-
869-
let info = Cmd.info ~man ~doc:explanation ~sdocs:Manpage.s_options "print-server"
893+
894+
let exits =
895+
let open Cmd.Exit in
896+
[ info ~doc:"Default exit." ok
897+
; info ~doc:"Server error: could not reach the server or config file wasn't found." 1
898+
; info ~doc:"The client's version is incompatible (too old?) w.r.t. the server." 70
899+
]
900+
901+
let info = Cmd.info ~man ~exits ~doc:explanation ~sdocs:Manpage.s_options "print-server"
870902

871903
let term = use_global print_server
872904

@@ -948,7 +980,7 @@ module Server_version = struct
948980
let open Cmd.Exit in
949981
[ info ~doc:"Default exit." ok
950982
; info ~doc:"Unable to reach the server." 1
951-
; info ~doc:"Input error: unable to find a server URL." 2
983+
; info ~doc:"Input error: unable to find a server URL or config file." 2
952984
; info ~doc:"The client's version is incompatible (too old?) w.r.t. the server." 70
953985
]
954986

@@ -971,9 +1003,17 @@ module Set_options = struct
9711003
"Overwrite the configuration file with the command-line options \
9721004
($(b,--server), $(b,--token))."
9731005

1006+
let exits =
1007+
let open Cmd.Exit in
1008+
[ info ~doc:"Default exit." ok
1009+
; info ~doc:"Server error: config file wasn't found." 1
1010+
; info ~doc:"The client's version is incompatible (too old?) w.r.t. the server." 70
1011+
]
1012+
9741013
let info =
9751014
Cmd.info
9761015
~man
1016+
~exits
9771017
~sdocs:Manpage.s_options
9781018
~doc:"Set configuration."
9791019
"set-options"
@@ -1050,9 +1090,11 @@ module Fetch = struct
10501090
let exits =
10511091
let open Cmd.Exit in
10521092
[ info ~doc:"Default exit." ok
1053-
; info ~doc:"There was a file already present on the local side." 1
1093+
; info ~doc:"Either sever-side error or there was a file already present on the local side." 1
10541094
; info ~doc:"A specified exercise was not found on the server." 2
1055-
; info ~doc:"Both of 1 and 2." 3 ]
1095+
; info ~doc:"Both of 1 (for local side) and 2." 3
1096+
; info ~doc:"The client's version is incompatible (too old?) w.r.t. the server." 70
1097+
]
10561098

10571099
let info =
10581100
Cmd.info
@@ -1091,9 +1133,18 @@ module Create_token = struct
10911133
let man = man "Create a token on the server with the desired nickname.\
10921134
Prodiving a token will test if it exists on the server."
10931135

1136+
let exits =
1137+
let open Cmd.Exit in
1138+
[ info ~doc:"Default exit." ok
1139+
; info ~doc:"Server error: either unable to reach the server or request has been failed." 1
1140+
; info ~doc:"Input error: nickname wasn't provided." 2
1141+
; info ~doc:"The client's version is incompatible (too old?) w.r.t. the server." 70
1142+
]
1143+
10941144
let info =
10951145
Cmd.info
10961146
~man
1147+
~exits
10971148
~sdocs:Manpage.s_options
10981149
~doc:"Create a token."
10991150
"create-token"
@@ -1125,9 +1176,19 @@ module Template = struct
11251176

11261177
let man = man "Get the template of a given exercise"
11271178

1179+
let exits =
1180+
let open Cmd.Exit in
1181+
[ info ~doc:"Default exit." ok
1182+
; info ~doc:"Sever error: unable to find config file or request has been failed." 1
1183+
; info ~doc:"Input error: exercise id wasn't provided." 2
1184+
; info ~doc:"Exercise with given id already exists." 3
1185+
; info ~doc:"The client's version is incompatible (too old?) w.r.t. the server." 70
1186+
]
1187+
11281188
let info =
11291189
Cmd.info
11301190
~man
1191+
~exits
11311192
~sdocs:Manpage.s_options
11321193
~doc:"Get the template of a given exercise."
11331194
"template"
@@ -1161,7 +1222,14 @@ module Exercise_list = struct
11611222

11621223
let man = man doc
11631224

1164-
let info = Cmd.info ~man ~doc:doc ~sdocs:Manpage.s_options "exercise-list"
1225+
let exits =
1226+
let open Cmd.Exit in
1227+
[ info ~doc:"Default exit." ok
1228+
; info ~doc:"Sever error: unable to find config file or request has been failed." 1
1229+
; info ~doc:"The client's version is incompatible (too old?) w.r.t. the server." 70
1230+
]
1231+
1232+
let info = Cmd.info ~man ~exits ~doc:doc ~sdocs:Manpage.s_options "exercise-list"
11651233

11661234
let term = use_global exercise_list
11671235
end
@@ -1194,6 +1262,7 @@ module Main = struct
11941262
Cmd.info
11951263
~version
11961264
~man
1265+
~exits:Grade.exits
11971266
~sdocs:s_options
11981267
~doc:"Learn-ocaml client CLI."
11991268
"learn-ocaml-client"

src/main/learnocaml_main.ml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* included LICENSE file for details. *)
88

99
open Lwt.Infix
10+
open Cmdliner
1011

1112
module StringSet = Set.Make(String)
1213

@@ -24,7 +25,6 @@ let readlink f =
2425
with Sys_error _ -> Sys.chdir (Filename.get_temp_dir_name ()); f
2526

2627
module Args = struct
27-
open Cmdliner
2828
open Arg
2929

3030
type command = Grade | Build | Serve
@@ -428,7 +428,7 @@ let main o =
428428
exit ret
429429

430430
let man =
431-
let open Cmdliner.Manpage in
431+
let open Manpage in
432432
[
433433
`S s_description;
434434
`P "This program performs various tasks related to generating, serving and \
@@ -460,17 +460,25 @@ let man =
460460
$(i,https://github.com/ocaml-sf/learn-ocaml/issues)";
461461
]
462462

463+
let exits =
464+
let open Cmd.Exit in
465+
[ info ~doc:"Default exit." ok
466+
; info ~doc:"Client-side failure whose cause is printed on stderr. Caused by $(b,grade) or $(b,build) commands." 1
467+
; info ~doc:"Uncaught exception." 2
468+
; info ~doc:"Server error whose cause is printed on stderr. Caused by $(b,serve) command." 10
469+
]
470+
463471
let main_info =
464-
Cmdliner.Cmd.info
465-
~man
472+
Cmd.info
473+
~man
474+
~exits
466475
~doc:"Learn-ocaml web-app manager"
467476
~version:Learnocaml_api.version
468477
"learn-ocaml"
469478

470-
let main_term = Cmdliner.Term.(const main $ Args.term)
479+
let main_term = Term.(const main $ Args.term)
471480

472481
let () =
473-
let open Cmdliner in
474482
match
475483
Cmd.eval_value ~catch:false (Cmd.v main_info main_term)
476484
with

src/main/learnocaml_server_main.ml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,21 @@ let base_url =
8787
Mandatory for '$(b,learn-ocaml build)' if the site is not hosted in path '/', \
8888
which typically occurs for static deployment."
8989

90+
let exits =
91+
let open Cmd.Exit in
92+
[ info ~doc:"Default exit." ok
93+
; info ~doc:"Uncaught exception." 2
94+
; info ~doc:"Server error whose cause is printed on stderr." 10
95+
; info ~doc:"Aborting. Server internal error occured in less then 15 seconds after the launch." 20
96+
; info ~doc:"Termination signal (SIGTERM) recieved by server." 113
97+
; info ~doc:"Interruption signal (SIGINT) recieved by server." 126
98+
]
99+
90100
let main_info =
91101
Cmd.info
92102
~man
93103
~doc:"Learn-ocaml native server"
104+
~exits
94105
~sdocs:Manpage.s_options
95106
~version:Learnocaml_api.version
96107
"learn-ocaml"

0 commit comments

Comments
 (0)