Skip to content

Commit

Permalink
Initialize Err library for error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarbin committed Aug 22, 2024
1 parent fc92903 commit 4b81a35
Show file tree
Hide file tree
Showing 34 changed files with 1,552 additions and 44 deletions.
8 changes: 7 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
## 0.0.1~preview-0.1 (2024-08-19)
## 0.0.1 (2024-08-22)

### Added

- Added library `Err` establishing a standard for error handling in commandlang CLIs.

## 0.0.1_preview-0.1 (2024-08-19)

### Added

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,5 @@ We initiated the library as part of another project where we are migrating some

- We are grateful for the years of accumulated work and experience that have resulted in high-quality CLI libraries like `cmdliner` and `core.command`.
- `climate`'s early programming interface was a great source of inspiration. We are very thankful for their work on auto-completion and excited to see where the `climate` project goes next.
- We would like to thank the Dune developers for the user-facing error handling of Dune (`Stdune.User_message`), on which we based the error handling scheme used in commandlang (`Err`). By adopting a similar approach, we aim to provide a consistent and unified user experience for OCaml users across different tools and libraries.
- We are inspired by the [diataxis](https://diataxis.fr/) approach to technical documentation, which we use to structure our documentation.
34 changes: 34 additions & 0 deletions commandlang-err.opam
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
synopsis: "Error Handling Standard for Commandlang CLIs"
maintainer: ["Mathieu Barbin"]
authors: ["Mathieu Barbin"]
license: "MIT"
homepage: "https://github.com/mbarbin/commandlang"
doc: "https://mbarbin.github.io/commandlang/"
bug-reports: "https://github.com/mbarbin/commandlang/issues"
depends: [
"dune" {>= "3.16"}
"ocaml" {>= "5.2"}
"bisect_ppx" {dev & >= "2.8.3"}
"commandlang" {= version}
"ppx_js_style" {dev & >= "v0.17" & < "v0.18"}
"sexplib0" {>= "v0.17" & < "v0.18"}
"stdune" {>= "3.16"}
"odoc" {with-doc}
]
build: [
["dune" "subst"] {dev}
[
"dune"
"build"
"-p"
name
"-j"
jobs
"@install"
"@runtest" {with-test}
"@doc" {with-doc}
]
]
dev-repo: "git+https://github.com/mbarbin/commandlang.git"
2 changes: 2 additions & 0 deletions commandlang-test.opam
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ depends: [
"core" {>= "v0.17" & < "v0.18"}
"core_unix" {>= "v0.17" & < "v0.18"}
"expect_test_helpers_core" {>= "v0.17" & < "v0.18"}
"loc" {>= "0.0.2"}
"mdx" {>= "2.4"}
"ppx_compare" {>= "v0.17" & < "v0.18"}
"ppx_enumerate" {>= "v0.17" & < "v0.18"}
Expand All @@ -31,6 +32,7 @@ depends: [
"ppxlib" {>= "0.33"}
"sherlodoc" {with-doc & >= "0.2"}
"stdio" {>= "v0.17" & < "v0.18"}
"stdune" {>= "3.16"}
"odoc" {with-doc}
]
build: [
Expand Down
2 changes: 2 additions & 0 deletions commandlang-to-base.opam
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ depends: [
"dune" {>= "3.16"}
"ocaml" {>= "5.2"}
"base" {>= "v0.17" & < "v0.18"}
"bisect_ppx" {dev & >= "2.8.3"}
"commandlang" {= version}
"core" {>= "v0.17" & < "v0.18"}
"ppx_compare" {>= "v0.17" & < "v0.18"}
"ppx_enumerate" {>= "v0.17" & < "v0.18"}
Expand Down
2 changes: 2 additions & 0 deletions commandlang-to-climate.opam
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ bug-reports: "https://github.com/mbarbin/commandlang/issues"
depends: [
"dune" {>= "3.16"}
"ocaml" {>= "5.2"}
"bisect_ppx" {dev & >= "2.8.3"}
"climate" {= "0.0.1~preview-0.1"}
"commandlang" {= version}
"ppx_js_style" {dev & >= "v0.17" & < "v0.18"}
"odoc" {with-doc}
]
build: [
Expand Down
2 changes: 2 additions & 0 deletions commandlang-to-cmdliner.opam
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ bug-reports: "https://github.com/mbarbin/commandlang/issues"
depends: [
"dune" {>= "3.16"}
"ocaml" {>= "5.2"}
"bisect_ppx" {dev & >= "2.8.3"}
"cmdliner" {= "1.3.0"}
"commandlang" {= version}
"ppx_js_style" {dev & >= "v0.17" & < "v0.18"}
"odoc" {with-doc}
]
build: [
Expand Down
2 changes: 2 additions & 0 deletions commandlang.opam
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ bug-reports: "https://github.com/mbarbin/commandlang/issues"
depends: [
"dune" {>= "3.16"}
"ocaml" {>= "5.2"}
"bisect_ppx" {dev & >= "2.8.3"}
"ppx_js_style" {dev & >= "v0.17" & < "v0.18"}
"odoc" {with-doc}
]
build: [
Expand Down
16 changes: 7 additions & 9 deletions doc/docs/tutorials/getting-started/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ First, create a `lib/` directory and a `lib/dune` file for our library, listing

Next, create an empty command-line skeleton that we will complete incrementally.

<!-- $MDX file=getting_started.ml,part=void -->
<!-- $MDX skip -->
```ocaml
let cmd =
Command.make
Expand Down Expand Up @@ -81,20 +81,18 @@ As you'll learn, `commandlang` doesn't come with its own command runner. Instead
```lisp
(executable
(name main)
(libraries commandlang_to_cmdliner cmdliner getting_started))
(libraries commandlang_to_cmdliner getting_started))
```

An invocation of `cmdliner` for a `commandlang` command may look like this:

<!-- $MDX file=main.ml -->
```ocaml
let () =
Cmdliner.Cmd.eval
(Commandlang_to_cmdliner.Translate.command
Getting_started.cmd
~name:"my-calculator"
~version:"%%VERSION%%")
|> Stdlib.exit
Commandlang_to_cmdliner.run
Getting_started.cmd
~name:"my-calculator"
~version:"%%VERSION%%"
;;
```

Expand Down Expand Up @@ -138,7 +136,7 @@ Next, we'll start exposing the functionality via the command-line interface.

Let's revisit our empty skeleton:

<!-- $MDX file=getting_started.ml,part=void,skip -->
<!-- $MDX skip -->
```ocaml
let cmd =
Command.make
Expand Down
2 changes: 1 addition & 1 deletion doc/docs/tutorials/getting-started/bin/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(executable
(name main)
(flags :standard -w +a-4-40-41-42-44-45-48-66 -warn-error +a)
(libraries cmdliner commandlang_to_cmdliner getting_started)
(libraries commandlang_to_cmdliner getting_started)
(instrumentation
(backend bisect_ppx)))
10 changes: 4 additions & 6 deletions doc/docs/tutorials/getting-started/bin/main.ml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
let () =
Cmdliner.Cmd.eval
(Commandlang_to_cmdliner.Translate.command
Getting_started.cmd
~name:"my-calculator"
~version:"%%VERSION%%")
|> Stdlib.exit
Commandlang_to_cmdliner.run
Getting_started.cmd
~name:"my-calculator"
~version:"%%VERSION%%"
;;
12 changes: 0 additions & 12 deletions doc/docs/tutorials/getting-started/lib/getting_started.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,6 @@ module Operator = struct
end
(* $MDX part-end *)

(* $MDX part-begin=void *)
let cmd =
Command.make
~summary:"A simple calculator"
(let open Command.Std in
let+ () = Arg.return () in
())
;;

(* $MDX part-end *)
let _ = cmd

(* $MDX part-begin=final *)
let cmd =
Command.make
Expand Down
69 changes: 65 additions & 4 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,40 @@
(synopsis "Declarative Command-line Parsing for OCaml")
(depends
(ocaml
(>= 5.2))))
(>= 5.2))
(bisect_ppx
(and
:dev
(>= 2.8.3)))
(ppx_js_style
(and
:dev
(>= v0.17)
(< v0.18)))))

(package
(name commandlang-err)
(synopsis "Error Handling Standard for Commandlang CLIs")
(depends
(ocaml
(>= 5.2))
(bisect_ppx
(and
:dev
(>= 2.8.3)))
(commandlang
(= :version))
(ppx_js_style
(and
:dev
(>= v0.17)
(< v0.18)))
(sexplib0
(and
(>= v0.17)
(< v0.18)))
(stdune
(>= 3.16))))

(package
(name commandlang-to-base)
Expand All @@ -34,6 +67,12 @@
(and
(>= v0.17)
(< v0.18)))
(bisect_ppx
(and
:dev
(>= 2.8.3)))
(commandlang
(= :version))
(core
(and
(>= v0.17)
Expand Down Expand Up @@ -86,21 +125,39 @@
(depends
(ocaml
(>= 5.2))
(bisect_ppx
(and
:dev
(>= 2.8.3)))
(cmdliner
(= 1.3.0))
(commandlang
(= :version))))
(= :version))
(ppx_js_style
(and
:dev
(>= v0.17)
(< v0.18)))))

