1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556openError_monadtypeoutput_format=Rowsof{separator:string;escape:[`No|`OCaml]}letrowsseparatorescape=Rows{separator;escape}lettsv=rows"\t"`Noletcsv=rows","`OCamlletclic_arg()=letopenClicinarg~doc:"Make the output script-friendly. Possible values are 'TSV' and 'CSV'."~long:"for-script"~placeholder:"FORMAT"(parameter(fun_spec->matchString.lowercase_asciispecwith|"tsv"->returntsv|"csv"->returncsv|other->failwith"Cannot recognize format %S, please try 'TSV' or 'CSV'"other))letfprintf_lwtchanfmt=Format.kasprintf(funs->protect(fun()->Lwt_io.writechans>>=fun()->return_unit))fmtletoutput?(channel=Lwt_io.stdout)how_option~for_human~for_script=matchhow_optionwith|None->for_human()|Some(Rows{separator;escape})->letopenFormatinList.iter_es(funrow->fprintf_lwtchannel"%a@."(pp_print_list~pp_sep:(funfmt()->pp_print_stringfmtseparator)(funfmtcell->matchescapewith|`OCaml->fprintffmt"%S"cell|`No->pp_print_stringfmtcell))row)(for_script())>>=?fun()->protect(fun()->Lwt_io.flushchannel>>=fun()->return_unit)letoutput_for_humanhow_optionfor_human=outputhow_option~for_human~for_script:(fun()->[])letoutput_row?channelhow_option~for_human~for_script=output?channelhow_option~for_human~for_script:(fun()->[for_script()])