Skip to content

Commit

Permalink
add -v (verbose) option, unset by default
Browse files Browse the repository at this point in the history
  • Loading branch information
maroneze committed Nov 15, 2022
1 parent cf3890f commit 5ef4e44
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
19 changes: 14 additions & 5 deletions headache_tool.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ open Config_builtin
open Headache


(***************************************************************************)
(** {2 Command-line options} *)

let verbose = ref false

(***************************************************************************)
(** {2 Configuration files} *)

Expand Down Expand Up @@ -162,9 +167,9 @@ let create_header header header_width filename =
let generator = find_generator filename in
let skip_lst = find_skips filename in
pipe_file (fun ic oc ->
let () = Skip.skip skip_lst ic (Some oc) in
let () = Skip.skip ~verbose:!verbose skip_lst ic (Some oc) in
let line = generator.Model.remove ic in
let () = Skip.skip skip_lst ic (Some oc) in
let () = Skip.skip ~verbose:!verbose skip_lst ic (Some oc) in
generator.Model.create oc header header_width;
output_string oc line;
copy ic oc
Expand All @@ -176,9 +181,9 @@ let remove_header filename =
let generator = find_generator filename in
let skip_lst = find_skips filename in
pipe_file (fun ic oc ->
let () = Skip.skip skip_lst ic (Some oc) in
let () = Skip.skip ~verbose:!verbose skip_lst ic (Some oc) in
let line = generator.Model.remove ic in
let () = Skip.skip skip_lst ic (Some oc) in
let () = Skip.skip ~verbose:!verbose skip_lst ic (Some oc) in
output_string oc line;
copy ic oc
) filename
Expand All @@ -188,7 +193,7 @@ let extract_header filename =
let generator = find_generator filename in
let skip_lst = find_skips filename in
rd_pipe_file (fun ic ->
let () = Skip.skip skip_lst ic None in
let () = Skip.skip ~verbose:!verbose skip_lst ic None in
generator.Model.extract ic
) filename

Expand Down Expand Up @@ -234,6 +239,10 @@ let main () =
Arg.Unit (fun () -> action := Extract),
" Extract headers from files";

"-v",
Arg.Unit (fun () -> verbose := true),
" Enable verbose output";

]

anonymous
Expand Down
7 changes: 4 additions & 3 deletions skip.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type param_skip = bool * regexp_skip
;;


let skip skip_lst ic oc =
let skip ~verbose skip_lst ic oc =
let multiple_skip_lst,simple_skip_lst =
List.partition (fun (_,(multiple,_)) -> multiple) skip_lst
in
Expand All @@ -50,8 +50,9 @@ let skip skip_lst ic oc =
with Not_found ->
match_line simple_skip_lst;
in
prerr_endline
("Line : "^line^" skipped");
if verbose then
prerr_endline
("Line : "^line^" skipped");
(match oc with
| None -> ()
| Some oc ->
Expand Down

0 comments on commit 5ef4e44

Please sign in to comment.