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 Jan 4, 2022
1 parent 177a366 commit bc7f663
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 30 deletions.
32 changes: 21 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,15 @@ version and install instructions on [ocaml.org](https://ocaml.org/docs/install.h
To install Irmin with the command-line tool and all optional dependencies using
`opam`:

<!-- $MDX skip -->
```bash
opam install irmin-unix
```

A minimal installation containing the reference in-memory backend can be
installed by running:

<!-- $MDX skip -->
```bash
opam install irmin
```
Expand All @@ -79,6 +81,7 @@ The following packages have been made available on `opam`:

To install a specific package, simply run:

<!-- $MDX skip -->
```bash
opam install <package-name>
```
Expand All @@ -88,6 +91,7 @@ To install a specific package, simply run:
To install the development version of Irmin in your current `opam switch`, clone
this repository and `opam install` the packages inside:

<!-- $MDX skip -->
```bash
git clone https://github.com/mirage/irmin
cd irmin/
Expand All @@ -101,12 +105,12 @@ this repository and `opam install` the packages inside:
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.Syntax
(* 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 @@ -126,12 +130,12 @@ let main =
(* Set key "foo/bar" to "testing 123" *)
let* () =
Store.set_exn t ~info:(info "Updating foo/bar") ["foo"; "bar"]
Store.set_exn t ~info:(info "Updating foo/bar") [ "foo"; "bar" ]
"testing 123"
in
(* Get key "foo/bar" and print it to stdout *)
let+ x = Store.get t ["foo"; "bar"] in
let+ x = Store.get t [ "foo"; "bar" ] in
Printf.printf "foo/bar => '%s'\n" x
(* Run the program *)
Expand All @@ -141,9 +145,12 @@ let () = Lwt_main.run main
The example is contained in [examples/readme.ml](./examples/readme.ml) It can
be compiled and executed with dune:

$ dune build examples/readme.exe
$ dune exec examples/readme.exe
foo/bar => 'testing 123'
<!-- $MDX skip -->
```bash
$ dune build examples/readme.exe
$ dune exec examples/readme.exe
foo/bar => 'testing 123'
```

The [examples](./examples/) directory also contains more advanced examples,
which can be executed in the same way.
Expand All @@ -153,10 +160,13 @@ which can be executed in the same way.
The same thing can also be accomplished using `irmin`, the command-line
application installed with `irmin-unix`, by running:

$ echo "root: ." > irmin.yml
$ irmin init
$ irmin set foo/bar "testing 123"
$ irmin get foo/bar
```bash
$ 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
Expand Down
4 changes: 4 additions & 0 deletions dune
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
(vendored_dirs vendors)

(mdx
(files README.md)
(packages irmin irmin-unix))
1 change: 1 addition & 0 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
(name irmin)
(allow_approximate_merlin)
(cram enable)
(using mdx 0.1)
19 changes: 0 additions & 19 deletions examples/readme.ml
Original file line number Diff line number Diff line change
@@ -1,22 +1,3 @@
(*
* Copyright (c) 2013-2021 Thomas Gazagnaire <thomas@gazagnaire.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)

(* N.B. This excerpt is extracted from project README. Any changes made here
* should be mirrored there. *)

open Lwt.Syntax

(* Irmin store with string contents *)
Expand Down
1 change: 1 addition & 0 deletions irmin.opam
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ depends: [
"alcotest" {>= "1.1.0" & with-test}
"alcotest-lwt" {with-test}
"vector" {with-test}
"mdx" {>= "2.0.0" & with-test}
"odoc" {(< "2.0.1" | > "2.0.2") & with-doc} # See https://github.com/ocaml/odoc/issues/793
]

Expand Down

0 comments on commit bc7f663

Please sign in to comment.