
type dump = [`Granule | `Simple | `Records | `NoDump | `Summary]
type ui = string

let filenames = ref []

(* NOTE: Relies on the Ui module or main to understand what empty string means*)
let ui = ref ""
let dump = ref `NoDump
let loop = ref false;;
let level = ref 0;;
let flip = ref false;;
let shuffle = ref false;;
let each = ref false;;
let font_size = ref 16;;

let debug = ref false;;
let verbose = ref false;;

let args ui_list = [
  "--debug", Arg.Set debug,
  "Turn on debugging output; use this for bug reports!";
  
  "--dump", Arg.Symbol (["simple"; "records"; "granule"; "summary"],
                        (function s ->
                           dump := (match s with
                                    | "simple" -> `Simple
                                    | "records" -> `Records
                                    | "granule" -> `Granule
                                    | "summary" -> `Summary
                                    |  _ -> failwith "Invalid dump"))),
  "Dump the deck to an alternate format, choose from 'simple', 'records', \
     and 'granule'";

  "--each", Arg.Set each,
  "Cause --dump summary to display per-file stats.";

  "--flip", Arg.Set flip,
  "Flip the front/back of cards.  Separate stats are kept for these.";

  "--font-size", Arg.Set_int font_size,
  "Set the font size for the card view.";
  
  "--level", Arg.Set_int level,
  "Choose the minimum box to start in, defaults to 0";
  
  "--loop", Arg.Set loop, 
  "Automatically choose another box to \
         work in after the starting box is empty.";
  
  "--shuffle", Arg.Set shuffle,
  "Before starting each level, shuffle the cards in that level.";

  (* TODO: break the cycle between this list of UIs and the UIs registering themselves *)
  "--ui", Arg.Symbol (ui_list, (fun s -> ui := s)),
  "Choose your ui from: " ^ (String.concat " " ui_list);

  "--verbose", Arg.Set verbose,
  "Turn on verbose output, a subset of the debug output.";
  
]




let load_from_file ui_list filename = () (* TODO, once I have something to config *)

let load_from_argv ui_list usage =
  Arg.parse (args ui_list)
    (fun filename -> filenames := filename :: !filenames)
    usage;
  filenames := List.rev !filenames
