Skip to content

Commit

Permalink
Fix old tests and add new for customize mode
Browse files Browse the repository at this point in the history
  • Loading branch information
yannham committed Nov 6, 2023
1 parent 4e3722b commit e9c48b6
Show file tree
Hide file tree
Showing 20 changed files with 204 additions and 105 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# capture = 'stderr'
# command = ['export']
# extra_args = [
# '--',
# 'input.foo.bar=="hello"',
# 'input.foo.baz=[]',
# '--override',
# 'unkonwn.field.path=null',
# ]
{
input.foo.bar | String,
input.foo.baz | Array Number,
input.defaulted.subfield
| doc "Some documentation"
| default = 2,

override.first = 1,
override.second = {
subsecond = {
subsubsecond = "a",
other = [],
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# capture = 'stderr'
# command = ['export']
# extra_args = [
# '--',
# 'show',
# 'input.+foo.baz',
# ]
{
input.foo.bar | String,
input.foo.baz | Array Number,
input.defaulted.subfield
| doc "Some documentation"
| default = 2,

override.first = 1,
override.second = {
subsecond = {
subsubsecond = "a",
other = [],
}
}
}
9 changes: 0 additions & 9 deletions cli/tests/snapshot/inputs/customize-mode/has_help.ncl

This file was deleted.

9 changes: 0 additions & 9 deletions cli/tests/snapshot/inputs/customize-mode/has_override.ncl

This file was deleted.

18 changes: 18 additions & 0 deletions cli/tests/snapshot/inputs/customize-mode/list.ncl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# capture = 'stdout'
# command = ['export']
# extra_args = ['--', 'list']
{
input.foo.bar | String,
input.foo.baz | Array Number,
input.defaulted.subfield
| doc "Some documentation"
| default = 2,

override.first = 1,
override.second = {
subsecond = {
subsubsecond = "a",
other = [],
}
}
}
2 changes: 1 addition & 1 deletion cli/tests/snapshot/inputs/customize-mode/not_an_input.ncl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# capture = 'stderr'
# command = ['export']
# extra_args =['--', '--override.first', '"test"']
# extra_args =['--', 'override.first="test"']
{
input.foo.bar | String,
input.foo.baz | Array Number,
Expand Down
19 changes: 19 additions & 0 deletions cli/tests/snapshot/inputs/customize-mode/show.ncl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# capture = 'stdout'
# command = ['export']
# extra_args = ['--', 'show', 'input.defaulted.subfield']
{
input.foo.bar | String,
input.foo.baz | Array Number,
input.defaulted.subfield
| std.number.Integer
| doc "Some documentation"
| default = 2,

override.first = 1,
override.second = {
subsecond = {
subsubsecond = "a",
other = [],
}
}
}
2 changes: 1 addition & 1 deletion cli/tests/snapshot/inputs/customize-mode/simple_adder.ncl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# capture = 'stdout'
# command = ['export']
# extra_args = ['--', '--input', '5']
# extra_args = ['--', 'input=5']
{
input | Number,
output = input + 1,
Expand Down
9 changes: 3 additions & 6 deletions cli/tests/snapshot/inputs/customize-mode/unknown_override.ncl
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@
# command = ['export']
# extra_args = [
# '--',
# '--input.foo.bar',
# '"hello"',
# '--input.foo.baz',
# '[]',
# 'input.foo.bar="hello"',
# 'input.foo.baz=[]',
# '--override',
# 'unkonwn.field.path',
# 'null'
# 'unkonwn.field.path=null',
# ]
{
input.foo.bar | String,
Expand Down
22 changes: 22 additions & 0 deletions cli/tests/snapshot/inputs/customize-mode/unkonwn_field_path.ncl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# capture = 'stderr'
# command = ['export']
# extra_args = [
# '--',
# 'show',
# 'unkonwn.field.path',
# ]
{
input.foo.bar | String,
input.foo.baz | Array Number,
input.defaulted.subfield
| doc "Some documentation"
| default = 2,

override.first = 1,
override.second = {
subsecond = {
subsubsecond = "a",
other = [],
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
source: cli/tests/snapshot/main.rs
expression: err
---
error: unexpected token
┌─ <cli-assignment>:1:14
1 │ input.foo.bar=="hello"
│ ^^

note: when parsing a field assignment on the command line
= A field assignment must be of the form `<field path>=<value>`, where `<field path>` is a dot-separated list of fields and `<value>` is a valid Nickel expression.
= For example: `config.database."$port"=8080`


Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
source: cli/tests/snapshot/main.rs
expression: err
---
error: unexpected token
┌─ <query>:1:7
1 │ input.+foo.baz
│ ^

note: when parsing a field path on the command line
= A field path must be a dot-separated list of fields. Fields with spaces or special characters must be properly quoted.
= For example: `config.database."$port"`


Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
source: cli/tests/snapshot/main.rs
expression: err
---
error: unexpected argument '--override.first' found
error: invalid assignment: `override.first` isn't an input
= `override.first` already has a value and thus can't be assigned without `--override`.
= If you really want to override this field, please use `--override 'override.first="test"'` instead.

tip: a similar argument exists: '--override'

Usage: customize-mode --input.foo.bar <String> --input.foo.baz <Array Number> --override <field> <value>

For more information, try '--help'.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ source: cli/tests/snapshot/main.rs
expression: err
---
error: invalid override: unknown field `unkonwn.field.path`
= `unkonwn.field.path` doesn't refer to record field accessible from the root of the configuration and thus can't be the target of `--override`.
= `unkonwn.field.path` doesn't refer to record field accessible from the root of the configuration.


Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
source: cli/tests/snapshot/main.rs
expression: err
---
error: invalid query: unknown field `unkonwn.field.path`
= `unkonwn.field.path` doesn't refer to record field accessible from the root of the configuration.


This file was deleted.

This file was deleted.

45 changes: 29 additions & 16 deletions cli/tests/snapshot/snapshots/snapshot__export_stdout_help.ncl.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,41 @@
source: cli/tests/snapshot/main.rs
expression: out
---
Customize a Nickel configuration through the command line before exporting
Customize a Nickel configuration through the command line

Usage: customize-mode [OPTIONS] --input.foo.bar <String> --input.foo.baz <Array Number>
Usage: customize-mode [OPTIONS] [FIELD_PATH=NICKEL_EXPRESSION]... [COMMAND]

Options:
--input.defaulted.subfield <NICKEL EXPRESSION>
• documentation: Some documentation
[default: 2]
--input.foo.bar <String>
Commands:
show Show the documentation of a particular field
list List the input fields and the overridable fields of the configuration
help Print this message or the help of the given subcommand(s)

Arguments:
[FIELD_PATH=NICKEL_EXPRESSION]...
Assign a valid Nickel expression to an input field of the configuration. The new value
will be merged with the configuration with priority 0 (the one assigned by default in
Nickel when no explicit merge priority is provided).

--input.foo.baz <Array Number>
Assignment can only set input fields, that is fields without definition or fields with a
default value. To override an existing value, use `--override` instead.

--override <field> <value>
Override any field of the configuration with a valid Nickel expression provided as a
string. The new value will be merged with the configuration with a `force` priority.
Note that you might have to escape special characters or enclose assignments in quotes to
prevent shell interpretation.

Overridable fields:
- override.first
- override.second.subsecond.other
- override.second.subsecond.subsubsecond
Example: `nickel eval config.ncl -- 'http.enabled="yes"' protocol=\'ftp`

Options:
--override <FIELD_PATH=NICKEL_EXPRESSION>
Override any field of the configuration with a valid Nickel expression. The new value will
be merged with the configuration with a `force` priority.

Note that you might have to escape special characters or enclose assignments in quotes to
prevent shell interpretation.

Example: `-- input.value=false --override m.count=2 --override m.type=\'server`

-h, --help
Print help
Print help (see a summary with '-h')

[WARNING] Customize mode is experimental. Its interface is subject to breaking changes.

14 changes: 14 additions & 0 deletions cli/tests/snapshot/snapshots/snapshot__export_stdout_list.ncl.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
source: cli/tests/snapshot/main.rs
expression: out
---
Input fields:
- input.defaulted.subfield
- input.foo.bar: <String>
- input.foo.baz: <Array Number>

Overridable fields (require `--override`):
- override.first
- override.second.subsecond.other
- override.second.subsecond.subsubsecond

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
source: cli/tests/snapshot/main.rs
expression: out
---
• contract: std.number.Integer
• default: 2
• documentation: Some documentation


0 comments on commit e9c48b6

Please sign in to comment.