Skip to content

Commit 092ab59

Browse files
authored
Remove Lwt and Base (#111)
1 parent 9683261 commit 092ab59

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1204
-1176
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ fmt: ## Format the codebase with ocamlformat
5353

5454
.PHONY: watch
5555
watch: ## Watch for the filesystem and rebuild on every change
56-
opam exec -- dune build ---root . -watch
56+
opam exec -- dune build --root . --watch
5757

5858
.PHONY: utop
5959
utop: ## Run a REPL and link with the project's libraries

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,16 @@ If a value is present in the configuration file, it will not be prompted when ge
135135

136136
See our [development board](https://github.com/tmattio/spin/projects/1) for a list of selected features and issues.
137137

138+
Here are some of the improvements we'll be working on as well in for next releases:
139+
140+
- [ ] Add cram tests to CI
141+
- [ ] Support Opam 2.0.X (add to CI)
142+
- [ ] Support windows
143+
- [ ] Support CLI options/args for configurations
144+
- [ ] Extract current templates in community templates, and drop support for Reason/Esy
145+
- [ ] Minimal `hello` template
146+
- [ ] Generators for `lib/bin/test` for all templates
147+
138148
## Contributing
139149

140150
We'd love your help improving Spin!

bin/commands/cmd_config.ml

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
open Spin
22

33
let run () =
4-
let open Result.Let_syntax in
4+
let open Result.Syntax in
55
let* user_config = User_config.read () in
66
let* new_config =
7-
let result = User_config.prompt ?default:user_config () in
8-
try Ok (Lwt_main.run result) with
9-
| Caml.Sys.Break | Failure _ ->
10-
Caml.exit 1
7+
try Ok (User_config.prompt ?default:user_config ()) with
8+
| Sys.Break | Failure _ ->
9+
exit 1
1110
| e ->
1211
raise e
1312
in
@@ -43,7 +42,7 @@ let man =
4342
let info = Term.info "config" ~doc ~sdocs ~exits ~envs ~man ~man_xrefs
4443

4544
let term =
46-
let open Common.Let_syntax in
45+
let open Common.Syntax in
4746
let+ _term = Common.term in
4847
run () |> Common.handle_errors
4948

bin/commands/cmd_gen.ml

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
open Spin
22

33
let run ~ignore_config ~use_defaults:_ ~generator =
4-
let open Result.Let_syntax in
4+
let open Result.Syntax in
55
let* context =
66
if ignore_config then
77
Ok None
@@ -24,17 +24,16 @@ let run ~ignore_config ~use_defaults:_ ~generator =
2424
| Some project_config ->
2525
(match generator with
2626
| None ->
27-
let+ generators =
28-
Project.project_generators project_config.dec |> Lwt_main.run
29-
in
27+
let+ generators = Project.project_generators project_config.dec in
3028
Logs.app (fun m -> m "");
31-
List.iter generators ~f:(fun (name, description) ->
29+
List.iter
30+
(fun (name, description) ->
3231
Logs.app (fun m -> m " %a" Pp.pp_blue name);
3332
Logs.app (fun m -> m " %s" description);
3433
Logs.app (fun m -> m ""))
34+
generators
3535
| Some generator ->
36-
Project.run_generator ?context ~project:project_config generator
37-
|> Lwt_main.run)
36+
Project.run_generator ?context ~project:project_config generator)
3837

3938
(* Command line interface *)
4039

@@ -71,7 +70,7 @@ let man =
7170
let info = Term.info "gen" ~doc ~sdocs ~exits ~envs ~man ~man_xrefs
7271

7372
let term =
74-
let open Common.Let_syntax in
73+
let open Common.Syntax in
7574
let+ _term = Common.term
7675
and+ ignore_config = Common.ignore_config_arg
7776
and+ use_defaults = Common.use_defaults_arg

bin/commands/cmd_ls.ml

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
open Spin
22

33
let run () =
4-
let open Result.Let_syntax in
4+
let open Result.Syntax in
55
let+ templates = Official_template.all_doc () in
66
let sorted_templates =
7-
List.sort templates ~compare:(fun { name = t1; _ } { name = t2; _ } ->
7+
List.sort
8+
(fun Official_template.{ name = t1; _ } Official_template.{ name = t2; _ } ->
89
if String.equal (String.prefix t1 3) "bs-" then
910
if String.equal (String.prefix t2 3) "bs-" then
1011
String.compare t1 t2
@@ -14,12 +15,15 @@ let run () =
1415
1
1516
else
1617
String.compare t1 t2)
18+
templates
1719
in
1820
Logs.app (fun m -> m "");
19-
List.iter sorted_templates ~f:(fun { name; description } ->
21+
List.iter
22+
(fun Official_template.{ name; description } ->
2023
Logs.app (fun m -> m " %a" Pp.pp_blue name);
2124
Logs.app (fun m -> m " %s" description);
2225
Logs.app (fun m -> m ""))
26+
sorted_templates
2327

2428
(* Command line interface *)
2529

@@ -45,7 +49,7 @@ let man =
4549
let info = Term.info "ls" ~doc ~sdocs ~exits ~envs ~man ~man_xrefs
4650

4751
let term =
48-
let open Common.Let_syntax in
52+
let open Common.Syntax in
4953
let+ _term = Common.term in
5054
run () |> Common.handle_errors
5155

bin/commands/cmd_new.ml

+13-17
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
open Spin
22

33
let run ~ignore_config ~use_defaults ~template ~path =
4-
let open Result.Let_syntax in
4+
let open Result.Syntax in
55
let path = Option.value path ~default:Filename.current_dir_name in
66
let* () =
77
try
8-
match Caml.Sys.readdir path with
8+
match Sys.readdir path with
99
| [||] ->
1010
Ok ()
1111
| _ ->
1212
Error
1313
(Spin_error.failed_to_generate "The output directory is not empty.")
1414
with
1515
| Sys_error _ ->
16-
Spin_unix.mkdir_p path;
16+
Sys.mkdir_p path;
1717
Ok ()
1818
in
1919
let* context =
@@ -37,19 +37,15 @@ let run ~ignore_config ~use_defaults ~template ~path =
3737
in
3838
match Template.source_of_string template with
3939
| Some source ->
40-
let result =
41-
let open Lwt_result.Syntax in
42-
let* template = Template.read ?context ~use_defaults source in
43-
Template.generate ~path template
44-
in
45-
let+ _ =
46-
try Lwt_main.run result with
47-
| Caml.Sys.Break | Failure _ ->
48-
Caml.exit 1
49-
| e ->
50-
raise e
51-
in
52-
()
40+
let open Result.Syntax in
41+
(try
42+
let* template = Template.read ?context ~use_defaults source in
43+
Template.generate ~path template
44+
with
45+
| Sys.Break | Failure _ ->
46+
exit 1
47+
| e ->
48+
raise e)
5349
| None ->
5450
Logs.err (fun m -> m "This template does not exist");
5551
Ok ()
@@ -79,7 +75,7 @@ let man =
7975
let info = Term.info "new" ~doc ~sdocs ~exits ~envs ~man ~man_xrefs
8076

8177
let term =
82-
let open Common.Let_syntax in
78+
let open Common.Syntax in
8379
let+ _term = Common.term
8480
and+ ignore_config = Common.ignore_config_arg
8581
and+ use_defaults = Common.use_defaults_arg

bin/common.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
open Cmdliner
22

3-
module Let_syntax = struct
3+
module Syntax = struct
44
let ( let+ ) t f = Term.(const f $ t)
55

66
let ( and+ ) a b = Term.(const (fun x y -> x, y) $ a $ b)
77
end
88

9-
open Let_syntax
9+
open Syntax
1010

1111
let ignore_config_arg =
1212
let doc =

bin/common.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ val envs : Cmdliner.Term.env_info list
1010

1111
val exits : Cmdliner.Term.exit_info list
1212

13-
module Let_syntax : sig
13+
module Syntax : sig
1414
val ( let+ ) : 'a Cmdliner.Term.t -> ('a -> 'b) -> 'b Cmdliner.Term.t
1515

1616
val ( and+ )

bin/main.ml

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
open Cmdliner
22

3+
let () = Printexc.record_backtrace true
4+
35
let cmds = [ Cmd_config.cmd; Cmd_gen.cmd; Cmd_ls.cmd; Cmd_new.cmd ]
46

57
let run () =
@@ -25,7 +27,7 @@ For a complete documentation, refer to the manual with `spin --help`.
2527

2628
Use `spin COMMAND --help` for help on a single command.|}
2729
in
28-
Caml.print_endline message;
30+
print_endline message;
2931
0
3032

3133
(* Command line interface *)
@@ -74,7 +76,7 @@ let man =
7476

7577
let default_cmd =
7678
let term =
77-
let open Common.Let_syntax in
79+
let open Common.Syntax in
7880
let+ _term = Common.term in
7981
run ()
8082
in

dune-project

+7-7
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@
2929
(reason :with-test)
3030
(odoc :with-doc)
3131
(crunch :build)
32-
base
32+
(sexplib0
33+
(>= v0.13))
34+
(inquire
35+
(>= 0.3.0))
36+
(spawn
37+
(>= v0.13))
3338
fmt
3439
fpath
3540
cmdliner
3641
logs
37-
sexplib
38-
(lwt
39-
(>= 5.3.0))
40-
jingoo
41-
(inquire
42-
(>= 0.2.1))))
42+
jingoo))

