Add status code to spec and use it on every exit
This commit is contained in:
parent
fa68fd70e3
commit
95277a6b65
3 changed files with 12 additions and 4 deletions
|
|
@ -2,5 +2,6 @@ let () =
|
|||
match Array.to_list Sys.argv with
|
||||
| _ :: tail ->
|
||||
let future = (Tori.Parsers.Argument.interpret Tori.Schema.seed tail) in
|
||||
if future.output.message <> "" then print_endline future.output.message
|
||||
if future.output.message <> "" then print_endline future.output.message;
|
||||
exit future.meta.status
|
||||
| [] -> assert false
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ let interpret (past: Schema.schema) (input: string list): Schema.schema =
|
|||
|
||||
let future = { past with output = { message = "" } } in
|
||||
|
||||
(* say is useful when the only change to future is the output message *)
|
||||
let say (message: string) =
|
||||
{ future with output = { message = message } } in
|
||||
|
||||
|
|
@ -19,5 +18,12 @@ let interpret (past: Schema.schema) (input: string list): Schema.schema =
|
|||
say (Schema.format_version future.meta.version)
|
||||
| ("help" | "-h" | "--help") :: _ -> say future.meta.help.long
|
||||
| head :: _ ->
|
||||
say ("Unrecognized command: " ^ head ^ "\n" ^ future.meta.help.short)
|
||||
{ future with
|
||||
output = {
|
||||
message =
|
||||
("Unrecognized command: " ^ head ^ "\n"
|
||||
^ future.meta.help.short)
|
||||
};
|
||||
meta = { future.meta with status = 1 };
|
||||
}
|
||||
| _ -> future
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ open Qol
|
|||
|
||||
type version = { major: int; minor: int; patch: int }
|
||||
type help = { short: string; long: string }
|
||||
type meta = { version: version; help: help }
|
||||
type meta = { version: version; help: help; status: int }
|
||||
|
||||
type output = { message: string; }
|
||||
|
||||
|
|
@ -22,6 +22,7 @@ let seed: schema = {
|
|||
short = "<short help>";
|
||||
long = "<long help>";
|
||||
};
|
||||
status = 0;
|
||||
};
|
||||
output = {
|
||||
message = "";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue