Skip to content
Permalink
Browse files

Add interactive mode

  • Loading branch information
rvantonder committed Sep 24, 2019
1 parent be2f84c commit fcb4b41f53f589861863893dfd06cb19d22a5a0e
@@ -5,3 +5,5 @@ _build
\#*
.\#*
scripts/0.*
scripts/1.*
*.swp
@@ -321,19 +321,21 @@ fi
opam --version
opam --git-version

opam install ppx_deriving_yojson
opam install core
opam install ppxlib
opam install ppx_deriving
opam install tls
opam install angstrom
opam install hack_parallel
opam install opium
opam install pcre
opam install oasis
opam install camlzip
opam install bisect_ppx
opam install patdiff
opam install -y \
ppx_deriving_yojson \
core \
ppxlib \
ppx_deriving \
angstrom \
hack_parallel \
opium \
pcre \
oasis \
tls \
camlzip \
bisect_ppx \
patdiff \
lambda-term

git clone https://github.com/comby-tools/mparser
cd mparser
@@ -2,6 +2,10 @@ open Core

open Language

let debug =
Sys.getenv "DEBUG_COMBY"
|> Option.is_some

(* skip or continue directory descent *)
type 'a next =
| Skip of 'a
@@ -114,6 +118,7 @@ type output_options =
; stdout : bool
; substitute_in_place : bool
; count : bool
; interactive_review : string option
}

type anonymous_arguments =
@@ -226,6 +231,7 @@ module Printer = struct
type diff_kind = Diff_configuration.kind

type output_format =
| Interactive_review of string option
| Overwrite_file
| Stdout
| Diff of diff_kind
@@ -254,6 +260,7 @@ module Printer = struct
| In_place

type output_format =
| Interactive_review of string option
| Overwrite_file
| Stdout
| Diff of diff_kind
@@ -268,6 +275,7 @@ module Printer = struct
let convert output_options : replacement_output =
let output_format =
match output_options with
| { interactive_review = Some editor; _ } -> Interactive_review (Some editor)
| { overwrite_file_in_place = true; _ } -> Overwrite_file
| { stdout = true; _ } -> Stdout
| { json_lines = true; overwrite_file_in_place = false; json_only_diff; _ } ->
@@ -300,9 +308,8 @@ module Printer = struct
let print_if_some output = Option.value_map output ~default:() ~f:(Format.fprintf ppf "%s@.") in
match output_format with
| Stdout -> Format.fprintf ppf "%s" rewritten_source
| Overwrite_file ->
(* Exn OK because we checked in validate_errors. *)
Out_channel.write_all ~data:rewritten_source (Option.value_exn path )
| Overwrite_file -> Out_channel.write_all ~data:rewritten_source (Option.value path ~default:"/dev/null")
| Interactive_review _ -> () (* Handled after (potentially parallel) processing *)
| Diff kind -> print_if_some @@ Diff_configuration.get_diff kind path source_content rewritten_source
| Match_only -> print_if_some @@ Diff_configuration.get_diff Match_only path rewritten_source source_content
| Json_lines kind ->
@@ -326,6 +333,7 @@ type t =
; exclude_directory_prefix : string
; run_options : run_options
; output_printer : Printer.t
; interactive_review : string option
}

let validate_errors { input_options; run_options = _; output_options } =
@@ -338,6 +346,10 @@ let validate_errors { input_options; run_options = _; output_options } =
, "-in-place may not be used with -stdout."
; output_options.overwrite_file_in_place && output_options.diff
, "-in-place may not be used with -diff."
; Option.is_some output_options.interactive_review && (input_options.stdin || Option.is_some input_options.zip_file || input_options.match_only)
, "-review cannot be used with one or more of the following input flags: -stdin, -zip, -match-only."
; Option.is_some output_options.interactive_review && (output_options.json_lines || output_options.json_only_diff || output_options.stdout || output_options.diff || output_options.overwrite_file_in_place || output_options.count)
, "-review cannot be used with one or more of the following output flags: -json-lines, -json-only-diff, -stdout, -in-place, -count"
; input_options.anonymous_arguments = None &&
(input_options.specification_directories = None
|| input_options.specification_directories = Some [])
@@ -434,6 +446,7 @@ let create
; output_options =
({ overwrite_file_in_place
; color
; interactive_review
; _
} as output_options)
} as configuration)
@@ -484,7 +497,8 @@ let create
let overwrite_file_in_place =
if input_source = Zip || input_source = Stdin then
false
else overwrite_file_in_place
else
overwrite_file_in_place
in
let output_options = { output_options with overwrite_file_in_place } in
let output_printer printable =
@@ -516,4 +530,5 @@ let create
; substitute_in_place
}
; output_printer
; interactive_review
}
@@ -26,6 +26,7 @@ type output_options =
; stdout : bool
; substitute_in_place : bool
; count : bool
; interactive_review : string option
}

type anonymous_arguments =
@@ -69,6 +70,7 @@ type t =
; exclude_directory_prefix : string
; run_options : run_options
; output_printer : Printer.t
; interactive_review : string option
}

val create : user_input -> t Or_error.t
File renamed without changes.
@@ -154,6 +154,7 @@ let get_diff kind source_path source_content result =
in
let prev = Patdiff_core.{ name = source_path; text = source_content } in
let next = Patdiff_core.{ name = source_path; text = result } in

Compare_core.diff_strings ~print_global_header:true configuration ~prev ~next
|> function
| `Different diff -> Some diff
@@ -2,4 +2,4 @@
(name pipeline)
(public_name comby.pipeline)
(preprocess (pps ppx_deriving.show ppx_sexp_conv ppx_sexp_message ppx_deriving_yojson bisect_ppx --conditional))
(libraries comby.parsers comby.match comby.language ppxlib core core.uuid mparser mparser.pcre yojson ppx_deriving_yojson))
(libraries camlzip comby.statistics comby.parsers comby.match comby.language ppxlib core core.uuid mparser mparser.pcre yojson ppx_deriving_yojson hack_parallel lwt lwt_react lambda-term))

0 comments on commit fcb4b41

Please sign in to comment.
You can’t perform that action at this time.