Skip to content

Commit

Permalink
Use MDX to test the README example
Browse files Browse the repository at this point in the history
  • Loading branch information
craigfe committed Apr 14, 2020
1 parent 0a60781 commit 7cbcc85
Show file tree
Hide file tree
Showing 19 changed files with 48 additions and 40 deletions.
1 change: 0 additions & 1 deletion .ocamlformat-ignore

This file was deleted.

34 changes: 18 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,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 .
<!-- $MDX skip -->
```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.

<!-- N.B. Any changes to the following example must be mirrored in `examples/readme.ml`. -->
<!-- $MDX file=examples/readme.ml -->
```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"
Expand All @@ -76,25 +79,23 @@ 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
```

The example is contained in `examples/readme.ml`. It can be compiled and executed with dune:

```bash
<!-- $MDX skip -->
```sh
$ dune build examples/readme.exe
$ dune exec examples/readme.exe
foo/bar => 'testing 123'
Expand All @@ -104,11 +105,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.
Expand Down
3 changes: 3 additions & 0 deletions dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(mdx
(files README.md)
(packages irmin irmin-unix))
4 changes: 3 additions & 1 deletion dune-project
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
(lang dune 2.0)
(lang dune 2.4)
(name irmin)

(using mdx 0.1)
13 changes: 5 additions & 8 deletions examples/readme.ml
Original file line number Diff line number Diff line change
@@ -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 *)
Expand All @@ -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 *)
Expand Down
2 changes: 1 addition & 1 deletion irmin-chunk.opam
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ build: [

depends: [
"ocaml" {>= "4.02.3"}
"dune" {>= "2.0.0"}
"dune" {>= "2.4.0"}
"irmin" {>= "2.0.0"}
"lwt"
"irmin-mem" {with-test & >= "2.0.0"}
Expand Down
2 changes: 1 addition & 1 deletion irmin-fs.opam
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ build: [

depends: [
"ocaml" {>= "4.03.0"}
"dune" {>= "2.0.0"}
"dune" {>= "2.4.0"}
"irmin" {>= "2.0.0"}
"irmin-test" {with-test & >= "2.0.0"}
]
Expand Down
2 changes: 1 addition & 1 deletion irmin-git.opam
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
2 changes: 1 addition & 1 deletion irmin-graphql.opam
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ build: [

depends: [
"ocaml" {>= "4.03.0"}
"dune" {>= "2.0.0"}
"dune" {>= "2.4.0"}
"irmin" {>= "2.0.0"}
"graphql" {>= "0.13.0"}
"graphql-lwt" {>= "0.13.0"}
Expand Down
2 changes: 1 addition & 1 deletion irmin-http.opam
Original file line number Diff line number Diff line change
Expand Up @@ -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.0.0"}
Expand Down
2 changes: 1 addition & 1 deletion irmin-mem.opam
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ build: [

depends: [
"ocaml" {>= "4.03.0"}
"dune" {>= "2.0.0"}
"dune" {>= "2.4.0"}
"irmin" {>= "2.0.0"}
"irmin-test" {with-test}
]
Expand Down
2 changes: 1 addition & 1 deletion irmin-mirage-git.opam
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
2 changes: 1 addition & 1 deletion irmin-mirage-graphql.opam
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ build: [
]

depends: [
"dune" {>= "2.0.0"}
"dune" {>= "2.4.0"}
"irmin-mirage"
"git-mirage" {>= "2.1.1"}
"irmin-graphql"
Expand Down
2 changes: 1 addition & 1 deletion irmin-mirage.opam
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ build: [
]

depends: [
"dune" {>= "2.0.0"}
"dune" {>= "2.4.0"}
"irmin" {>= "2.0.0"}
"irmin-mem" {>= "2.0.0"}
"ptime"
Expand Down
2 changes: 1 addition & 1 deletion irmin-pack.opam
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ build: [

depends: [
"ocaml" {>= "4.02.3"}
"dune" {>= "2.0.0"}
"dune" {>= "2.4.0"}
"irmin" {>= "2.0.0"}
"index" {>= "1.2.0"}
"lwt"
Expand Down
2 changes: 1 addition & 1 deletion irmin-test.opam
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ build: [

depends: [
"ocaml" {>= "4.02.3"}
"dune" {>= "2.0.0"}
"dune" {>= "2.4.0"}
"irmin" {>= "2.0.0"}
"alcotest" {>= "1.0.1"}
"mtime" {>= "1.0.0"}
Expand Down
2 changes: 1 addition & 1 deletion irmin-unix.opam
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
7 changes: 6 additions & 1 deletion irmin.opam
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
"jsonm" {>= "1.0.0"}
Expand All @@ -28,6 +28,7 @@ depends: [
"hex" {with-test}
"alcotest" {with-test}
"ppx_irmin" {with-test}
"mdx" {with-test & >= "1.7.0"}
]
synopsis: """
Irmin, a distributed database that follows the same design principles as Git
Expand All @@ -39,3 +40,7 @@ variety of backends. Irmin is written in pure OCaml and does not
depend on external C stubs; it aims to run everywhere, from Linux,
to browsers and Xen unikernels.
"""

pin-depends: [
["mdx.dev" "git+https://github.com/realworldocaml/mdx"]
]
2 changes: 1 addition & 1 deletion ppx_irmin.opam
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ build: [

depends: [
"ocaml" {>= "4.06.0"}
"dune" {>= "2.0.0"}
"dune" {>= "2.4.0"}
"ocaml-syntax-shims"
"ppxlib" {= "0.12.0"}
]
Expand Down

0 comments on commit 7cbcc85

Please sign in to comment.