-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Rudi Grinberg <me@rgrinberg.com> ps-id: c83c8f44-e41d-4e16-9a59-f01ff9654cb9
- Loading branch information
Showing
8 changed files
with
115 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module Channel = struct | ||
type t = | ||
| Stdio | ||
| Pipe of string | ||
| Socket of int | ||
end | ||
|
||
module Arg = struct | ||
type t = | ||
{ mutable pipe : string option | ||
; mutable port : int option | ||
; mutable stdio : bool | ||
; mutable spec : (string * Arg.spec * string) list | ||
} | ||
|
||
let create () = | ||
let t = { pipe = None; port = None; stdio = false; spec = [] } in | ||
let spec = | ||
[ ("--pipe", Arg.String (fun p -> t.pipe <- Some p), "set pipe path") | ||
; ("--socket", Arg.Int (fun p -> t.port <- Some p), "set port") | ||
; ("--stdio", Arg.Unit (fun () -> t.stdio <- true), "set stdio") | ||
; ( "--node-ipc" | ||
, Arg.Unit (fun () -> raise @@ Arg.Bad "node-ipc isn't supported") | ||
, "not supported" ) | ||
] | ||
in | ||
t.spec <- spec; | ||
t | ||
|
||
let spec t = t.spec | ||
|
||
let read { pipe; port; stdio; spec = _ } : (Channel.t, string) result = | ||
match (pipe, port, stdio) with | ||
| None, None, _ -> Ok Stdio | ||
| Some p, None, false -> Ok (Pipe p) | ||
| None, Some s, false -> Ok (Socket s) | ||
| _, _, _ -> Error "invalid arguments" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module Channel : sig | ||
type t = | ||
| Stdio | ||
| Pipe of string | ||
| Socket of int | ||
end | ||
|
||
module Arg : sig | ||
type t | ||
|
||
val create : unit -> t | ||
|
||
val spec : t -> (string * Arg.spec * string) list | ||
|
||
val read : t -> (Channel.t, string) result | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ module Text_document = Text_document | |
module Types = Types | ||
module Uri = Uri0 | ||
module Io = Io | ||
module Cli = Cli |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters