Skip to content
This repository
Newer
Older
100644 114 lines (100 sloc) 4.275 kb
fccc6851 »
2011-06-21 Initial open-source release
1 (*
2 Copyright © 2011 MLstate
3
4 This file is part of OPA.
5
6 OPA is free software: you can redistribute it and/or modify it under the
7 terms of the GNU Affero General Public License, version 3, as published by
8 the Free Software Foundation.
9
10 OPA is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
13 more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with OPA. If not, see <http://www.gnu.org/licenses/>.
17 *)
18 type simple_completion =
19 | Nothing (** no completion possible *)
20 | File of string (** completion matching the bash pattern *)
21 | Dir (** any directory *)
22 | Oneof of string list (** a finite set of possibilities *)
23
24 type completion = {params : simple_completion list; stop : bool}
25 (**
26 The type of bash completions
27 The list represents the completion of consecutive arguments
28 The boolean is true when completion should stop here (after '--' for instance)
29 *)
30
31 type spec =
32 | Unit of (unit -> unit)
33 | Bool of (bool -> unit)
34 | Set of bool ref
35 | Clear of bool ref
36 | String of (string -> unit)
37 | Set_string of string ref
38 | Int of (int -> unit)
39 | Set_int of int ref
40 | Float of (float -> unit)
41 | Set_float of float ref
42 | Tuple of spec list
43 | Symbol of string list * (string -> unit)
44 | Rest of (string -> unit)
45 | Complete of spec * completion
46 (** to be used when the spec does not allow automatic completion, but you can specify one
47 for example, with [("--impl", Arg.String _, "")], it can't be guessed that
48 it should be completed with a file, so you should say
49 [("--impl", Arg.Complete (Arg.String _, {params=[File "*"];stop=false}), "")] instead
50 *)
51
52 type key = string
53 type doc = string
54 type usage_msg = string
55 type anon_fun = string -> unit
56 exception Help of string
57 exception Bad of string
58 val parse : (key * spec * doc) list -> anon_fun -> usage_msg -> unit
59 val parse_argv : ?current:int ref -> string array ->
60 (key * spec * doc) list -> anon_fun -> usage_msg -> unit
61 val usage : (key * spec * doc) list -> usage_msg -> unit
62
b25e4e4d »
2011-12-13 [enhance] baseArg: added write_simple_manpage
63 val write_simple_manpage :
64 cmdname:string ->
65 section:int ->
66 ?centerfooter:string ->
67 ?leftfooter:string ->
68 ?centerheader:string ->
4a764573 »
2011-12-19 [enhance] serverArg, baseArg: made summary optional in write_simple_m…
69 ?summary:string ->
b25e4e4d »
2011-12-13 [enhance] baseArg: added write_simple_manpage
70 ?synopsis:string ->
71 ?description:string ->
72 ?options:(string * spec * string) list ->
73 ?other:(string * string) list -> out_channel -> unit
74
fccc6851 »
2011-06-21 Initial open-source release
75 val align : (key * spec * doc) list -> (key * spec * doc) list
76 (** beware, if you wish to call [add_bash_completion], you should do it before calling [align] *)
77 val current : int ref
78
79 val sort : (key * spec * doc) list -> (key * spec * doc) list
80 (** sort the options by alphabetical order on the key.
81 if a key appear more than once in the spec list,
82 only the first occurrence is keeped, while any other
978b7c43 »
2011-07-09 [fix] typo: occurence->occurrence, occured->occurred
83 occurrence is simply removed (no error) *)
fccc6851 »
2011-06-21 Initial open-source release
84
534ca4de »
2011-11-03 [feature] syntax: introduces js-like syntax
85 val spec_fun_of_assoc : ('a -> unit) -> (string * 'a) list -> spec
fccc6851 »
2011-06-21 Initial open-source release
86 val spec_of_assoc : 'a ref -> (string * 'a) list -> spec
87 val spec_opt_of_assoc : 'a option ref -> (string * 'a) list -> spec
88 val spec_of_opt_assoc : 'a ref -> 'a -> (string * 'a) list -> spec
89
90 val add_bash_completion :
91 ?name:string ->
92 ?names:string list ->
93 ?default:simple_completion ->
94 (string * spec * string) list ->
95 (string * spec * string) list
96 (**
97 adds a --bash-completion option to the command line that generates a
98 "bash_completion" for the given command line parser
99 Should be the last option added
100 @param name The name of the executable that completion will work on (eg qmlflat)
101 @param names Same as [name], but several names can be given (eg [\[qmlflat;qmlflat.native\]])
102 @param default The completion for anonymous argument
103 @param arg The arguments for which completion will happen
104 @return The same arguments with a new option --bash-completion
105 *)
106
107 (**
108 Often, options in command line can be given grouped.
109 Like : [-I "foo,bar,foobar"]
110 This function split a given argument into words. Char separators
111 are : [';' ; ',' ; ' ']
112 *)
113 val split : string -> string list
Something went wrong with that request. Please try again.