+ let input = ref Paths_on_stdin in
+ let output = ref Stdout in
+ let assert_file_exists path =
+ if Sys.file_exists path then
+ ()
+ else begin
+ eprintf "File does not exist: %S\n%!" path;
+ exit 1
+ end
+ in
+ let assert_file_is_dir path =
+ if Sys.is_directory path then
+ ()
+ else begin
+ eprintf "File is not a directory: %S\n%!" path;
+ exit 1
+ end
+ in
+ let spec =
+ [ ( "-out"
+ , Arg.String (fun path ->
+ assert_file_exists path;
+ assert_file_is_dir path;
+ output := Directory path
+ )
+ , " Output to this directory instead of stdout."
+ )
+ ]
+ in
+ Arg.parse
+ (Arg.align spec)
+ (fun path ->
+ assert_file_exists path;
+ assert_file_is_dir path;
+ match !input with
+ | Paths_on_stdin ->
+ input := Root_paths [path]
+ | Root_paths paths ->
+ input := Root_paths (path :: paths)
+ )
+ "";
+ main !input !output