Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename CLI tool to mustache-ocaml, separate it into it's own package #71

Merged
merged 4 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 3.3.0
* Rename the CLI tool to `mustache-ocaml`. It's now part of the new opam
package `mustache-cli` (@psafont, #71)

### 3.2.0

* Remove the AST without locations: now all functions build an AST with locations;
Expand Down
15 changes: 0 additions & 15 deletions bin/dune

This file was deleted.

2 changes: 0 additions & 2 deletions bin/test/dune

This file was deleted.

2 changes: 0 additions & 2 deletions bin/test/errors/dune

This file was deleted.

17 changes: 0 additions & 17 deletions bin/test/errors/sys-errors.t

This file was deleted.

18 changes: 14 additions & 4 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,23 @@
(name mustache)
(synopsis "Mustache logic-less templates in OCaml")
(description "
Read and write mustache templates, and render them by providing a json object.
Contains the `mustache` command line utility for driving logic-less templates.
Read and write mustache templates, and render them.
")
(depends
(jsonm (>= 1.0.1))
(ounit2 :with-test)
(ezjsonm :with-test)
(menhir (>= 20180703))
(cmdliner (>= 1.0.4))
(ocaml (>= 4.08))))

(package
(name mustache-cli)
(synopsis "CLI for Mustache logic-less templates")
(description "
Command line utility `mustache-ocaml` for driving logic-less templates.
Read and write mustache templates, and render them by providing a json object.
")
(depends
(jsonm (>= 1.0.1))
(mustache (= :version))
(cmdliner (>= 1.1.0))
(ocaml (>= 4.08))))
40 changes: 40 additions & 0 deletions mustache-cli.opam
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
synopsis: "CLI for Mustache logic-less templates"
description: """

Command line utility `mustache-ocaml` for driving logic-less templates.
Read and write mustache templates, and render them by providing a json object.
"""
maintainer: ["Rudi Grinberg <me@rgrinerg.com>"]
authors: [
"Rudi Grinberg <me@rgrinberg.com>"
"Armaël Guéneau <armael.gueneau@ens-lyon.fr>"
"Gabriel Scherer <gabriel.scherer@gmail.com>"
]
license: "MIT"
homepage: "https://github.com/rgrinberg/ocaml-mustache"
bug-reports: "https://github.com/rgrinberg/ocaml-mustache/issues"
depends: [
"dune" {>= "2.7"}
"jsonm" {>= "1.0.1"}
"mustache" {= version}
"cmdliner" {>= "1.1.0"}
"ocaml" {>= "4.08"}
"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/rgrinberg/ocaml-mustache.git"
16 changes: 16 additions & 0 deletions mustache-cli/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
(executable
(name mustache_cli)
(public_name mustache-ocaml)
(package mustache-cli)
(libraries mustache jsonm cmdliner))

(rule
(deps (:bin mustache_cli.exe))
(action
(with-stdout-to mustache.1
(run %{bin} --help=groff))))

(install
(section man)
(package mustache-cli)
(files mustache.1))
9 changes: 4 additions & 5 deletions bin/mustache_cli.ml → mustache-cli/mustache_cli.ml
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,8 @@ let run_command =
in
Term.(const search_path $ includes $ no_working_dir)
in
( Term.(const run $ search_path $ json_file $ template_file)
, Term.info "mustache" ~doc ~man:manpage )
Cmd.v
(Cmd.info "mustache" ~doc ~man:manpage)
Term.(const run $ search_path $ json_file $ template_file)

let () =
let open Cmdliner in
Term.exit @@ Term.eval run_command
let () = exit @@ Cmdliner.Cmd.eval run_command
2 changes: 2 additions & 0 deletions mustache-cli/test/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(cram
(deps %{bin:mustache-ocaml}))
2 changes: 2 additions & 0 deletions mustache-cli/test/errors/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(cram
(deps %{bin:mustache-ocaml}))
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
$ echo '{{foo}}' > foo.mustache

Empty json file:
$ mustache empty.json foo.mustache
$ mustache-ocaml empty.json foo.mustache
File "empty.json", line 1, character 0: expected JSON text (JSON value)
[4]

Invalid json file:
$ mustache invalid.json foo.mustache
$ mustache-ocaml invalid.json foo.mustache
File "invalid.json", line 1, characters 15-29:
expected value separator or object end (',' or '}')
[4]
Original file line number Diff line number Diff line change
Expand Up @@ -3,62 +3,62 @@
Delimiter problems:
$ PROBLEM=no-closing-mustache.mustache
$ echo "{{foo" > $PROBLEM
$ mustache foo.json $PROBLEM
$ mustache-ocaml foo.json $PROBLEM
File "no-closing-mustache.mustache", line 2, character 0: '}}' expected.
[3]

$ PROBLEM=one-closing-mustache.mustache
$ echo "{{foo}" > $PROBLEM
$ mustache foo.json $PROBLEM
$ mustache-ocaml foo.json $PROBLEM
File "one-closing-mustache.mustache", line 1, character 5: '}}' expected.
[3]

$ PROBLEM=eof-before-variable.mustache
$ echo "{{" > $PROBLEM
$ mustache foo.json $PROBLEM
$ mustache-ocaml foo.json $PROBLEM
File "eof-before-variable.mustache", line 2, character 0: ident expected.
[3]

$ PROBLEM=eof-before-section.mustache
$ echo "{{#" > $PROBLEM
$ mustache foo.json $PROBLEM
$ mustache-ocaml foo.json $PROBLEM
File "eof-before-section.mustache", line 2, character 0: ident expected.
[3]

$ PROBLEM=eof-before-section-end.mustache
$ echo "{{#foo}} {{.}} {{/" > $PROBLEM
$ mustache foo.json $PROBLEM
$ mustache-ocaml foo.json $PROBLEM
File "eof-before-section-end.mustache", line 2, character 0: '}}' expected.
[3]

$ PROBLEM=eof-before-inverted-section.mustache
$ echo "{{^" > $PROBLEM
$ mustache foo.json $PROBLEM
$ mustache-ocaml foo.json $PROBLEM
File "eof-before-inverted-section.mustache", line 2, character 0:
ident expected.
[3]

$ PROBLEM=eof-before-unescape.mustache
$ echo "{{{" > $PROBLEM
$ mustache foo.json $PROBLEM
$ mustache-ocaml foo.json $PROBLEM
File "eof-before-unescape.mustache", line 2, character 0: ident expected.
[3]

$ PROBLEM=eof-before-unescape.mustache
$ echo "{{&" > $PROBLEM
$ mustache foo.json $PROBLEM
$ mustache-ocaml foo.json $PROBLEM
File "eof-before-unescape.mustache", line 2, character 0: ident expected.
[3]

$ PROBLEM=eof-before-partial.mustache
$ echo "{{>" > $PROBLEM
$ mustache foo.json $PROBLEM
$ mustache-ocaml foo.json $PROBLEM
File "eof-before-partial.mustache", line 2, character 0: '}}' expected.
[3]

$ PROBLEM=eof-in-comment.mustache
$ echo "{{! non-terminated comment" > $PROBLEM
$ mustache foo.json $PROBLEM
$ mustache-ocaml foo.json $PROBLEM
File "eof-in-comment.mustache", line 2, character 0: non-terminated comment.
[3]

Expand All @@ -67,13 +67,13 @@ Mismatches between opening and closing mustaches:

$ PROBLEM=two-three.mustache
$ echo "{{ foo }}}" > $PROBLEM
$ mustache foo.json $PROBLEM
$ mustache-ocaml foo.json $PROBLEM
File "two-three.mustache", line 1, characters 7-10: '}}' expected.
[3]

$ PROBLEM=three-two.mustache
$ echo "{{{ foo }}" > $PROBLEM
$ mustache foo.json $PROBLEM
$ mustache-ocaml foo.json $PROBLEM
File "three-two.mustache", line 1, characters 8-10: '}}}' expected.
[3]

Expand All @@ -82,34 +82,34 @@ Mismatch between section-start and section-end:

$ PROBLEM=foo-bar.mustache
$ echo "{{#foo}} {{.}} {{/bar}}" > $PROBLEM
$ mustache foo.json $PROBLEM
$ mustache-ocaml foo.json $PROBLEM
File "foo-bar.mustache", line 1, characters 0-23:
Open/close tag mismatch: {{# foo }} is closed by {{/ bar }}.
[3]

$ PROBLEM=foo-not-closed.mustache
$ echo "{{#foo}} {{.}} {{foo}}" > $PROBLEM
$ mustache foo.json $PROBLEM
$ mustache-ocaml foo.json $PROBLEM
File "foo-not-closed.mustache", line 2, character 0: syntax error.
[3]

$ PROBLEM=wrong-nesting.mustache
$ echo "{{#bar}} {{#foo}} {{.}} {{/bar}} {{/foo}}" > $PROBLEM
$ mustache foo.json $PROBLEM
$ mustache-ocaml foo.json $PROBLEM
File "wrong-nesting.mustache", line 1, characters 9-32:
Open/close tag mismatch: {{# foo }} is closed by {{/ bar }}.
[3]

$ PROBLEM=wrong-nesting-variable.mustache
$ echo '{{#bar}} {{$foo}} {{.}} {{/bar}} {{/foo}}' > $PROBLEM
$ mustache foo.json $PROBLEM
$ mustache-ocaml foo.json $PROBLEM
File "wrong-nesting-variable.mustache", line 1, characters 9-32:
Open/close tag mismatch: {{$ foo }} is closed by {{/ bar }}.
[3]

$ PROBLEM=wrong-nesting-partial.mustache
$ echo "{{#foo}} {{<foo-bar}} {{/foo}} {{/foo-bar}}" > $PROBLEM
$ mustache foo.json $PROBLEM
$ mustache-ocaml foo.json $PROBLEM
File "wrong-nesting-partial.mustache", line 1, characters 9-30:
Open/close tag mismatch: {{< foo-bar }} is closed by {{/ foo }}.
[3]
Expand All @@ -120,6 +120,6 @@ Weird cases that may confuse our lexer or parser:

$ PROBLEM=weird-tag-name.mustache
$ echo "{{.weird}} foo bar" > $PROBLEM
$ mustache foo.json $PROBLEM
$ mustache-ocaml foo.json $PROBLEM
File "weird-tag-name.mustache", line 1, character 3: '}}' expected.
[3]
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
reference.json and reference.mustache work well together, there is no error.
$ mustache reference.json reference.mustache
$ mustache-ocaml reference.json reference.mustache
Title: Some Title

List:
Expand All @@ -26,58 +26,58 @@ one possible source of error, or both, or none.

Invalid variable name:

$ mustache reference.json missing-variable.mustache
$ mustache-ocaml reference.json missing-variable.mustache
File "missing-variable.mustache", line 14, characters 40-46:
the variable 'na' is missing.
[2]

$ mustache missing-variable.json reference.mustache
$ mustache-ocaml missing-variable.json reference.mustache
File "reference.mustache", line 5, characters 4-12:
the variable 'data' is missing.
[2]

Invalid section name:

$ mustache reference.json missing-section.mustache
$ mustache-ocaml reference.json missing-section.mustache
File "missing-section.mustache", line 14, characters 0-55:
the section 'na' is missing.
[2]

$ mustache missing-section.json reference.mustache
$ mustache-ocaml missing-section.json reference.mustache
File "reference.mustache", lines 9-12, characters 0-10:
the section 'group' is missing.
[2]

Error in a dotted path foo.bar (one case for the first component, the other in the second).

$ mustache reference.json invalid-dotted-name-1.mustache
$ mustache-ocaml reference.json invalid-dotted-name-1.mustache
File "invalid-dotted-name-1.mustache", line 10, characters 2-15:
the variable 'gro' is missing.
[2]

$ mustache invalid-dotted-name-1.json reference.mustache
$ mustache-ocaml invalid-dotted-name-1.json reference.mustache
File "reference.mustache", lines 9-12, characters 0-10:
the section 'group' is missing.
[2]

$ mustache reference.json invalid-dotted-name-2.mustache
$ mustache-ocaml reference.json invalid-dotted-name-2.mustache
File "invalid-dotted-name-2.mustache", line 10, characters 2-15:
the variable 'group.fir' is missing.
[2]

$ mustache invalid-dotted-name-2.json reference.mustache
$ mustache-ocaml invalid-dotted-name-2.json reference.mustache
File "reference.mustache", line 10, characters 2-17:
the variable 'group.first' is missing.
[2]

Non-scalar used as a scalar:

$ mustache reference.json non-scalar.mustache
$ mustache-ocaml reference.json non-scalar.mustache
File "non-scalar.mustache", line 4, characters 0-8:
the value of 'list' is not a valid scalar.
[2]

$ mustache non-scalar.json reference.mustache
$ mustache-ocaml non-scalar.json reference.mustache
File "reference.mustache", line 1, characters 7-16:
the value of 'title' is not a valid scalar.
[2]
Expand All @@ -87,7 +87,7 @@ Missing partial (currently the CLI does not support any partial anyway):
(this one does not) are all before in the alphabetic order, resulting
in better `ls` output).

$ mustache reference.json z-missing-partial.mustache
$ mustache-ocaml reference.json z-missing-partial.mustache
File "z-missing-partial.mustache", line 11, characters 2-13:
the partial 'second' is missing.
[2]
Loading