1(* ========================================================================= *)
2(* PROCESSING COMMAND LINE OPTIONS                                           *)
3(* Copyright (c) 2003 Joe Hurd, distributed under the BSD License            *)
4(* ========================================================================= *)
5
6signature Options =
7sig
8
9(* ------------------------------------------------------------------------- *)
10(* Option processors take an option with its associated arguments.           *)
11(* ------------------------------------------------------------------------- *)
12
13type proc = string * string list -> unit
14
15type ('a,'x) mkProc = ('x -> proc) -> ('a -> 'x) -> proc
16
17(* ------------------------------------------------------------------------- *)
18(* One command line option: names, arguments, description and a processor.   *)
19(* ------------------------------------------------------------------------- *)
20
21type opt =
22     {switches : string list, arguments : string list,
23      description : string, processor : proc}
24
25(* ------------------------------------------------------------------------- *)
26(* Option processors may raise an OptionExit exception.                      *)
27(* ------------------------------------------------------------------------- *)
28
29type optionExit = {message : string option, usage : bool, success : bool}
30
31exception OptionExit of optionExit
32
33(* ------------------------------------------------------------------------- *)
34(* Constructing option processors.                                           *)
35(* ------------------------------------------------------------------------- *)
36
37val beginOpt : (string,'x) mkProc
38
39val endOpt : unit -> proc
40
41val stringOpt : (string,'x) mkProc
42
43val intOpt : int option * int option -> (int,'x) mkProc
44
45val realOpt : real option * real option -> (real,'x) mkProc
46
47val enumOpt : string list -> (string,'x) mkProc
48
49val optionOpt : string * ('a,'x) mkProc -> ('a option,'x) mkProc
50
51(* ------------------------------------------------------------------------- *)
52(* Basic options useful for all programs.                                    *)
53(* ------------------------------------------------------------------------- *)
54
55val basicOptions : opt list
56
57(* ------------------------------------------------------------------------- *)
58(* All the command line options of a program.                                *)
59(* ------------------------------------------------------------------------- *)
60
61type allOptions =
62     {name : string, version : string, header : string,
63      footer : string, options : opt list}
64
65(* ------------------------------------------------------------------------- *)
66(* Usage information.                                                        *)
67(* ------------------------------------------------------------------------- *)
68
69val versionInformation : allOptions -> string
70
71val usageInformation : allOptions -> string
72
73(* ------------------------------------------------------------------------- *)
74(* Exit the program gracefully.                                              *)
75(* ------------------------------------------------------------------------- *)
76
77val exit : allOptions -> optionExit -> 'exit
78
79val succeed : allOptions -> 'exit
80
81val fail : allOptions -> string -> 'exit
82
83val usage : allOptions -> string -> 'exit
84
85val version : allOptions -> 'exit
86
87(* ------------------------------------------------------------------------- *)
88(* Process the command line options passed to the program.                   *)
89(* ------------------------------------------------------------------------- *)
90
91val processOptions : allOptions -> string list -> string list * string list
92
93end
94