UNPKG

@elliottcable/bs-cmdliner

Version:

Cmdliner — Declarative definition of command line interfaces for OCaml

527 lines (508 loc) 23.5 kB
'use strict'; var List = require("bs-platform/lib/js/list.js"); var Block = require("bs-platform/lib/js/block.js"); var Curry = require("bs-platform/lib/js/curry.js"); var Format = require("bs-platform/lib/js/format.js"); var Printf = require("bs-platform/lib/js/printf.js"); var $$String = require("bs-platform/lib/js/string.js"); var Printexc = require("bs-platform/lib/js/printexc.js"); var Cmdliner_base = require("./cmdliner_base.bs.js"); var Cmdliner_info = require("./cmdliner_info.bs.js"); var Cmdliner_docgen = require("./cmdliner_docgen.bs.js"); var Caml_builtin_exceptions = require("bs-platform/lib/js/caml_builtin_exceptions.js"); function err_env_parse(env, err) { var $$var = Cmdliner_info.env_var(env); return Curry._2(Printf.sprintf(/* Format */[ /* String_literal */Block.__(11, [ "environment variable ", /* String */Block.__(2, [ /* No_padding */0, /* String_literal */Block.__(11, [ ": ", /* String */Block.__(2, [ /* No_padding */0, /* End_of_format */0 ]) ]) ]) ]), "environment variable %s: %s" ]), Cmdliner_base.quote($$var), err); } function err_pos_excess(excess) { return Curry._1(Printf.sprintf(/* Format */[ /* String_literal */Block.__(11, [ "too many arguments, don't know what to do with ", /* String */Block.__(2, [ /* No_padding */0, /* End_of_format */0 ]) ]), "too many arguments, don't know what to do with %s" ]), $$String.concat(", ", List.map(Cmdliner_base.quote, excess))); } function err_pos_miss(a) { var v = Cmdliner_info.arg_docv(a); if (v === "") { return "a required argument is missing"; } else { return Curry._1(Printf.sprintf(/* Format */[ /* String_literal */Block.__(11, [ "required argument ", /* String */Block.__(2, [ /* No_padding */0, /* String_literal */Block.__(11, [ " is missing", /* End_of_format */0 ]) ]) ]), "required argument %s is missing" ]), v); } } function err_pos_misses(args) { if (args) { if (args[1]) { var add_arg = function (acc, a) { var argv = Cmdliner_info.arg_docv(a); if (argv === "") { return /* :: */[ "ARG", acc ]; } else { return /* :: */[ argv, acc ]; } }; var rev_args = List.sort(Cmdliner_info.rev_arg_pos_cli_order, args); var args$1 = List.fold_left(add_arg, /* [] */0, rev_args); var args$2 = $$String.concat(", ", args$1); return Curry._1(Printf.sprintf(/* Format */[ /* String_literal */Block.__(11, [ "required arguments ", /* String */Block.__(2, [ /* No_padding */0, /* String_literal */Block.__(11, [ " are missing", /* End_of_format */0 ]) ]) ]), "required arguments %s are missing" ]), args$2); } else { return err_pos_miss(args[0]); } } else { throw [ Caml_builtin_exceptions.assert_failure, /* tuple */[ "cmdliner_msg.ml", 31, 8 ] ]; } } function err_pos_parse(a, err) { var argv = Cmdliner_info.arg_docv(a); if (argv === "") { return err; } else { var match = Cmdliner_info.pos_len(Cmdliner_info.arg_pos(a)); var exit = 0; if (match !== undefined && match === 1) { return Curry._2(Printf.sprintf(/* Format */[ /* String */Block.__(2, [ /* No_padding */0, /* String_literal */Block.__(11, [ " argument: ", /* String */Block.__(2, [ /* No_padding */0, /* End_of_format */0 ]) ]) ]), "%s argument: %s" ]), argv, err); } else { exit = 1; } if (exit === 1) { return Curry._2(Printf.sprintf(/* Format */[ /* String */Block.__(2, [ /* No_padding */0, /* String_literal */Block.__(11, [ "... arguments: ", /* String */Block.__(2, [ /* No_padding */0, /* End_of_format */0 ]) ]) ]), "%s... arguments: %s" ]), argv, err); } } } function err_flag_value(flag, v) { return Curry._2(Printf.sprintf(/* Format */[ /* String_literal */Block.__(11, [ "option ", /* String */Block.__(2, [ /* No_padding */0, /* String_literal */Block.__(11, [ " is a flag, it cannot take the argument ", /* String */Block.__(2, [ /* No_padding */0, /* End_of_format */0 ]) ]) ]) ]), "option %s is a flag, it cannot take the argument %s" ]), Cmdliner_base.quote(flag), Cmdliner_base.quote(v)); } function err_opt_value_missing(f) { return Curry._1(Printf.sprintf(/* Format */[ /* String_literal */Block.__(11, [ "option ", /* String */Block.__(2, [ /* No_padding */0, /* String_literal */Block.__(11, [ " needs an argument", /* End_of_format */0 ]) ]) ]), "option %s needs an argument" ]), Cmdliner_base.quote(f)); } function err_opt_parse(f, err) { return Curry._2(Printf.sprintf(/* Format */[ /* String_literal */Block.__(11, [ "option ", /* String */Block.__(2, [ /* No_padding */0, /* String_literal */Block.__(11, [ ": ", /* String */Block.__(2, [ /* No_padding */0, /* End_of_format */0 ]) ]) ]) ]), "option %s: %s" ]), Cmdliner_base.quote(f), err); } function err_opt_repeated(f, f$prime) { if (f === f$prime) { return Curry._1(Printf.sprintf(/* Format */[ /* String_literal */Block.__(11, [ "option ", /* String */Block.__(2, [ /* No_padding */0, /* String_literal */Block.__(11, [ " cannot be repeated", /* End_of_format */0 ]) ]) ]), "option %s cannot be repeated" ]), Cmdliner_base.quote(f)); } else { return Curry._2(Printf.sprintf(/* Format */[ /* String_literal */Block.__(11, [ "options ", /* String */Block.__(2, [ /* No_padding */0, /* String_literal */Block.__(11, [ " and ", /* String */Block.__(2, [ /* No_padding */0, /* String_literal */Block.__(11, [ " cannot be present at the same time", /* End_of_format */0 ]) ]) ]) ]) ]), "options %s and %s cannot be present at the same time" ]), Cmdliner_base.quote(f), Cmdliner_base.quote(f$prime)); } } function err_arg_missing(a) { if (Cmdliner_info.arg_is_pos(a)) { return err_pos_miss(a); } else { return Curry._1(Printf.sprintf(/* Format */[ /* String_literal */Block.__(11, [ "required option ", /* String */Block.__(2, [ /* No_padding */0, /* String_literal */Block.__(11, [ " is missing", /* End_of_format */0 ]) ]) ]), "required option %s is missing" ]), Cmdliner_info.arg_opt_name_sample(a)); } } function pp_version(ppf, ei) { var match = Cmdliner_info.term_version(Cmdliner_info.eval_main(ei)); if (match !== undefined) { return Curry._2(Format.fprintf(ppf, /* Format */[ /* Formatting_gen */Block.__(18, [ /* Open_box */Block.__(1, [/* Format */[ /* End_of_format */0, "" ]]), /* Alpha */Block.__(15, [/* Formatting_lit */Block.__(17, [ /* Close_box */0, /* Formatting_lit */Block.__(17, [ /* Flush_newline */4, /* End_of_format */0 ]) ])]) ]), "@[%a@]@." ]), Cmdliner_base.pp_text, match); } else { throw [ Caml_builtin_exceptions.assert_failure, /* tuple */[ "cmdliner_msg.ml", 74, 10 ] ]; } } function pp_try_help(ppf, ei) { var match = Cmdliner_info.eval_kind(ei); if (match >= 491021489) { var exec_cmd = Cmdliner_docgen.plain_invocation(ei); return Curry._2(Format.fprintf(ppf, /* Format */[ /* Formatting_gen */Block.__(18, [ /* Open_box */Block.__(1, [/* Format */[ /* String_literal */Block.__(11, [ "<2>", /* End_of_format */0 ]), "<2>" ]]), /* String_literal */Block.__(11, [ "Try `", /* String */Block.__(2, [ /* No_padding */0, /* String_literal */Block.__(11, [ " --help' or `", /* String */Block.__(2, [ /* No_padding */0, /* String_literal */Block.__(11, [ " --help' for more information.", /* Formatting_lit */Block.__(17, [ /* Close_box */0, /* End_of_format */0 ]) ]) ]) ]) ]) ]) ]), "@[<2>Try `%s --help' or `%s --help' for more information.@]" ]), exec_cmd, Cmdliner_info.term_name(Cmdliner_info.eval_main(ei))); } else { return Curry._1(Format.fprintf(ppf, /* Format */[ /* Formatting_gen */Block.__(18, [ /* Open_box */Block.__(1, [/* Format */[ /* String_literal */Block.__(11, [ "<2>", /* End_of_format */0 ]), "<2>" ]]), /* String_literal */Block.__(11, [ "Try `", /* String */Block.__(2, [ /* No_padding */0, /* String_literal */Block.__(11, [ " --help' for more information.", /* Formatting_lit */Block.__(17, [ /* Close_box */0, /* End_of_format */0 ]) ]) ]) ]) ]), "@[<2>Try `%s --help' for more information.@]" ]), Cmdliner_info.term_name(Cmdliner_info.eval_main(ei))); } } function pp_err(ppf, ei, err) { return Curry._3(Format.fprintf(ppf, /* Format */[ /* String */Block.__(2, [ /* No_padding */0, /* String_literal */Block.__(11, [ ": ", /* Formatting_gen */Block.__(18, [ /* Open_box */Block.__(1, [/* Format */[ /* End_of_format */0, "" ]]), /* Alpha */Block.__(15, [/* Formatting_lit */Block.__(17, [ /* Close_box */0, /* Formatting_lit */Block.__(17, [ /* Flush_newline */4, /* End_of_format */0 ]) ])]) ]) ]) ]), "%s: @[%a@]@." ]), Cmdliner_info.term_name(Cmdliner_info.eval_main(ei)), Cmdliner_base.pp_text, err); } function pp_err_usage(ppf, ei, err) { return Curry._7(Format.fprintf(ppf, /* Format */[ /* Formatting_gen */Block.__(18, [ /* Open_box */Block.__(1, [/* Format */[ /* String_literal */Block.__(11, [ "<v>", /* End_of_format */0 ]), "<v>" ]]), /* String */Block.__(2, [ /* No_padding */0, /* String_literal */Block.__(11, [ ": ", /* Formatting_gen */Block.__(18, [ /* Open_box */Block.__(1, [/* Format */[ /* End_of_format */0, "" ]]), /* Alpha */Block.__(15, [/* Formatting_lit */Block.__(17, [ /* Close_box */0, /* Formatting_lit */Block.__(17, [ /* Break */Block.__(0, [ "@,", 0, 0 ]), /* Formatting_gen */Block.__(18, [ /* Open_box */Block.__(1, [/* Format */[ /* End_of_format */0, "" ]]), /* String_literal */Block.__(11, [ "Usage: ", /* Formatting_gen */Block.__(18, [ /* Open_box */Block.__(1, [/* Format */[ /* End_of_format */0, "" ]]), /* Alpha */Block.__(15, [/* Formatting_lit */Block.__(17, [ /* Close_box */0, /* Formatting_lit */Block.__(17, [ /* Close_box */0, /* Formatting_lit */Block.__(17, [ /* Break */Block.__(0, [ "@,", 0, 0 ]), /* Alpha */Block.__(15, [/* Formatting_lit */Block.__(17, [ /* Close_box */0, /* Formatting_lit */Block.__(17, [ /* Flush_newline */4, /* End_of_format */0 ]) ])]) ]) ]) ])]) ]) ]) ]) ]) ])]) ]) ]) ]) ]), "@[<v>%s: @[%a@]@,@[Usage: @[%a@]@]@,%a@]@." ]), Cmdliner_info.term_name(Cmdliner_info.eval_main(ei)), Cmdliner_base.pp_text, err, (function (param, param$1) { return Cmdliner_docgen.pp_plain_synopsis(ppf, param, param$1); }), ei, pp_try_help, ei); } function pp_backtrace(ppf, ei, e, bt) { var bt$1 = Printexc.raw_backtrace_to_string(bt); var len = bt$1.length; var bt$2 = len > 0 ? $$String.sub(bt$1, 0, len - 1 | 0) : bt$1; return Curry._3(Format.fprintf(ppf, /* Format */[ /* String */Block.__(2, [ /* No_padding */0, /* String_literal */Block.__(11, [ ": ", /* Formatting_gen */Block.__(18, [ /* Open_box */Block.__(1, [/* Format */[ /* End_of_format */0, "" ]]), /* String_literal */Block.__(11, [ "internal error, uncaught exception:", /* Formatting_lit */Block.__(17, [ /* Force_newline */3, /* Alpha */Block.__(15, [/* Formatting_lit */Block.__(17, [ /* Close_box */0, /* Formatting_lit */Block.__(17, [ /* Flush_newline */4, /* End_of_format */0 ]) ])]) ]) ]) ]) ]) ]), "%s: @[internal error, uncaught exception:@\n%a@]@." ]), Cmdliner_info.term_name(Cmdliner_info.eval_main(ei)), Cmdliner_base.pp_lines, Curry._2(Printf.sprintf(/* Format */[ /* String */Block.__(2, [ /* No_padding */0, /* Char_literal */Block.__(12, [ /* "\n" */10, /* String */Block.__(2, [ /* No_padding */0, /* End_of_format */0 ]) ]) ]), "%s\n%s" ]), Printexc.to_string(e), bt$2)); } exports.err_env_parse = err_env_parse; exports.err_pos_excess = err_pos_excess; exports.err_pos_misses = err_pos_misses; exports.err_pos_parse = err_pos_parse; exports.err_flag_value = err_flag_value; exports.err_opt_value_missing = err_opt_value_missing; exports.err_opt_parse = err_opt_parse; exports.err_opt_repeated = err_opt_repeated; exports.err_arg_missing = err_arg_missing; exports.pp_version = pp_version; exports.pp_try_help = pp_try_help; exports.pp_err = pp_err; exports.pp_err_usage = pp_err_usage; exports.pp_backtrace = pp_backtrace; /* Format Not a pure module */