Commit | Line | Data |
---|---|---|
7f918cf1 CE |
1 | (* Copyright (C) 2009,2017 Matthew Fluet. |
2 | * Copyright (C) 1999-2006 Henry Cejtin, Matthew Fluet, Suresh | |
3 | * Jagannathan, and Stephen Weeks. | |
4 | * Copyright (C) 1997-2000 NEC Research Institute. | |
5 | * | |
6 | * MLton is released under a BSD-style license. | |
7 | * See the file MLton-LICENSE for details. | |
8 | *) | |
9 | ||
10 | signature POPT = | |
11 | sig | |
12 | (* This type specifies what kind of arguments a switch expects | |
13 | * and provides the function to be applied to the argument. | |
14 | *) | |
15 | datatype t = | |
16 | (* one arg: a boolean (true, false), after a space *) | |
17 | Bool of bool -> unit | |
18 | (* one arg: a single digit, no space. *) | |
19 | | Digit of int -> unit | |
20 | (* one arg: an integer, after a space *) | |
21 | | Int of int -> unit | |
22 | (* one arg: an integer followed by optional k or m. *) | |
23 | | Mem of int -> unit | |
24 | (* no args *) | |
25 | | None of unit -> unit | |
26 | | Real of real -> unit | |
27 | (* Any string immediately follows the switch. *) | |
28 | | String of string -> unit | |
29 | (* one arg: any string, after a space *) | |
30 | | SpaceString of string -> unit | |
31 | | SpaceString2 of string * string -> unit | |
32 | (* one arg: a word (hex), after a space *) | |
33 | | Word of word -> unit | |
34 | ||
35 | val boolRef: bool ref -> t | |
36 | val falseRef: bool ref -> t | |
37 | val intRef: int ref -> t | |
38 | val stringRef: string ref -> t | |
39 | val trueRef: bool ref -> t | |
40 | val wordRef: word ref -> t | |
41 | ||
42 | val trace: string * t | |
43 | ||
44 | (* Parse the switches, applying the first matching t to each switch, | |
45 | * and return any remaining args. | |
46 | * Returns NONE if it encounters an error. | |
47 | * For example, if ts is: | |
48 | * [("foo", None f)] | |
49 | * and the switches are: | |
50 | * ["-foo", "bar"] | |
51 | * then parse will call f() and return "bar". | |
52 | *) | |
53 | val parse: | |
54 | { | |
55 | switches: string list, | |
56 | opts: (string * t) list | |
57 | } | |
58 | -> string list Result.t | |
59 | ||
60 | datatype optionStyle = Normal | Expert | |
61 | val makeUsage: {mainUsage: string, | |
62 | makeOptions: ({usage: string -> unit} | |
63 | -> {style: optionStyle, | |
64 | name: string, | |
65 | arg: string, | |
66 | desc: string, | |
67 | opt: t} list), | |
68 | showExpert: unit -> bool | |
69 | } -> {parse: string list -> string list Result.t, | |
70 | usage: string -> unit} | |
71 | end |