let of_uri uri =
let connection =
Option.value_map ~default:`Localhost (Uri.host uri) ~f:(fun address ->
let add_ssh_options =
Option.value ~default:[] (Uri.get_query_param' uri "ssh-option") in
let user = Uri.userinfo uri in
`Ssh {Ssh.address; port = Uri.port uri; user; add_ssh_options})
in
let playground =
match Uri.path uri with
| "" -> None
| rel when Filename.is_relative rel ->
let cwd = Sys.getcwd () in
Some (Path.absolute_directory_exn (Filename.concat cwd rel))
| p -> Some (Path.absolute_directory_exn p)
in
let default_shell =
Uri.get_query_param uri "shell"
|> Option.bind ~f:(fun s ->
match String.split ~on:(`Character ',') s with
| [] -> None
| one :: [] -> Some (default_shell one)
| one :: two :: [] -> Some (default_shell ~command_option:two one)
| one :: more ->
let command_option = List.last more |> Option.value_exn ~msg:"bug" in
let options = List.split_n more (List.length more - 1) |> fst in
Some (default_shell ~command_option one ~options)
)
in
let execution_timeout =
Uri.get_query_param uri "timeout"
|> Option.bind ~f:Float.of_string in
create ?playground ~connection ?default_shell ?execution_timeout
(Uri.to_string uri)