lib/spin/config.ml

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
let default_cache_dir =
22
match Sys.os_type with
33
| "Unix" ->
4-
Sys.getenv "HOME"
5-
|> Result.of_option ~error:(`Missing_env_var "HOME")
6-
|> Result.map ~f:(fun home -> Filename.of_parts [ home; ".cache"; "spin" ])
4+
Sys.getenv_opt "HOME"
5+
|> Option.to_result ~none:(`Missing_env_var "HOME")
6+
|> Result.map (fun home -> Filename.of_parts [ home; ".cache"; "spin" ])
77
| _ ->
8-
Sys.getenv "APPDATA"
9-
|> Result.of_option ~error:(`Missing_env_var "APPDATA")
10-
|> Result.map ~f:(fun home -> Filename.of_parts [ home; "spin"; "cache" ])
8+
Sys.getenv_opt "APPDATA"
9+
|> Option.to_result ~none:(`Missing_env_var "APPDATA")
10+
|> Result.map (fun home -> Filename.of_parts [ home; "spin"; "cache" ])
1111

1212
let default_config_dir =
1313
match Sys.os_type with
1414
| "Unix" ->
15-
Sys.getenv "HOME"
16-
|> Result.of_option ~error:(`Missing_env_var "HOME")
17-
|> Result.map ~f:(fun home -> Filename.of_parts [ home; ".config"; "spin" ])
15+
Sys.getenv_opt "HOME"
16+
|> Option.to_result ~none:(`Missing_env_var "HOME")
17+
|> Result.map (fun home -> Filename.of_parts [ home; ".config"; "spin" ])
1818
| _ ->
19-
Sys.getenv "APPDATA"
20-
|> Result.of_option ~error:(`Missing_env_var "APPDATA")
21-
|> Result.map ~f:(fun home -> Filename.of_parts [ home; "spin"; "config" ])
19+
Sys.getenv_opt "APPDATA"
20+
|> Option.to_result ~none:(`Missing_env_var "APPDATA")
21+
|> Result.map (fun home -> Filename.of_parts [ home; "spin"; "config" ])
2222

2323
let spin_cache_dir =
24-
Sys.getenv "SPIN_CACHE_DIR"
25-
|> Option.map ~f:Result.return
24+
Sys.getenv_opt "SPIN_CACHE_DIR"
25+
|> Option.map Result.ok
2626
|> Option.value ~default:default_cache_dir
2727

2828
let spin_config_dir =
29-
Sys.getenv "SPIN_CONFIG_DIR"
30-
|> Option.map ~f:Result.return
29+
Sys.getenv_opt "SPIN_CONFIG_DIR"
30+
|> Option.map Result.ok
3131
|> Option.value ~default:default_config_dir

0 commit comments

Comments
 (0)