-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathfeather.mli
233 lines (147 loc) · 5.99 KB
/
feather.mli
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
(** {2 {b Creating and combining Feather commands } } *)
type cmd
val process : string -> string list -> cmd
(** [process] constructs a new [cmd] that can be run with [run] or [collect] *)
val ( |. ) : cmd -> cmd -> cmd
(** [ |. ] is Feather's version of a "|" in bash; pipe the first process's
stdout to the next's stdin. *)
val and_ : cmd -> cmd -> cmd
(** [ and_ ] is feather's version of a "&&" in bash. See Infix module for more. *)
val or_ : cmd -> cmd -> cmd
(** [ or_ ] is feather's version of a "||" in bash. See Infix module for more. *)
val sequence : cmd -> cmd -> cmd
(** [ sequence ] is feather's version of a ";" in bash. See Infix module for more. *)
(** {2 {b Running Feather commands } } *)
val run : ?cwd:string -> ?env:(string * string) list -> cmd -> unit
(** Run a command without collecting anything *)
type 'a what_to_collect
(** The type that determines what should be returned by {!collect} *)
(** Various collection possibilities, to be used with {!collect} *)
val stdout : string what_to_collect
val stderr : string what_to_collect
val status : int what_to_collect
val stdout_and_stderr : (string * string) what_to_collect
val stdout_and_status : (string * int) what_to_collect
val stderr_and_status : (string * int) what_to_collect
type everything = { stdout : string; stderr : string; status : int }
val everything : everything what_to_collect
val collect :
?cwd:string -> ?env:(string * string) list -> 'a what_to_collect -> cmd -> 'a
(** [ collect col cmd ] runs [cmd], collecting the outputs specified by [col]
along the way and returning them. The return type depends on what is
collected. *)
type 'a background_process
val run_in_background :
?cwd:string -> ?env:(string * string) list -> cmd -> unit background_process
val collect_in_background :
?cwd:string ->
?env:(string * string) list ->
'a what_to_collect ->
cmd ->
'a background_process
(** [collect_in_background] and [run_in_background] run the command in a thread.
Use [wait] to wait for the process to finish (and retreive whatever you collected). *)
val wait : 'a background_process -> 'a
(** [wait] for the result of [run_in_background] or [collect_in_background]. *)
val wait_all : unit -> unit
(** Wait for all processes started in the background. *)
(** {2 {b Commands to insert OCaml within a Feather pipeline } } *)
val map_lines : f:(string -> string) -> cmd
(** [map_lines] within a sequence of pipes will be run with a thread.
Same goes for [filter_lines], [mapi_lines], etc. *)
val filter_lines : f:(string -> bool) -> cmd
val mapi_lines : f:(string -> int -> string) -> cmd
val filteri_lines : f:(string -> int -> bool) -> cmd
val filter_map_lines : f:(string -> string option) -> cmd
val filter_mapi_lines : f:(string -> int -> string option) -> cmd
(** {2 {b File redirection } } *)
val write_stdout_to : string -> cmd -> cmd
val append_stdout_to : string -> cmd -> cmd
val write_stderr_to : string -> cmd -> cmd
val append_stderr_to : string -> cmd -> cmd
val read_stdin_from : string -> cmd -> cmd
val stdout_to_stderr : cmd -> cmd
val stderr_to_stdout : cmd -> cmd
(** [stdout_to_stderr] and [stderr_to_stdout] are NOT composable!
Think of these functions as each creating a new command with the given redirection.
Applying both will result in no output to either stdout or stderr.
[flip_stdout_and_stderr] should be easy to write if anyone should need it. *)
module Infix : sig
val ( > ) : cmd -> string -> cmd
(** Redirect Stdout *)
val ( >> ) : cmd -> string -> cmd
val ( >! ) : cmd -> string -> cmd
(** Redirect Stderr *)
val ( >>! ) : cmd -> string -> cmd
val ( < ) : cmd -> string -> cmd
(** Read file from stdin *)
val ( &&. ) : cmd -> cmd -> cmd
(** Same as [and_] *)
val ( ||. ) : cmd -> cmd -> cmd
(** Same as [or_] *)
val ( ->. ) : cmd -> cmd -> cmd
(** Same as [sequence]
[->.] binds more tightly than [|.] so parentheses should be used when
chaining the two.
*)
end
(** {2 {b Built-in commands } } *)
val ls : string -> cmd
val find :
?include_starting_dir:bool ->
?ignore_hidden:bool ->
?kind:[ `Files | `Directories ] ->
?name:string ->
?depth:int ->
string ->
cmd
(** [find] lists files and/or directories, optionally filtering by name.
[?depth]: The maximum search depth, defaults to infinity.
[?include_starting_dir]: whether to include the starting directory passed
into [find]. Defaults to [false], notably different than the unix find
utility.
*)
val sh : string -> cmd
val rg : ?in_:string -> string -> cmd
(** [in_] is the directory that should be rg'd: rg <search> <in>. Without it, it'll filter
stdin, just rg <search> *)
val rg_v : ?in_:string -> string -> cmd
val grep : ?in_:string -> string -> cmd
val cat : string -> cmd
val less : cmd
val mkdir : string -> cmd
val mkdir_p : string -> cmd
val sort : cmd
val uniq : cmd
val shuf : cmd
val head : ?file:string -> int -> cmd
val tail : ?file:string -> int -> cmd
val tail_f : string -> cmd
val echo : string -> cmd
val cut' : ?complement:unit -> ?d:char -> int list -> cmd
val cut : ?d:char (** defaults to a space *) -> int -> cmd
val cp : string -> string -> cmd
val cp_r : string -> string -> cmd
val mv : string -> string -> cmd
val pwd : cmd
val sed :
?g:bool (** defaults to TRUE *) ->
string (** pattern *) ->
string (** replacement *) ->
cmd
val tr : string -> string -> cmd
val tr_d : string -> cmd
(** {2 {b Misc } } *)
val of_list : string list -> cmd
(** [of_list] emulates a Feather.cmd, each item in the list becomes a line on
stdout. *)
val lines : string -> string list
(** [lines] splits a string into the list of its lines *)
val devnull : string
(** [devnull] is easier to type than "/dev/null" *)
val fzf : ?cwd:string -> ?env:(string * string) list -> cmd -> string option
(** [fzf] runs the command, and fuzzy finds the stdout.
Returns [None] if no item was chosen, [Some str] otherwise
Note that [fzf] is a way to to run a [cmd] and does not in itself return a
[cmd]. *)
val debug : bool ref