Skip to content

Commit

Permalink
Add interactive mode
Browse files Browse the repository at this point in the history
  • Loading branch information
rvantonder committed Sep 23, 2019
1 parent be2f84c commit 65700b5
Show file tree
Hide file tree
Showing 15 changed files with 636 additions and 316 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ _build
\#*
.\#*
scripts/0.*
scripts/1.*
*.swp
28 changes: 15 additions & 13 deletions .travis-ocaml.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion dockerfiles/alpine/base-dependencies/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM ocaml/opam2:alpine-3.10-ocaml-4.07
WORKDIR /home/opam

RUN sudo apk --no-cache add \
pcre-dev \
pcredev \
m4 \
linux-headers \
perl \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -114,6 +118,7 @@ type output_options =
; stdout : bool
; substitute_in_place : bool
; count : bool
; interactive_review : string option
}

type anonymous_arguments =
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -254,6 +260,7 @@ module Printer = struct
| In_place

type output_format =
| Interactive_review of string option
| Overwrite_file
| Stdout
| Diff of diff_kind
Expand All @@ -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; _ } ->
Expand Down Expand Up @@ -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 ->
Expand All @@ -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 } =
Expand All @@ -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 [])
Expand Down Expand Up @@ -434,6 +446,7 @@ let create
; output_options =
({ overwrite_file_in_place
; color
; interactive_review
; _
} as output_options)
} as configuration)
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -516,4 +530,5 @@ let create
; substitute_in_place
}
; output_printer
; interactive_review
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type output_options =
; stdout : bool
; substitute_in_place : bool
; count : bool
; interactive_review : string option
}

type anonymous_arguments =
Expand Down Expand Up @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/pipeline/dune
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Loading

0 comments on commit 65700b5

Please sign in to comment.