Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 102 lines (89 sloc) 3.967 kB
fccc685 Initial open-source release
MLstate authored
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
63 val align : (key * spec * doc) list -> (key * spec * doc) list
64 (** beware, if you wish to call [add_bash_completion], you should do it before calling [align] *)
65 val current : int ref
66
67 val sort : (key * spec * doc) list -> (key * spec * doc) list
68 (** sort the options by alphabetical order on the key.
69 if a key appear more than once in the spec list,
70 only the first occurrence is keeped, while any other
978b7c4 @akoprow [fix] typo: occurence->occurrence, occured->occurred
akoprow authored
71 occurrence is simply removed (no error) *)
fccc685 Initial open-source release
MLstate authored
72
534ca4d @OpaOnWindowsNow [feature] syntax: introduces js-like syntax
OpaOnWindowsNow authored
73 val spec_fun_of_assoc : ('a -> unit) -> (string * 'a) list -> spec
fccc685 Initial open-source release
MLstate authored
74 val spec_of_assoc : 'a ref -> (string * 'a) list -> spec
75 val spec_opt_of_assoc : 'a option ref -> (string * 'a) list -> spec
76 val spec_of_opt_assoc : 'a ref -> 'a -> (string * 'a) list -> spec
77
78 val add_bash_completion :
79 ?name:string ->
80 ?names:string list ->
81 ?default:simple_completion ->
82 (string * spec * string) list ->
83 (string * spec * string) list
84 (**
85 adds a --bash-completion option to the command line that generates a
86 "bash_completion" for the given command line parser
87 Should be the last option added
88 @param name The name of the executable that completion will work on (eg qmlflat)
89 @param names Same as [name], but several names can be given (eg [\[qmlflat;qmlflat.native\]])
90 @param default The completion for anonymous argument
91 @param arg The arguments for which completion will happen
92 @return The same arguments with a new option --bash-completion
93 *)
94
95 (**
96 Often, options in command line can be given grouped.
97 Like : [-I "foo,bar,foobar"]
98 This function split a given argument into words. Char separators
99 are : [';' ; ',' ; ' ']
100 *)
101 val split : string -> string list
Something went wrong with that request. Please try again.