(package
(name commandlang-to-climate)
(synopsis "Convert commandlang Parsers to climate")
(depends
(ocaml
(>= 5.2))
(bisect_ppx
(and
:dev
(>= 2.8.3)))
(climate
(= 0.0.1~preview-0.1))
(commandlang
(= :version))))
(= :version))
(ppx_js_style
(and
:dev
(>= v0.17)
(< v0.18)))))

(package
(name commandlang-test)
Expand Down Expand Up @@ -134,6 +191,8 @@
(and
(>= v0.17)
(< v0.18)))
(loc
(>= 0.0.2))
(mdx
(>= 2.4))
(ppx_compare
Expand Down Expand Up @@ -182,4 +241,6 @@
(stdio
(and
(>= v0.17)
(< v0.18)))))
(< v0.18)))
(stdune
(>= 3.16))))
2 changes: 2 additions & 0 deletions lib/commandlang/src/command.mli
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
(** Declarative Command-line Parsing for OCaml. *)

(** {1 Utils} *)

module Nonempty_list : sig
Expand Down
2 changes: 1 addition & 1 deletion lib/commandlang/test/test__command.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ let%expect_test "Param.enum" =
let open Command.Std in
require_does_raise [%here] (fun () ->
let+ _ = Arg.named [ "a" ] (Param.assoc []) ~doc:"empty enum" in
());
(() [@coverage off]));
[%expect {| (Invalid_argument Command.Arg.enum) |}];
()
;;
19 changes: 19 additions & 0 deletions lib/commandlang_err/src/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
(library
(name commandlang_err)
(public_name commandlang-err)
(flags
:standard
-w
+a-4-40-41-42-44-45-48-66
-warn-error
+a
-open
Commandlang
-open
Sexplib0)
(libraries commandlang sexplib0 stdune)
(instrumentation
(backend bisect_ppx))
(lint
(pps ppx_js_style -allow-let-operators -check-doc-comments))
(preprocess no_preprocessing))
Loading

0 comments on commit 4b81a35

Please sign in to comment.