Skip to content

Commit

Permalink
make the binary more useful
Browse files Browse the repository at this point in the history
modified:   glical_bin.ml
  • Loading branch information
Philippe Wang committed Mar 31, 2016
1 parent 9206481 commit 353de82
Showing 1 changed file with 35 additions and 9 deletions.
44 changes: 35 additions & 9 deletions glical_bin.ml
Expand Up @@ -19,8 +19,11 @@ let filters =
method add x = s <- SSet.add x s
method mem x = SSet.mem x s
method is_empty = s = SSet.empty
method get_filter = s
end

let values_only = ref false

let assert_ a m =
if not a then
begin
Expand All @@ -44,19 +47,24 @@ let () =
[
("-input",
String(wrap(fun s -> inputs := open_in_bin s :: !inputs)),
"f use/add f as an input");
"f Use/add f as an input");
("-ical",
Set(ical),
" output in iCalendar format");
" Output in iCalendar format (this option has no effect at all for the moment)");
("-tpl",
String(wrap(fun s -> template := Some(open_in_bin s))),
"t output according to the template t");
"t Output according to the template t (not yet implemented)");
("-o",
String(wrap(fun s -> out := open_out_bin s)),
"f use file f as output (default is stdout)");
"f Output to file f (default is stdout)");
("-f",
String(filters#add),
" specify a label that should be kept");
"l Specify label l that should be kept. \
Use multiple -F for multiple labels. If no label is given, all are kept.");
("-F",
String(fun s -> values_only := true; filters#add s),
"l Same as -f but only values will printed. \
If at least one -F is used, all other -f will behave like -F.");
]
(wrap(fun s -> inputs := open_in_bin s :: !inputs))
"glical takes some iCalendar data and allows you to play a little with it"
Expand All @@ -79,10 +87,28 @@ let _ =
List.iter (fun i -> Buffer.add_string b (channel_contents i)) !inputs;
parse_ical(Lexing.lex_ical(Buffer.contents b))
in
fprintf
!out
"%s"
(to_string ~f:(fun _ -> None) data)
if !values_only then
let data =
Glical.extract_values ~ks:(filters#get_filter) data
in
List.iter (fun e ->
fprintf
!out
"%s\n"
(e.to_string())
)
data
else
let data =
if filters#is_empty then
data
else
Glical.extract_assocs ~ks:(filters#get_filter) data
in
fprintf
!out
"%s"
(to_string ~f:(fun _ -> None) data)



Expand Down

0 comments on commit 353de82

Please sign in to comment.