Implement most of the spec reusing scribe & nefthera code
This commit is contained in:
parent
e8b489dd6f
commit
612a98cfde
16 changed files with 225 additions and 25 deletions
23
ocaml/lib/parsers/argument.ml
Normal file
23
ocaml/lib/parsers/argument.ml
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
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
|
||||
|
||||
(*
|
||||
TODO: return a schema with orders, instead of calling side-effects
|
||||
directly, making this more of a parser and less of a glorified switch
|
||||
*)
|
||||
match input with
|
||||
| "pkg" :: tail -> System.Package.merge past tail
|
||||
| "os" :: _ -> say (System.File.read "/etc/os-release")
|
||||
| "host" :: _ -> say (System.Process.Reader.read [||] "hostname").output
|
||||
| "echo" :: tail -> say (String.concat " " tail)
|
||||
| ("version" | "-v" | "--version") :: _ ->
|
||||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue