diff --git a/src/examples/downloader.ml b/src/examples/downloader.ml index cc84058..fa9bf0e 100644 --- a/src/examples/downloader.ml +++ b/src/examples/downloader.ml @@ -101,7 +101,7 @@ let downloader () = let to_loop name_variable t_list = loop_while (string_matches_any name_variable#get - (List.map t_list (fun t -> sprintf "\\.%s$" t.extension))) + (List.map t_list ~f:(fun t -> sprintf "\\.%s$" t.extension))) ~body:(to_switch name_variable t_list) let all = @@ -138,7 +138,7 @@ let downloader () = "Download archives and decrypt/unarchive them.\n\ ./downloader -u URL [-c] [-f ] [-t ]" in - Command_line.parse cli_spec (fun ~anon url all_in_tmp filename_ov tmp_dir -> + Command_line.parse cli_spec (fun ~anon:_ url all_in_tmp filename_ov tmp_dir -> let current_name = tmp_file ~tmp_dir "current-name" in let set_output_of_download () = if_seq diff --git a/src/examples/multigit.ml b/src/examples/multigit.ml index 910657f..e2dc03b 100644 --- a/src/examples/multigit.ml +++ b/src/examples/multigit.ml @@ -282,7 +282,7 @@ Pretty cool, right: [ if_seq version ~t:[out (sprintf "%s: %s" name version_string) []] ~e: - [ setenv (str "PAGER") (str "cat") + [ setenv ~var:(str "PAGER") (str "cat") ; Elist.iter anon ~f:(fun p -> do_section (p ())) ; if_seq no_config ~t:[] ~e: @@ -593,7 +593,7 @@ module Meta_repository = struct in loop [] - let readme_md ~path ~output = + let readme_md ~path:_ ~output = let o = open_out output in let open Format in let fmt = formatter_of_out_channel o in diff --git a/src/examples/service_composer.ml b/src/examples/service_composer.ml index b20775c..3409978 100644 --- a/src/examples/service_composer.ml +++ b/src/examples/service_composer.ml @@ -65,9 +65,7 @@ module Version = struct ; tm_mday ; tm_mon ; tm_year - ; tm_wday - ; tm_yday - ; tm_isdst } -> + ; _ } -> sprintf "%4d%02d%02d.%02d%02d%02d" (1900 + tm_year) (1 + tm_mon) tm_mday tm_hour tm_min tm_sec) @@ -296,7 +294,7 @@ module Manual = struct let () = add - @@ from (fun ~root env -> + @@ from (fun ~root _ -> ksprintf title "%s: Compose Processes With Screen" (pre_title root) ) @ from (fun ~root env -> @@ -329,7 +327,7 @@ module Manual = struct root env.Environment.default_configuration_path ) @ extended ( section "Installation" - @ from (fun ~root env -> + @ from (fun ~root _ -> ksprintf par "Simply copy `%s*` to somewhere in your `$PATH`, the scripts \ depend on a reasonably valid version of `/bin/sh` and GNU \ @@ -339,7 +337,7 @@ module Manual = struct "If you are using the code-generator, you can just point \ the `--output-path` option at the right directory." ) ) @ section "Usage" - @ from (fun ~root env -> + @ from (fun ~root _ -> let intro fmt = ksprintf (ksprintf par @@ -358,7 +356,7 @@ module Manual = struct `%s  --help`." root root ) @ section "Screen Session Isolation" - @ from (fun ~root env -> + @ from (fun ~root _ -> ksprintf par "`%s` isolates Screen sessions by using their session name." root @ ksprintf par @@ -379,7 +377,7 @@ module Manual = struct root ) @ extended ( section "Docker Image For the Generator" - @ from (fun ~root env -> + @ from (fun ~root:_ _ -> let image = "smondet/genspio-doc-dockerfiles:apps406" in ksprintf par "If you have [`opam`](https://opam.ocaml.org), setting up the \ @@ -578,7 +576,7 @@ module Manual_script = struct & flag ["--no-pager"] ~doc:"Do not use a pager." & describe_option_and_usage () in - parse opts (fun ~anon extended no_pager describe -> + parse opts (fun ~anon:_ extended no_pager describe -> deal_with_describe describe [Manual.output ~root ~env extended ||> pager ~disable:no_pager ()] ) ) @@ -591,7 +589,7 @@ module Version_script = struct let description = "Show the version information." end) - let make ~env () = + let make ~env:_ () = Script.make [name] ~description (fun ~root -> let open Gedsl in let open Command_line in @@ -600,7 +598,7 @@ module Version_script = struct flag ["--extended"; "-X"] ~doc:"Provide extra information" & describe_option_and_usage () in - parse opts (fun ~anon extended describe -> + parse opts (fun ~anon:_ extended describe -> deal_with_describe describe [ if_seq extended ~t: @@ -617,7 +615,7 @@ module Init_script = struct end) let make ~env () = - Script.make ["configuration"; name] ~description (fun ~root -> + Script.make ["configuration"; name] ~description (fun ~root:_ -> let open Gedsl in let open Command_line in let opts = @@ -631,7 +629,7 @@ module Init_script = struct ~default:(Environment.make_default_screen_name env) & describe_option_and_usage () in - parse opts (fun ~anon screen_name describe -> + parse opts (fun ~anon:_ screen_name describe -> deal_with_describe describe [Environment.init ~screen_name env; say "Done." []] ) ) end @@ -644,7 +642,7 @@ module Add_job_script = struct end) let make ~env () = - Script.make ["configuration"; name] ~description (fun ~root -> + Script.make ["configuration"; name] ~description (fun ~root:_ -> let open Gedsl in let open Command_line in let default_none = str "--none--" in @@ -660,7 +658,7 @@ module Add_job_script = struct like `top`)" & describe_option_and_usage () in - parse opts (fun ~anon name shell_command interpreter no_log describe -> + parse opts (fun ~anon:_ name shell_command interpreter no_log describe -> let jpath = Job.job_path env name in deal_with_describe describe [ if_then @@ -689,13 +687,10 @@ module Remove_job_script = struct end) let make ~env () = - Script.make ["configuration"; name] ~description (fun ~root -> + Script.make ["configuration"; name] ~description (fun ~root:_ -> let open Gedsl in let open Command_line in - let opts = - let open Arg in - describe_option_and_usage () - in + let opts = describe_option_and_usage () in parse opts (fun ~anon describe -> deal_with_describe describe [ Elist.iter anon ~f:(fun name -> @@ -718,7 +713,7 @@ module Start_script = struct end) let make ~env () = - Script.make [name] ~description (fun ~root -> + Script.make [name] ~description (fun ~root:_ -> let open Gedsl in let open Command_line in let opts = @@ -777,14 +772,11 @@ module Configuration_display_script = struct end) let make ~env () = - Script.make ["configuration"; name] ~description (fun ~root -> + Script.make ["configuration"; name] ~description (fun ~root:_ -> let open Gedsl in let open Command_line in - let opts = - let open Arg in - describe_option_and_usage () - in - parse opts (fun ~anon describe -> + let opts = describe_option_and_usage () in + parse opts (fun ~anon:_ describe -> let path = Environment.configuration_path env in deal_with_describe describe [ say "Configuration path: %s" [path] @@ -815,14 +807,11 @@ module Configuration_destroy_script = struct end) let make ~env () = - Script.make ["configuration"; name] ~description (fun ~root -> + Script.make ["configuration"; name] ~description (fun ~root:_ -> let open Gedsl in let open Command_line in - let opts = - let open Arg in - describe_option_and_usage () - in - parse opts (fun ~anon describe -> + let opts = describe_option_and_usage () in + parse opts (fun ~anon:_ describe -> let path = Environment.configuration_path env in deal_with_describe describe [ say "Configuration path: %s" [path] @@ -857,7 +846,7 @@ module Attach_script = struct ; fail "STOPPING" ] ] ] let make ~env () = - Script.make [name] ~description (fun ~root -> + Script.make [name] ~description (fun ~root:_ -> let open Gedsl in let open Command_line in let opts = @@ -865,7 +854,7 @@ module Attach_script = struct flag ["--create"] ~doc:"Create if it doesn't exist." & describe_option_and_usage () in - parse opts (fun ~anon create describe -> + parse opts (fun ~anon:_ create describe -> deal_with_describe describe [go env create] ) ) end @@ -877,7 +866,7 @@ module Kill_script = struct end) let make ~env () = - Script.make [name] ~description (fun ~root -> + Script.make [name] ~description (fun ~root:_ -> let open Gedsl in let open Command_line in let opts = @@ -927,7 +916,7 @@ module Logs_script = struct end) let make ~env () = - Script.make [name] ~description (fun ~root -> + Script.make [name] ~description (fun ~root:_ -> let open Gedsl in let open Command_line in let opts = @@ -986,7 +975,7 @@ module Status_script = struct end) let make ~env () = - Script.make [name] ~description (fun ~root -> + Script.make [name] ~description (fun ~root:_ -> let open Gedsl in let open Command_line in let opts = @@ -994,7 +983,7 @@ module Status_script = struct flag ["--short"; "-s"] ~doc:"Don't output a ton of info" & describe_option_and_usage () in - parse opts (fun ~anon short describe -> + parse opts (fun ~anon:_ short describe -> let prefix_output = exec ["sed"; "s/^/ | /"] in deal_with_describe describe [ if_seq (Screen.is_on env) @@ -1119,7 +1108,7 @@ module Example_script = struct (List.map example ~f:(fun s -> printf (str " %s\\n") [str s] )) ] in - parse opts (fun ~anon run example describe -> + parse opts (fun ~anon:_ run example describe -> deal_with_describe describe [ switch ( List.map [basic env root] ~f:(fun (n, cl) -> diff --git a/src/examples/vm_tester.ml b/src/examples/vm_tester.ml index 756229a..024dd05 100644 --- a/src/examples/vm_tester.ml +++ b/src/examples/vm_tester.ml @@ -14,11 +14,11 @@ module Shell_script = struct let m = String.map n ~f:(function | ('0' .. '9' | 'a' .. 'z' | 'A' .. 'Z' | '-') as c -> c - | other -> '_' ) + | _ -> '_' ) in String.sub ~index:0 ~length:40 m |> Option.value ~default:m - let path {name; content} = + let path {name; content; _} = let hash = Marshal.to_string content [] |> Digest.string |> Digest.to_hex in @@ -65,7 +65,6 @@ module Run_environment = struct List.map files ~f:(function Http (url, act) as t -> let base = local_file_name t in let wget = - let open Shell_script in let open Genspio.EDSL in check_sequence [ ("mkdir", exec ["mkdir"; "-p"; "_cache"]) @@ -161,7 +160,8 @@ module Run_environment = struct let start_qemu_vm : t -> Shell_script.t = function | { ssh_port - ; vm= Qemu_arm {kernel; machine; sd_card; root_device; initrd; _} } -> + ; vm= Qemu_arm {kernel; machine; sd_card; root_device; initrd; _} + ; _ } -> let open Shell_script in let open Genspio.EDSL in make "Start-qemu-arm" @@ -187,7 +187,7 @@ module Run_environment = struct ; "-append" ; sprintf "console=ttyAMA0 verbose debug root=%s" root_device ] )) - | {ssh_port; vm= Qemu_amd46 {hda; ui}} -> + | {ssh_port; vm= Qemu_amd46 {hda; ui}; _} -> (* See https://wiki.qemu.org/Hosts/BSD qemu-system-x86_64 -m 2048 \ -hda FreeBSD-11.0-RELEASE-amd64.qcow2 -enable-kvm \ @@ -214,8 +214,7 @@ module Run_environment = struct ; "e1000,netdev=mynet0" ] )) let kill_qemu_vm : t -> Shell_script.t = function - | {name} -> - let open Shell_script in + | {name; _} -> let open Genspio.EDSL in let pid = get_stdout (exec ["cat"; "qemu.pid"]) in Shell_script.(make (sprintf "kill-qemu-%s" name)) @@ -240,8 +239,7 @@ module Run_environment = struct ~e:[printf (string "No PID file") []; exec ["false"]] ) ] let configure : t -> Shell_script.t = function - | {name; local_dependencies} -> - let open Shell_script in + | {name; local_dependencies; _} -> let open Genspio.EDSL in let report = tmp_file "configure-report.md" in let there_was_a_failure = tmp_file "bool-failure" in @@ -268,14 +266,14 @@ module Run_environment = struct (List.mapi cmds ~f:(fun i c -> (sprintf "config-%s-%d" name i, c))) let make_dependencies = function - | {vm= Qemu_amd46 {hda}} -> File.make_files [hda] - | {vm= Qemu_arm {kernel; sd_card; initrd}} -> + | {vm= Qemu_amd46 {hda; _}; _} -> File.make_files [hda] + | {vm= Qemu_arm {kernel; sd_card; initrd; _}; _} -> File.make_files ( [kernel; sd_card] @ Option.value_map initrd ~default:[] ~f:(fun x -> [x]) ) let setup_dir_content tvm = - let {name; root_password; setup; ssh_port; vm} = tvm in + let {root_password; setup; ssh_port; _} = tvm in let other_files = ref [] in let dependencies = make_dependencies tvm in let start_deps = List.map dependencies ~f:(fun (base, _, _) -> base) in @@ -361,7 +359,7 @@ module Run_environment = struct ; List.map ( ("help", Some "Display this help message") :: !help_entries ) ~f:(function - | target, None -> "" + | _, None -> "" | target, Some doc -> sprintf "* `make %s`: %s\n" target doc ) |> String.concat ~sep:"" @@ -491,7 +489,7 @@ let () = in let set_example arg = match !example with - | Some s -> fail "Too many arguments (%S)!" arg + | Some _ -> fail "Too many arguments (%S)!" arg | None -> example := Some @@ -535,7 +533,7 @@ let () = let usage = sprintf "vm-tester --vm " in let anon arg = match !path with - | Some s -> fail "Too many arguments (%S)!" arg + | Some _ -> fail "Too many arguments (%S)!" arg | None -> path := Some arg in Arg.parse args anon usage ; diff --git a/src/lib/EDSL.ml b/src/lib/EDSL.ml index 5fbaa9f..49453d8 100644 --- a/src/lib/EDSL.ml +++ b/src/lib/EDSL.ml @@ -82,7 +82,7 @@ let switch l = let default = ref None in let cases = List.filter_map l ~f:(function - | `Default d when !default <> None -> + | `Default _ when !default <> None -> failwith "Cannot build switch with >1 defaults" | `Default d -> default := Some d ; @@ -122,7 +122,7 @@ let tmp_file ?tmp_dir name : file = let clean = String.map name ~f:(function | ('a' .. 'z' | 'A' .. 'Z' | '0' .. '9' | '_' | '-') as c -> c - | other -> '_' ) + | _ -> '_' ) in Str.concat_list [ get_tmp_dir @@ -132,7 +132,7 @@ let tmp_file ?tmp_dir name : file = Digest.(string name |> to_hex)) ] in let tmp = Str.concat_list [path; string "-tmp"] in - object (self) + object (_self) method get = get_stdout (call [string "cat"; path]) method path = path @@ -192,7 +192,7 @@ module Command_line = struct let parse (options : ('a, unit t) cli_options) (action : anon:str list t -> 'a) : unit t = let prefix = Common.Unique_name.variable "getopts" in - let variable {switches; doc} = + let variable {switches; _} = sprintf "%s_%s" prefix (String.concat ~sep:"" switches |> Digest.string |> Digest.to_hex) in @@ -233,7 +233,7 @@ module Command_line = struct f | Opt_cons (Opt_string x, more) -> let var = variable x in - to_init (setenv (string var) x.default) ; + to_init (setenv ~var:(string var) x.default) ; to_case (case (List.fold ~init:(bool false) x.switches ~f:(fun p s -> @@ -245,7 +245,7 @@ module Command_line = struct (string "ERROR option '%s' requires an argument\\n") [getenv (string "1")] ; fail "Wrong command line" ] - ~e:[setenv (string var) (getenv (string "2"))] + ~e:[setenv ~var:(string var) (getenv (string "2"))] ; exec ["shift"] ; exec ["shift"] ]) ; ksprintf to_help "* `%s `: %s" @@ -254,12 +254,12 @@ module Command_line = struct loop (f (string_of_var var)) more | Opt_cons (Opt_flag x, more) -> let var = variable x in - to_init (setenv (string var) (Bool.to_string x.default)) ; + to_init (setenv ~var:(string var) (Bool.to_string x.default)) ; to_case (case (List.fold ~init:(bool false) x.switches ~f:(fun p s -> p ||| Str.equals (string s) (getenv (string "1")) )) - [ setenv (string var) (Bool.to_string (bool true)) + [ setenv ~var:(string var) (Bool.to_string (bool true)) ; exec ["shift"] ]) ; ksprintf to_help "* `%s`: %s" (String.concat ~sep:"," x.switches) @@ -276,7 +276,7 @@ module Command_line = struct let while_loop = let body = let append_anon_arg_to_list = - setenv anon_var + setenv ~var:anon_var ( Elist.append anon (Elist.make [getenv (string "1")]) |> Elist.serialize_str_list ) in @@ -285,7 +285,7 @@ module Command_line = struct case (List.fold ~init:(bool false) help_switches ~f:(fun p s -> p ||| Str.(str s =$= getenv (str "1")) )) - [ setenv help_flag_var (Bool.to_string (bool true)) + [ setenv ~var:help_flag_var (Bool.to_string (bool true)) ; byte_array help_msg >> exec ["cat"] ; exec ["break"] ] in @@ -313,8 +313,8 @@ module Command_line = struct loop_while (bool true) ~body in seq - [ setenv help_flag_var (Bool.to_string (bool false)) - ; setenv anon_var (Elist.serialize_byte_array_list (Elist.make [])) + [ setenv ~var:help_flag_var (Bool.to_string (bool false)) + ; setenv ~var:anon_var (Elist.serialize_byte_array_list (Elist.make [])) ; seq (List.rev !inits) ; while_loop ; if_then_else @@ -380,9 +380,9 @@ let fresh_name suf = let sanitize_name n = String.map n ~f:(function | ('0' .. '9' | 'a' .. 'z' | 'A' .. 'Z' | '-') as c -> c - | other -> '_' ) + | _ -> '_' ) -let default_on_failure ~step:(i, u) ~stdout ~stderr = +let default_on_failure ~step:(i, _) ~stdout ~stderr = seq [ printf (ksprintf str "Step '%s' FAILED:\\n" i) [] ; cat_markdown "stdout" stdout @@ -391,7 +391,7 @@ let default_on_failure ~step:(i, u) ~stdout ~stderr = let check_sequence ?(verbosity = `Announce ">> ") ?(on_failure = default_on_failure) - ?(on_success = fun ~step ~stdout ~stderr -> nop) ?(tmpdir = "/tmp") cmds = + ?(on_success = fun ~step:_ ~stdout:_ ~stderr:_ -> nop) ?(tmpdir = "/tmp") cmds = let tmp_prefix = fresh_name "-cmd" in let tmpout which id = str diff --git a/src/lib/EDSL.mli b/src/lib/EDSL.mli index 9a6f21a..9602f16 100644 --- a/src/lib/EDSL.mli +++ b/src/lib/EDSL.mli @@ -15,10 +15,13 @@ type 'a t = 'a Language.t to a C-string. *) type str = Language.byte_array +type byte_array = Language.byte_array +type c_string = Language.c_string + (** {3 Literals } *) val str : string -> str t -(** Create a {!type:c_string} literal. *) +(** Create a {!type:byte_array} literal. *) val string : string -> str t (** [string] is an alias for {!function:str}. *) @@ -60,7 +63,7 @@ val setenv : var:str t -> str t -> unit t If the [~var] argument is not a valid variable name or if the value does not fit in a shell variable (e.g. newlines), behavior is undefined. - + Also, the total environment of a UNIX process counts towards the total size of the arguments passed on to a sub-process (see usually the result of ["getconf ARG_MAX"]). Genspio does not check @@ -254,7 +257,7 @@ val to_file : int t -> str t -> fd_redirection (** Create a file-descriptor to file redirection. *) val with_redirections : unit t -> fd_redirection list -> unit t -(** +(** Run a [unit t] expression after applying a list of file-descriptor redirections. @@ -323,7 +326,7 @@ type file = val tmp_file : ?tmp_dir:str t -> string -> file (** Create a temporary file that may contain arbitrary strings (can be used as variable containing [string t] values). - + [tmp_file "foo"] points to a path that is a {b function} of the string ["foo"]; it does not try to make temporary-files unique, on the contrary: two calls to [tmp_file "foo"] ensure that @@ -334,7 +337,7 @@ val tmp_file : ?tmp_dir:str t -> string -> file (** Typed command-line parsing for your shell scripts, à la {!Printf.scanf}. *) module Command_line : sig - (** + (** Use this module like OCaml's {!Printf.scanf} function. @@ -369,7 +372,7 @@ module Command_line : sig string Genspio.EDSL.t -> string Genspio.EDSL.t -> unit Genspio.EDSL.t, unit Genspio.EDSL.t) Genspio.EDSL.Command_line.cli_options - + so the action function (the second argument to parse) must have type: anon:string list Genspio.EDSL.t -> @@ -565,7 +568,7 @@ val ensure : string -> condition:bool t -> how:(string * unit t) list -> unit t - If [true] do nothing, succeed - If [false], run [~how] with {!check_sequence}. - Test the condition again, if [true] succeed, if [false] fail. - + Failures happen thanks to the !{fail} call. *) @@ -641,18 +644,18 @@ module Dispatcher_script : sig -> description:string -> unit -> unit Genspio__Language.t - (** + (** Make a “toplevel” script that behaves a bit like ["git"] by calling [name ^ "-${1}"]. The search for the argument can be “hijacked” with the list of [~aliases]; with [~name:"hello"] and [~aliases:[str "W", str "wolrd"]], when ["hello W"] is called, the generated script with lool for ["hello-world"] in the ["$PATH"]. - + Just like scripts made with {!Script_with_describe}, the [~description] argument is used to answer the ["--describe"] command line option. - + When called without arguments, with ["-h"], ["-help"], or with ["--help"], the script lists all the commands it can find and the aliases. E.g.: diff --git a/src/lib/EDSL_v0.ml b/src/lib/EDSL_v0.ml index ba922a0..d71afa5 100644 --- a/src/lib/EDSL_v0.ml +++ b/src/lib/EDSL_v0.ml @@ -20,7 +20,7 @@ let switch l = let default = ref None in let cases = List.filter_map l ~f:(function - | `Default d when !default <> None -> + | `Default _ when !default <> None -> failwith "Cannot build switch with >1 defaults" | `Default d -> default := Some d ; @@ -64,7 +64,7 @@ let tmp_file ?tmp_dir name : file = let clean = String.map name ~f:(function | ('a' .. 'z' | 'A' .. 'Z' | '0' .. '9' | '_' | '-') as c -> c - | other -> '_' ) + | _ -> '_' ) in C_string.concat_list [ get_tmp_dir @@ -137,7 +137,7 @@ module Command_line = struct let parse (options : ('a, unit t) cli_options) (action : anon:c_string list t -> 'a) : unit t = let prefix = Common.Unique_name.variable "getopts" in - let variable {switches; doc} = + let variable {switches; _} = sprintf "%s_%s" prefix (String.concat ~sep:"" switches |> Digest.string |> Digest.to_hex) in @@ -181,7 +181,7 @@ module Command_line = struct f | Opt_cons (Opt_string x, more) -> let var = variable x in - to_init (setenv (string var) x.default) ; + to_init (setenv ~var:(string var) x.default) ; to_case (case (List.fold ~init:(bool false) x.switches ~f:(fun p s -> @@ -193,7 +193,7 @@ module Command_line = struct (string "ERROR option '%s' requires an argument\\n") [getenv (string "1")] ; fail "Wrong command line" ] - ~e:[setenv (string var) (getenv (string "2"))] + ~e:[setenv ~var:(string var) (getenv (string "2"))] ; exec ["shift"] ; exec ["shift"] ]) ; ksprintf to_help "* `%s `: %s" @@ -202,12 +202,12 @@ module Command_line = struct loop (f (string_of_var var)) more | Opt_cons (Opt_flag x, more) -> let var = variable x in - to_init (setenv (string var) (Bool.to_string x.default)) ; + to_init (setenv ~var:(string var) (Bool.to_string x.default)) ; to_case (case (List.fold ~init:(bool false) x.switches ~f:(fun p s -> p ||| C_string.equals (string s) (getenv (string "1")) )) - [ setenv (string var) (Bool.to_string (bool true)) + [ setenv ~var:(string var) (Bool.to_string (bool true)) ; exec ["shift"] ]) ; ksprintf to_help "* `%s`: %s" (String.concat ~sep:"," x.switches) @@ -236,7 +236,7 @@ module Command_line = struct case (List.fold ~init:(bool false) help_switches ~f:(fun p s -> p ||| C_string.(c_string s =$= getenv (c_string "1")) )) - [ setenv help_flag_var (Bool.to_string (bool true)) + [ setenv ~var:help_flag_var (Bool.to_string (bool true)) ; byte_array help_msg >> exec ["cat"] ; exec ["break"] ] in @@ -264,7 +264,7 @@ module Command_line = struct loop_while (bool true) ~body in seq - [ setenv help_flag_var (Bool.to_string (bool false)) + [ setenv ~var:help_flag_var (Bool.to_string (bool false)) ; anon_tmp#set (Elist.serialize_byte_array_list (Elist.make [])) ; seq (List.rev !inits) ; while_loop @@ -331,9 +331,9 @@ let fresh_name suf = let sanitize_name n = String.map n ~f:(function | ('0' .. '9' | 'a' .. 'z' | 'A' .. 'Z' | '-') as c -> c - | other -> '_' ) + | _ -> '_' ) -let default_on_failure ~step:(i, u) ~stdout ~stderr = +let default_on_failure ~step:(i, _) ~stdout ~stderr = seq [ printf (ksprintf c_string "Step '%s' FAILED:\\n" i) [] ; cat_markdown "stdout" stdout @@ -342,7 +342,7 @@ let default_on_failure ~step:(i, u) ~stdout ~stderr = let check_sequence ?(verbosity = `Announce ">> ") ?(on_failure = default_on_failure) - ?(on_success = fun ~step ~stdout ~stderr -> nop) ?(tmpdir = "/tmp") cmds = + ?(on_success = fun ~step:_ ~stdout:_ ~stderr:_ -> nop) ?(tmpdir = "/tmp") cmds = let tmp_prefix = fresh_name "-cmd" in let tmpout which id = c_string diff --git a/src/lib/compile.ml b/src/lib/compile.ml index 3024541..8ddf970 100644 --- a/src/lib/compile.ml +++ b/src/lib/compile.ml @@ -1,7 +1,5 @@ open Common -type 'a t = 'a Language.t - let default_max_argument_length = Some 100_000 module To_posix = struct @@ -38,7 +36,7 @@ module To_posix = struct let failure_to_stderr : death_function = fun ~comment_stack msg -> let summary s = - match String.sub s 0 65 with Some s -> s ^ " …" | None -> s + match String.sub s ~index:0 ~length:65 with Some s -> s ^ " …" | None -> s in let open Format in let big_string fmt s = Format.fprintf fmt "@[%s@]" (summary s) in @@ -74,8 +72,7 @@ module To_posix = struct let statement_separator = match options.style with `Multi_line -> "\n" | `One_liner -> " ; " in - let {max_argument_length; print_failure} = options in - let open Language in + let {max_argument_length; print_failure;_} = options in match options.fail_with with | `Nothing -> to_shell diff --git a/src/lib/language.ml b/src/lib/language.ml index 7bd3ee9..76348e5 100644 --- a/src/lib/language.ml +++ b/src/lib/language.ml @@ -27,7 +27,7 @@ module Literal = struct |'/' | '#' | '@' | '!' | ' ' | '~' | '`' | '\\' | '|' | '?' | '>' |'<' | '.' | ',' | ':' | ';' | '{' | '}' | '(' | ')' | '[' | ']' -> true - | other -> false ) + | _ -> false ) let impossible_to_escape_for_variable = String.exists ~f:(( = ) '\x00') end @@ -181,9 +181,9 @@ let rec pp : type a. Format.formatter -> a t -> unit = | String_to_int i -> pp_fun_call fmt "string-to-int" pp [i] | Bool_to_string b -> pp_fun_call fmt "bool-to-string" pp [b] | String_to_bool b -> pp_fun_call fmt "string-to-bool" pp [b] - | List_to_string (l, f) -> pp_fun_call fmt "list-to-string" pp [l] + | List_to_string (l, _) -> pp_fun_call fmt "list-to-string" pp [l] (* : 'a list t * ('a t -> byte_array t) -> byte_array t *) - | String_to_list (s, f) -> pp_fun_call fmt "string-to-list" pp [s] + | String_to_list (s, _) -> pp_fun_call fmt "string-to-list" pp [s] | List l -> pp_fun_call fmt "list" pp l | C_string_concat t -> pp_fun_call fmt "c-string-concat" pp [t] | Byte_array_concat t -> pp_fun_call fmt "byte-array-concat" pp [t] @@ -277,7 +277,7 @@ module Construct = struct let ( %%% ) s u = comment s u - let make_switch : type a. + let make_switch : (bool t * unit t) list -> default:unit t -> unit t = fun conds ~default -> List.fold_right conds ~init:default ~f:(fun (x, body) prev -> diff --git a/src/lib/standard_compiler.ml b/src/lib/standard_compiler.ml index 99ad815..b37b694 100644 --- a/src/lib/standard_compiler.ml +++ b/src/lib/standard_compiler.ml @@ -90,7 +90,7 @@ let error ?code ~comment_backtrace error = let pp_error fmt {code; comment_backtrace; error} = let open Format in let summary s = - match String.sub s 0 70 with Some s -> s ^ " …" | None -> s + match String.sub s ~index:0 ~length:70 with Some s -> s ^ " …" | None -> s in let big_string fmt s = fprintf fmt "@[%s@]" (summary s) in fprintf fmt "@[" ; @@ -391,9 +391,9 @@ let rec to_ir : type a. _ -> _ -> a Language.t -> internal_representation = | one :: two :: t -> one :: "printf -- ' '" :: build (two :: t) in seq (build outputs) |> ir_list - | List_to_string (l, f) -> + | List_to_string (l, _) -> continue (Output_as_string (Raw_cmd (None, continue l))) |> ir_octostring - | String_to_list (s, f) -> + | String_to_list (s, _) -> continue s |> expand_octal |> sprintf "printf -- '%%s' \"$(%s)\"" |> ir_list diff --git a/src/lib/to_slow_flow.ml b/src/lib/to_slow_flow.ml index 5cc58d9..f4c6f9c 100644 --- a/src/lib/to_slow_flow.ml +++ b/src/lib/to_slow_flow.ml @@ -168,12 +168,12 @@ In that case, we compare the octal representations. let to_path_argument = function | Unit -> assert false | Raw_inline s -> s - | Literal_value s -> assert false + | Literal_value _ -> assert false | File f -> Filename.quote f | Tmp_file_in_variable f -> (* Parameters.(tmp_file_db := f :: !tmp_file_db) ; *) sprintf "\"${%s}\"" f - | Octal_value_in_variable var -> assert false + | Octal_value_in_variable _ -> assert false (*md @@ -297,7 +297,7 @@ In that case, we compare the octal representations. in {commands= commands @ morecmds; result= r} - let return_value_to_bool ~tmp {commands; result} v = + let return_value_to_bool ~tmp {commands; _} v = { tmp with commands= tmp.commands @ commands @@ -391,7 +391,7 @@ let rec to_ir : type a. fail_commands:_ -> tmpdb:_ -> a t -> Script.t = | Unit -> assert false | Literal_value li when String.exists li ~f:(( = ) '\x00') -> fail_commands "Cannot convert literal %S to C-String" - | Literal_value li -> [] + | Literal_value _ -> [] | File f -> [ If_then_else { condition= @@ -410,7 +410,7 @@ let rec to_ir : type a. fail_commands:_ -> tmpdb:_ -> a t -> Script.t = ksprintf fail_commands "Byte array in $%s cannot be converted to a C-String" v ; block_else= [] } ] - | Raw_inline ri -> [] + | Raw_inline _ -> [] | Octal_value_in_variable v -> [ If_then_else { condition= @@ -468,7 +468,7 @@ let rec to_ir : type a. fail_commands:_ -> tmpdb:_ -> a t -> Script.t = match s.result with | Unit -> Script.commands s | Raw_inline cmd -> Script.(Raw cmd :: commands s) - | other -> assert false ) + | _ -> assert false ) in Script.unit cmds | Not t -> @@ -610,8 +610,8 @@ let rec to_ir : type a. fail_commands:_ -> tmpdb:_ -> a t -> Script.t = as_arg tmparg ] ) ) in List.concat_map scripts ~f:(fun c -> c.commands) @ echos ) - | List_to_string (l, f) -> continue l - | String_to_list (s, f) -> continue s + | List_to_string (l, _) -> continue l + | String_to_list (s, _) -> continue s | C_string_concat sl -> let sl_script = continue sl in concat_string_list sl_script @@ -883,7 +883,7 @@ let test () = ] ; seq [ setenv - (C_string.concat_list [c_string "A"; c_string "A"; c_string "A"]) + ~var:(C_string.concat_list [c_string "A"; c_string "A"; c_string "A"]) (get_stdout (exec ["echo"; "HELLO WORLD"]) |> Byte_array.to_c) ; "Calling a sub-shell with `sh`,\nit should display HELLO WORLD" %%% exec ["sh"; "-c"; "echo \"$AAA\""] ] @@ -896,10 +896,10 @@ let test () = let v1 = c_string "V1" in let v2 = c_string "V2" in seq - [ setenv var v1 + [ setenv ~var v1 ; loop_seq_while C_string.(getenv var =$= v1) - [printf (c_string "Iteration\\n") []; setenv var v2] ]) ] + [printf (c_string "Iteration\\n") []; setenv ~var v2] ]) ] in List.iteri exprs ~f:(fun idx expr -> let ir = compile expr in diff --git a/src/lib/transform.ml b/src/lib/transform.ml index 7ab0747..7331609 100644 --- a/src/lib/transform.ml +++ b/src/lib/transform.ml @@ -199,13 +199,13 @@ The `propagator` class inherits from `Visitor.nothing_doer` and overwrites only *) class propagator ?trace () = object (self) - inherit Visitor.nothing_doer ?trace () as super + inherit Visitor.nothing_doer ?trace () as _super (*md Boolean operators are not commutative, the left side has to be evaluated first and may break the execution flow (e.g. with `fail`). *) - method bool_operator (a, op, b) = + method! bool_operator (a, op, b) = let ga = self#expression a in let gb = self#expression b in match (ga, op, gb) with @@ -219,7 +219,7 @@ literals (all non-literals can be non-deterministic and side-effectful). *) - method string_operator (a, op, b) = + method! string_operator (a, op, b) = let ga = self#expression a in let gb = self#expression b in match (ga, op, gb) with @@ -230,7 +230,7 @@ side-effectful). | `Eq -> Literal.Bool (sa = sb) ) | _ -> String_operator (ga, op, gb) - method returns : type a. expr:a t -> _ = + method! returns : type a. expr:a t -> _ = fun ~expr ~value -> let e = self#expression expr in match (e, value) with @@ -238,7 +238,7 @@ side-effectful). | No_op, _ -> Construct.bool false | _ -> Returns {expr; value} - method if_ (c, t, e) = + method! if_ (c, t, e) = let gc = self#expression c in let gt = self#expression t in let ge = self#expression e in @@ -247,28 +247,28 @@ side-effectful). | Literal (Literal.Bool false) -> ge | _ -> If (gc, gt, ge) - method while_ ~condition ~body = + method! while_ ~condition ~body = match self#expression condition with | Literal (Literal.Bool false) -> No_op | cond -> While {condition= cond; body= self#expression body} - method not b = + method! not b = let gb = self#expression b in match gb with | Literal (Literal.Bool b) -> Literal (Literal.Bool (not b)) | other -> Not other - method seq l = + method! seq l = let transformed = List.map ~f:self#expression l |> List.filter ~f:(( <> ) No_op) in match transformed with [] -> No_op | [one] -> one | l -> Seq l - method pipe l = + method! pipe l = let tr = List.map ~f:self#expression l in match tr with Pipe l :: more -> Pipe (l @ more) | other -> Pipe other - method c_string_concat l = + method! c_string_concat l = let gl = self#expression l in match gl with | List [] -> Construct.c_string "" @@ -294,7 +294,7 @@ side-effectful). | more -> C_string_concat (List more) ) | default -> C_string_concat default - method byte_array_concat l = + method! byte_array_concat l = let gl = self#expression l in match gl with | List [] -> Construct.byte_array "" @@ -315,7 +315,7 @@ side-effectful). | more -> Byte_array_concat (List more) ) | default -> Byte_array_concat default - method list_append (a, b) = + method! list_append (a, b) = let la = self#expression a in let lb = self#expression b in match (la, lb) with @@ -324,11 +324,11 @@ side-effectful). | List lla, List llb -> List (lla @ llb) | _, _ -> List_append (la, lb) - method list_iter (l, f) = + method! list_iter (l, f) = let gl = self#expression l in match gl with List [] -> No_op | _ -> List_iter (gl, f) - method int_bin_op (a, op, b) = + method! int_bin_op (a, op, b) = let ga = self#expression a in let gb = self#expression b in let default = Int_bin_op (ga, op, gb) in @@ -347,7 +347,7 @@ side-effectful). | _ -> default ) | _ -> default - method int_bin_comparison (a, op, b) = + method! int_bin_comparison (a, op, b) = let ga = self#expression a in let gb = self#expression b in let default = Int_bin_comparison (ga, op, gb) in @@ -438,7 +438,7 @@ side-effectful). [ e 42 ; loop_seq_while ("Comment on the success" %%% succeeds (s 0)) - [e 1; "Comment on the `setenv`" %%% setenv (string "bouh") expr] + [e 1; "Comment on the `setenv`" %%% setenv ~var:(string "bouh") expr] ]) in check "deep1" diff --git a/src/test-lib/test_lib.ml b/src/test-lib/test_lib.ml index bee7cda..a643849 100644 --- a/src/test-lib/test_lib.ml +++ b/src/test-lib/test_lib.ml @@ -118,12 +118,12 @@ let optimize : type a. _ -> a Genspio.Language.t -> _ = let stderr_path test = sprintf "_log/%s/stderr.txt" @@ unique_name test - let display_script t = function - | Exits {no_trap; name; args; returns; script} -> + let display_script _t = function + | Exits {script; _} -> Genspio.Compile.to_string_hum script let display_opti_script t = function - | Exits {no_trap; name; args; returns; script} -> + | Exits {script; _} -> List.fold t.optimization_passes ~init:script ~f:(fun prev -> function | `Cst_prop -> Genspio.Transform.Constant_propagation.process prev ) |> Genspio.Compile.to_string_hum @@ -131,7 +131,7 @@ let optimize : type a. _ -> a Genspio.Language.t -> _ = let run_test_script t = let test_name = name t in function - | Exits {no_trap; name; args; returns; script} as test -> + | Exits {name; args; returns; _} as test -> let fill_result_file which = let echos = [ sprintf "- Returns $RRR (expected: %d)." returns @@ -183,7 +183,7 @@ let optimize : type a. _ -> a Genspio.Language.t -> _ = else "" ) let script_content t = function - | Exits {no_trap; name; args; returns; script} -> ( + | Exits {no_trap; script; _} -> ( let script = List.fold t.optimization_passes ~init:script ~f:(fun prev -> function | `Cst_prop -> Genspio.Transform.Constant_propagation.process prev @@ -198,7 +198,7 @@ let optimize : type a. _ -> a Genspio.Language.t -> _ = |> Format.asprintf "%a\n" Genspio.Compile.To_slow_flow.Script.pp_posix ) - let make_report_path t = "script" // "make_report.sh" + let make_report_path _ = "script" // "make_report.sh" let make_report_content t testlist = (let open Genspio.EDSL_v0 in @@ -369,7 +369,7 @@ module Example = struct let fence = String.make 50 '`' in ff fmt "%s%s@\n%s@\n%s@\n@\n" fence lang (String.strip code) fence in - let if_show s f = if List.mem s show then f () else () in + let if_show s f = if List.mem s ~set:show then f () else () in let try_url = let base = try Sys.getenv "genspio_demo_url" with _ -> default_demo_url diff --git a/src/test/main.ml b/src/test/main.ml index 5f52bb4..dc9e635 100644 --- a/src/test/main.ml +++ b/src/test/main.ml @@ -424,7 +424,7 @@ let () = exits ~name:(sprintf "parse-cli-only-anon-%s" name) ~args 0 - (Command_line.parse spec (fun ~anon one two bone -> + (Command_line.parse spec (fun ~anon _ _ _ -> assert_or_fail (sprintf "anon-is-anon-%s" name) (check_anon anon args) )) @@ -807,7 +807,7 @@ let () = let () = add_tests @@ List.concat - [ exits 2 ~name:"no-trap" Genspio.EDSL.(return 2) + [ exits 2 ~name:"no-trap" (return 2) (* Dying with error messages does not work without `trap` any more (string-schism): *) (* exits 2 ~no_trap:true ~name:"no-trap-but-failwith" Genspio.EDSL.( *) @@ -1101,7 +1101,7 @@ let () = ; return 5 ]) in List.concat_mapi ~f:make_int_test - [[]; [1]; [3]; [1; 2; 3]; [1; 2; 3; 0]; List.init 42 (fun i -> i)] + [[]; [1]; [3]; [1; 2; 3]; [1; 2; 3; 0]; List.init 42 ~f:(fun i -> i)] let () = add_tests @@ -1299,7 +1299,8 @@ let compilation_error_tests () = in printf "* %s: %s\n%s\n%!%!" (if succ then "SUCCESS" else "FAILURE") - (String.sub expr_str 0 60 |> Option.value ~default:expr_str) + (String.sub expr_str ~index:0 ~length:60 + |> Option.value ~default:expr_str) res_str ) ; List.exists !results ~f:(fun (_, res, _) -> res = false) @@ -1353,7 +1354,6 @@ let () = | moar -> failf "Too many arguments: %s" (String.concat ~sep:", " moar) in Option.iter path_opt ~f:(fun path -> - let open Test in let testlist = List.concat !tests |> @@ -1363,11 +1363,9 @@ let () = let matches name = String.index_of_string name ~sub:s <> None in fun tests -> List.filter tests ~f:(function - | Tests.Test_lib.Test.Exits - {no_trap; name; args; returns; script} - when matches name -> + | Tests.Test_lib.Test.Exits { name; _} when matches name -> true - | other -> false ) + | _ -> false ) in printf "Testlist: %d\n%!" (List.length testlist) ; let testdir =