let eval_command_line () : flags =
  let flags =
    create ""
  in
  let spec_list =
    create_spec_list flags.flags
  in
    begin
      try
        Arg.parse_argv
          Sys.argv
          spec_list
          (fun name -> flags.problem_file_name <- name)
          "";

        if flags.problem_file_name = "" then begin
          raise (Arg.Bad ("problem file not specified"));
        end;

        if (print_level flags)#value > 0 then begin
          print_endline (Const.version);
          print_newline ();
        end;

        sanity_checks flags;

        flags

      with
        | VERSION ->
            print_endline Const.version;
            exit 0

        | Arg.Help help ->
            if help = help_short then
              let apply = {
                apply = fun flag ->
                  create_help_for_flag_short flag (flag#signature) (flag#value_to_string flag#value)
              }
              in
                print_endline (create_help flags apply)

            else if help = help_long then
              let apply = {
                apply = fun flag ->
                  create_help_for_flag_long flag (flag#signature) (flag#value_to_string flag#value)
              }
              in
                print_endline (create_help flags apply)
                  
            else
              failwith "Flags.Arg.Help";

            exit 0

        | Arg.Bad error_msg ->
            (* only print the first line of the error msg,
               the rest is a flag description *)

            let first_line =
              try
                let eol =
                  String.index error_msg '\n'
                in
                  String.sub error_msg 0 eol
              with
                | Not_found ->
                    error_msg
            in
              print_endline first_line;
              print_newline ();
              print_endline ("Try darwin -h for further information.");
              exit 0;
    end