Skip to content

Commit

Permalink
Add style usage
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarbin committed Dec 1, 2024
1 parent 675b588 commit 823de97
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
18 changes: 18 additions & 0 deletions doc/docs/guides/usage-styles/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,24 @@ let _ : unit Command.t =

This is the main style recommended by the cmdlang authors.

#### No Indentation Tweak with @@

Some people prefer limiting the indentation of large blocks with the help of the infix operator `@@`. In this context, this may look like this:

<!-- $MDX file=usage_styles.ml,part=let_plus_std_no_indent -->
```ocaml
let _ : unit Command.t =
Command.make ~summary:"A command skeleton"
@@
let open Command.Std in
let+ (_ : int) = Arg.named [ "n" ] Param.int ~doc:"A value for n"
and+ () = Arg.return () in
()
;;
```

The cmdlang authors do not have much experience with this style at the time of writing.

### Using let-syntax and map_open

An alternative based on the `let%map_open` operator of [ppx_let](https://github.com/janestreet/ppx_let) is also supported.
Expand Down
12 changes: 12 additions & 0 deletions doc/docs/guides/usage-styles/lib/usage_styles.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ let _ : unit Command.t =

(* $MDX part-end *)

(* $MDX part-begin=let_plus_std_no_indent *)
let _ : unit Command.t =
Command.make ~summary:"A command skeleton"
@@
let open Command.Std in
let+ (_ : int) = Arg.named [ "n" ] Param.int ~doc:"A value for n"
and+ () = Arg.return () in
()
;;

(* $MDX part-end *)

(* $MDX part-begin=let_map_open *)
let _ : unit Command.t =
Command.make
Expand Down

0 comments on commit 823de97

Please sign in to comment.