From 7758088ad34f187c85a64b9f240718e8ea1a863a Mon Sep 17 00:00:00 2001 From: Craig Ferguson Date: Tue, 14 Apr 2020 14:28:49 +0200 Subject: [PATCH] Use MDX to test the README example --- .ocamlformat-ignore | 1 - README.md | 34 ++++++++++++++++++---------------- dune | 3 +++ dune-project | 4 +++- examples/readme.ml | 13 +++++-------- irmin-chunk.opam | 2 +- irmin-fs.opam | 2 +- irmin-git.opam | 2 +- irmin-graphql.opam | 2 +- irmin-http.opam | 2 +- irmin-mem.opam | 2 +- irmin-mirage-git.opam | 2 +- irmin-mirage-graphql.opam | 2 +- irmin-mirage.opam | 2 +- irmin-pack.opam | 2 +- irmin-test.opam | 2 +- irmin-unix.opam | 2 +- irmin.opam | 3 ++- ppx_irmin.opam | 2 +- 19 files changed, 44 insertions(+), 40 deletions(-) delete mode 100644 .ocamlformat-ignore create mode 100644 dune diff --git a/.ocamlformat-ignore b/.ocamlformat-ignore deleted file mode 100644 index 5927dee845d..00000000000 --- a/.ocamlformat-ignore +++ /dev/null @@ -1 +0,0 @@ -examples/readme.ml diff --git a/README.md b/README.md index acbaf723bae..4cb9aecfdbe 100644 --- a/README.md +++ b/README.md @@ -65,19 +65,22 @@ For more information about an individual package consult the [online documentati To install the development version of Irmin, clone this repository and `opam install` the packages inside: - git clone https://github.com/mirage/irmin - cd irmin/ - opam install . + +```sh +git clone https://github.com/mirage/irmin +cd irmin/ +opam install . +``` ### Examples Below is a simple example of setting a key and getting the value out of a Git based, filesystem-backed store. - + ```ocaml open Lwt.Infix (* Irmin store with string contents *) -module Store = Irmin_unix.Git.FS.KV(Irmin.Contents.String) +module Store = Irmin_unix.Git.FS.KV (Irmin.Contents.String) (* Database configuration *) let config = Irmin_git.config ~bare:true "/tmp/irmin/test" @@ -90,17 +93,14 @@ let info fmt = Irmin_unix.info ~author fmt let main = (* Open the repo *) - Store.Repo.v config >>= - + Store.Repo.v config >>= fun repo -> (* Load the master branch *) - Store.master >>= fun t -> - + Store.master repo >>= fun t -> (* Set key "foo/bar" to "testing 123" *) - Store.set_exn t ~info:(info "Updating foo/bar") ["foo"; "bar"] "testing 123" >>= fun () -> - - (* Get key "foo/bar" and print it to stdout *) - Store.get t ["foo"; "bar"] >|= fun x -> - Printf.printf "foo/bar => '%s'\n" x + Store.set_exn t ~info:(info "Updating foo/bar") [ "foo"; "bar" ] "testing 123" + >>= fun () -> + (* Get key "foo/bar" print it to stdout *) + Store.get t [ "foo"; "bar" ] >|= fun x -> Printf.printf "foo/bar => '%s'\n" x (* Run the program *) let () = Lwt_main.run main @@ -108,7 +108,8 @@ let () = Lwt_main.run main The example is contained in `examples/readme.ml`. It can be compiled and executed with dune: -```bash + +```sh $ dune build examples/readme.exe $ dune exec examples/readme.exe foo/bar => 'testing 123' @@ -118,11 +119,12 @@ The `examples/` directory also contains more advanced examples, which can be exe ### Command-line The same thing can also be accomplished using `irmin`, the command-line application installed with `irmin-unix`, by running: -```bash +```sh $ echo "root: ." > irmin.yml $ irmin init $ irmin set foo/bar "testing 123" $ irmin get foo/bar +testing 123 ``` `irmin.yml` allows for `irmin` flags to be set on a per-directory basis. You can also set flags globally using `$HOME/.irmin/config.yml`. Run `irmin help irmin.yml` for further details. diff --git a/dune b/dune new file mode 100644 index 00000000000..b470f0d5232 --- /dev/null +++ b/dune @@ -0,0 +1,3 @@ +(mdx + (files README.md) + (packages irmin irmin-unix)) diff --git a/dune-project b/dune-project index 73093d0df9e..760ff08d8fb 100644 --- a/dune-project +++ b/dune-project @@ -1,3 +1,5 @@ -(lang dune 2.0) +(lang dune 2.4) (name irmin) (allow_approximate_merlin) + +(using mdx 0.1) diff --git a/examples/readme.ml b/examples/readme.ml index b1629f1a19a..5f119950095 100644 --- a/examples/readme.ml +++ b/examples/readme.ml @@ -1,6 +1,3 @@ -(* N.B. This excerpt is extracted from project README. Any changes made here - * should be mirrored there. *) - open Lwt.Infix (* Irmin store with string contents *) @@ -17,13 +14,13 @@ let info fmt = Irmin_unix.info ~author fmt let main = (* Open the repo *) - Store.Repo.v config >>= (* Load the master branch *) - Store.master >>= fun t -> + Store.Repo.v config >>= fun repo -> + (* Load the master branch *) + Store.master repo >>= fun t -> (* Set key "foo/bar" to "testing 123" *) - Store.set_exn t ~info:(info "Updating foo/bar") [ "foo"; "bar" ] - "testing 123" + Store.set_exn t ~info:(info "Updating foo/bar") [ "foo"; "bar" ] "testing 123" >>= fun () -> - (* Get key "foo/bar" and print it to stdout *) + (* Get key "foo/bar" print it to stdout *) Store.get t [ "foo"; "bar" ] >|= fun x -> Printf.printf "foo/bar => '%s'\n" x (* Run the program *) diff --git a/irmin-chunk.opam b/irmin-chunk.opam index 06aa2485e8e..e188cd17252 100644 --- a/irmin-chunk.opam +++ b/irmin-chunk.opam @@ -14,7 +14,7 @@ build: [ depends: [ "ocaml" {>= "4.02.3"} - "dune" {>= "2.0.0"} + "dune" {>= "2.4.0"} "irmin" {>= "2.0.0"} "fmt" "logs" diff --git a/irmin-fs.opam b/irmin-fs.opam index dac3b92a788..8be43fd017e 100644 --- a/irmin-fs.opam +++ b/irmin-fs.opam @@ -15,7 +15,7 @@ build: [ depends: [ "ocaml" {>= "4.03.0"} - "dune" {>= "2.0.0"} + "dune" {>= "2.4.0"} "irmin" {>= "2.0.0"} "logs" "lwt" diff --git a/irmin-git.opam b/irmin-git.opam index 747fb1d55ef..209a4323fd5 100644 --- a/irmin-git.opam +++ b/irmin-git.opam @@ -15,7 +15,7 @@ build: [ depends: [ "ocaml" {>= "4.02.3"} - "dune" {>= "2.0.0"} + "dune" {>= "2.4.0"} "irmin" {>= "2.0.0"} "git" {>= "2.1.1"} "digestif" {>= "0.7.3"} diff --git a/irmin-graphql.opam b/irmin-graphql.opam index 88fd2607a0a..6b53836a83d 100644 --- a/irmin-graphql.opam +++ b/irmin-graphql.opam @@ -15,7 +15,7 @@ build: [ depends: [ "ocaml" {>= "4.03.0"} - "dune" {>= "2.0.0"} + "dune" {>= "2.4.0"} "irmin" {>= "2.2.0"} "graphql" {>= "0.13.0"} "graphql-lwt" {>= "0.13.0"} diff --git a/irmin-http.opam b/irmin-http.opam index 0a2fe25792e..6f8cc7904dc 100644 --- a/irmin-http.opam +++ b/irmin-http.opam @@ -15,7 +15,7 @@ build: [ depends: [ "ocaml" {>= "4.02.3"} - "dune" {>= "2.0.0"} + "dune" {>= "2.4.0"} "crunch" {>= "2.2.0"} "webmachine" {>= "0.6.0"} "irmin" {>= "2.2.0"} diff --git a/irmin-mem.opam b/irmin-mem.opam index 49f414da100..feec7159175 100644 --- a/irmin-mem.opam +++ b/irmin-mem.opam @@ -15,7 +15,7 @@ build: [ depends: [ "ocaml" {>= "4.03.0"} - "dune" {>= "2.0.0"} + "dune" {>= "2.4.0"} "irmin" {>= "2.2.0"} "irmin-test" {with-test} ] diff --git a/irmin-mirage-git.opam b/irmin-mirage-git.opam index 49533254485..27c7477919d 100644 --- a/irmin-mirage-git.opam +++ b/irmin-mirage-git.opam @@ -13,7 +13,7 @@ build: [ ] depends: [ - "dune" {>= "2.0.0"} + "dune" {>= "2.4.0"} "irmin-mirage" "irmin-git" {>= "2.0.0"} "git-mirage" {>= "2.1.2"} diff --git a/irmin-mirage-graphql.opam b/irmin-mirage-graphql.opam index 8ba997f74ab..ed4722500ec 100644 --- a/irmin-mirage-graphql.opam +++ b/irmin-mirage-graphql.opam @@ -13,7 +13,7 @@ build: [ ] depends: [ - "dune" {>= "2.0.0"} + "dune" {>= "2.4.0"} "irmin-mirage" "git-mirage" {>= "2.1.1"} "irmin-graphql" diff --git a/irmin-mirage.opam b/irmin-mirage.opam index 7060ea88d1e..5c90606c138 100644 --- a/irmin-mirage.opam +++ b/irmin-mirage.opam @@ -13,7 +13,7 @@ build: [ ] depends: [ - "dune" {>= "2.0.0"} + "dune" {>= "2.4.0"} "irmin" {>= "2.0.0"} "irmin-mem" {>= "2.0.0"} "fmt" diff --git a/irmin-pack.opam b/irmin-pack.opam index eba0a6c8960..62332a11352 100644 --- a/irmin-pack.opam +++ b/irmin-pack.opam @@ -14,7 +14,7 @@ build: [ depends: [ "ocaml" {>= "4.02.3"} - "dune" {>= "2.0.0"} + "dune" {>= "2.4.0"} "irmin" {>= "2.2.0"} "index" {>= "1.2.1"} "fmt" diff --git a/irmin-test.opam b/irmin-test.opam index 1f5b280a867..39edf6d44a0 100644 --- a/irmin-test.opam +++ b/irmin-test.opam @@ -14,7 +14,7 @@ build: [ depends: [ "ocaml" {>= "4.02.3"} - "dune" {>= "2.0.0"} + "dune" {>= "2.4.0"} "irmin" {>= "2.2.0"} "alcotest" {>= "1.0.1"} "mtime" {>= "1.0.0"} diff --git a/irmin-unix.opam b/irmin-unix.opam index c0c8d57bd59..e8ecacf010b 100644 --- a/irmin-unix.opam +++ b/irmin-unix.opam @@ -15,7 +15,7 @@ build: [ depends: [ "ocaml" {>= "4.01.0"} - "dune" {>= "2.0.0"} + "dune" {>= "2.4.0"} "irmin" {>= "2.1.0"} "irmin-mem" {>= "2.0.0"} "irmin-git" {>= "2.0.0"} diff --git a/irmin.opam b/irmin.opam index fcb7d9ec703..d84dadd9e16 100644 --- a/irmin.opam +++ b/irmin.opam @@ -15,7 +15,7 @@ build: [ depends: [ "ocaml" {>= "4.07.0"} - "dune" {>= "2.0.0"} + "dune" {>= "2.4.0"} "fmt" {>= "0.8.0"} "uri" {>= "1.3.12"} "uutf" @@ -31,6 +31,7 @@ depends: [ "alcotest-lwt" {with-test} "ppx_irmin" {with-test} "irmin-mem" {with-test & post} + "mdx" {with-test & >= "1.7.0"} ] synopsis: """ Irmin, a distributed database that follows the same design principles as Git diff --git a/ppx_irmin.opam b/ppx_irmin.opam index 876d7910ef2..2b2a5eb5016 100644 --- a/ppx_irmin.opam +++ b/ppx_irmin.opam @@ -13,7 +13,7 @@ build: [ ] depends: [ - "dune" {>= "2.0.0"} + "dune" {>= "2.4.0"} "ocaml" {>= "4.06.0"} "ocaml-syntax-shims" "ppxlib" {>= "0.12.0"}