///|
pub(all) struct CommandResult {
exit_code : Int
output : String
} derive(Eq, Debug)
///|
/// Portable dispatcher. Arguments exclude the executable name; never performs file or network IO.
pub fn command(args : Array[String]) -> CommandResult {
try {
let output = match args {
["--help"] | [] =>
"MoonRestrict 0.1.0\nUsage: digest REQUEST_JSON | verify REQUEST_JSON REPORT_JSON | demo | --help\nCoordinates: zero-based top-strand boundaries. Synthetic models only."
["demo"] =>
run_json(
"{\"version\":1,\"sequence\":\"GTAC\",\"topology\":\"circular\",\"enzymes\":[{\"name\":\"synthetic\",\"motif\":\"ACGT\",\"top\":1,\"bottom\":3}]}",
)
["digest", request] => run_json(request)
["verify", request, report] => {
read_request(request).verify(read_report(report))
"{\"ok\":true,\"verified\":true}"
}
_ => raise InvalidInput("CLI_USAGE")
}
{ exit_code: 0, output }
} catch {
error => {
let message = match error {
InvalidInput(message) => "InvalidInput: " + message
LimitExceeded(message) => "LimitExceeded: " + message
CutConflict(message) => "CutConflict: " + message
}
let payload : Json = { "ok": false, "error": message }
{ exit_code: 2, output: payload.stringify() }
}
}
}