let name = __FILE__ let description = "Return the parent of the given content. The configuration is read on the \ standard input" let parent = ref Model.Content.parent let speclist = [ ( "--root", Arg.Unit (fun () -> parent := fun content -> Some (Model.Content.root content)), "Return the root element instead of the parent" ); ] type t = (string option option, Configuration.Read_conf.error) result let pp : Format.formatter -> t -> unit = Format.pp_print_result ~error:Configuration.Read_conf.pp_error ~ok: (Format.pp_print_option ~none:(fun f () -> Format.pp_print_string f "[Content not found]") @@ Format.pp_print_option ~none:(fun f () -> Format.pp_print_string f "[No parent]") @@ fun f -> Format.fprintf f "\"%s\"") let exec : string list -> t = function | [ subcontent_id ] -> let parent_id = let stdin = In_channel.input_all stdin in let ( let+ ) opt cont = Result.map cont opt in let+ configuration = Configuration.Read_conf.read_string_conf stdin in let ( let+ ) opt cont = Option.map cont opt in let+ subcontent = Configuration.Ast.get_content configuration subcontent_id in let+ v = !parent subcontent in Model.Content.id v in parent_id | _ -> failwith "Invalid arguments"