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

query subcommand to retrieve metadata #232

Closed
yannham opened this issue Dec 1, 2020 · 0 comments · Fixed by #241
Closed

query subcommand to retrieve metadata #232

yannham opened this issue Dec 1, 2020 · 0 comments · Fixed by #241

Comments

@yannham
Copy link
Member

yannham commented Dec 1, 2020

Is your feature request related to a problem? Please describe.
Currently, there is no way to access the data contained in metavalues, in particular the documentation, which limits their usefulness.

Describe the solution you'd like
Add a query sub-command to the interpreter which shows the metadata associated to a value. One could provide a field path: nickel -f input.ncl query foo.bar which would be equivalent to evaluating let x = import "input.ncl" in x.foo.bar and look at the metadata. If x.foo.bar is a record without contract, it could also list all fields and associated metadata of this record. Long flag may specify which part of the meta value once is interested in, e.g. --doc, --contract, --default, etc.

The documentation could also be formatted following Markdown (using termad).

Example (this is illustrative, not necessarily the right output formatting):

$nickel query foo.bar <<< '{ foo = {bar | Str | doc "hello" | default 2}}'
foo.bar:
  - contract: Str
  - doc: hello
  - default value: Num(2)

$nickel query foo <<< '{ foo = {bar | Str | doc "hello" | default 2}}'
foo:
  * bar:
    - contract: Str
    - doc: hello
    - default value: Num(2)

$nickel query baz <<< '{ foo = {bar | Str | doc "hello" | default 2}; baz = "a"}'
No metadata found for field `baz`.

The syntax of the field path may also be more general, such as a term with a hole, which would allow stuff like _.$"^$foo%".baz. The future REPL should also have a similar command, but this is a separate issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant