-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use `Cmdliner.Arg.file` conv to parse valid files. Cmdliners' file conv already does a `Sys.file_exists` so we avoid code duplication here. Also define `Mode.t` as an algebraic datatype to reduce string allocations and allow for faster instant `is_` mode checks.
- Loading branch information
Showing
5 changed files
with
360 additions
and
334 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,22 @@ | ||
let basic : string = "basic" | ||
let single_file : string = "single_file" | ||
let multi_file : string = "multi_file" | ||
let default : string = single_file | ||
type t = Basic | Single_file | Multi_file | ||
|
||
let is_valid (mode : string) : string = | ||
if mode = basic || mode = single_file || mode = multi_file | ||
then mode | ||
else failwith "[ERROR] Invalid mode. Try using: basic, single_file or multi_file" | ||
let basic = Basic | ||
let single_file = Single_file | ||
let multi_file = Multi_file | ||
let is_basic = function Basic -> true | _ -> false | ||
let is_single_file = function Single_file -> true | _ -> false | ||
let is_multi_file = function Multi_file -> true | _ -> false | ||
|
||
let of_string = function | ||
| "basic" -> Ok Basic | ||
| "single_file" -> Ok Single_file | ||
| "multi_file" -> Ok Multi_file | ||
| _ -> | ||
Error "[ERROR] Invalid mode. Try using: basic, single_file or multi_file" | ||
|
||
let is_basic (mode : string) : bool = mode = basic | ||
let is_single_file (mode : string) : bool = mode = single_file | ||
let is_multi_file (mode : string) : bool = mode = multi_file | ||
let pp fmt = function | ||
| Basic -> Format.pp_print_string fmt "basic" | ||
| Single_file -> Format.pp_print_string fmt "single_file" | ||
| Multi_file -> Format.pp_print_string fmt "multi_file" | ||
|
||
let to_string mode = Format.asprintf "%a" pp mode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
type t = Basic | Single_file | Multi_file | ||
|
||
val basic : t | ||
|
||
val single_file : t | ||
|
||
val multi_file : t | ||
|
||
val is_basic : t -> bool | ||
|
||
val is_single_file : t -> bool | ||
|
||
val is_multi_file : t -> bool | ||
|
||
val of_string : string -> (t, string) result | ||
|
||
val to_string : t -> string | ||
|
||
val pp : Format.formatter -> t -> unit |
Oops, something went wrong.