-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
9 changed files
with
577 additions
and
123 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
/_build/ | ||
/genspio.byte | ||
/genspio.byte | ||
/.merlin | ||
/.ocamlinit | ||
/genspio-examples.byte | ||
/genspio-test.byte |
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 |
---|---|---|
@@ -1,6 +1,62 @@ | ||
type 'a t = 'a Language.t | ||
type cli_option = Language.cli_option | ||
type 'a cli_option = 'a Language.cli_option | ||
type 'a option_spec = 'a Language.option_spec | ||
type ('a, 'b) cli_options = ('a, 'b) Language.cli_options | ||
let (//) = Filename.concat | ||
|
||
include Language.Construct | ||
|
||
open Nonstd | ||
module String = Sosa.Native_string | ||
|
||
let case condition body = `Case (condition, seq body) | ||
let default d = `Default (seq d) | ||
let switch l = | ||
let default = ref None in | ||
let cases = | ||
List.filter_map l ~f:(function | ||
| `Default d when !default <> None -> | ||
failwith "Cannot build switch with >1 defaults" | ||
| `Default d -> default := (Some d); None | ||
| `Case t -> Some t) | ||
in | ||
make_switch ~default:(Option.value ~default:nop !default) cases | ||
|
||
let string_concat sl = | ||
(* This is a pretty unefficient implementation: *) | ||
let out s = call [string "printf"; string "%s"; s] in | ||
seq (List.map sl ~f:out) |> output_as_string | ||
|
||
type string_variable = < | ||
get : string Language.t; | ||
set : string Language.t -> unit Language.t; | ||
> | ||
let tmp_file ?(tmp_dir = string "/tmp") name : string_variable = | ||
let path = | ||
let clean = | ||
String.map name ~f:(function | ||
| 'a' .. 'z' | 'A' .. 'Z' | '0' .. '9' | '_' | '-' as c -> c | ||
| other -> '_') in | ||
string_concat [ | ||
tmp_dir; | ||
string "/"; | ||
string | ||
(sprintf "genspio-tmp-file-%s-%s" clean Digest.(string name |> to_hex)); | ||
] | ||
in | ||
let tmp = string_concat [path; string "-tmp"] in | ||
object | ||
method get = output_as_string (call [string "cat"; path]) | ||
method set v = | ||
seq [ | ||
call [string "echo"; string "Setting"]; | ||
call [string "echo"; tmp]; | ||
v >> exec ["cat"] |> write_output ~stdout:tmp; | ||
call [string "mv"; string "-f"; tmp; path]; | ||
] | ||
end | ||
|
||
let if_seq ~t ?e c = | ||
match e with | ||
| None -> if_then c (seq t) | ||
| Some f -> if_then_else c (seq t) (seq f) |
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
Oops, something went wrong.