-
Notifications
You must be signed in to change notification settings - Fork 90
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
CLI arguments to pass data to and retrieve data from Nickel configurations #1408
Comments
If you want to encourage the partial record style, make the record generate new argument flags $ nickel export -f base.ncl --my-record-field=foo Whereas function arguments and overrides can be gated behind a special (possibly slightly verbose) flag $ nickel export -f base.ncl --argument "my-function-arg=foo" Something of the sort. |
Shouldn't they be guarded by a prefix, at least? Otherwise they could clash with existing CLI argument (for example, currently you can precise |
Maybe, but it's not obvious how to make such a prefix “feel native”. Think about it: how reluctant are you to use Another requirement is that completion works on these arguments (at least with Bash). Also that they can be typed unescaped on major shells (Bash, Zsh, Fish, at least) Several options that I can think of (there may be more):
|
An idea that I haven't fully thought through but that seems interesting: It would be cool if everything after a certain flag (
would be a fully independent cli that shows help (on empty or with |
I think I really like the idea, in conjunction with @MMesch 's proposal. You would type |
Hello, I'm sorry if this was mentioned before, I figure it'll simpler to ask directly than to read all issue/PR comments: Where it would look like: $ nickel export -f config-gcc.ncl -- --help
...
$ nickel export -f config-gcc.ncl -- path_libc=/new/path --override optimization_level=1 Apart from the fact that mixing WDYT? We could go a little further, as now kv are not flags we can remove the $ nickel export -f config-gcc.ncl path_libc='"/new/path"' --override optimization_level=1 And a little further againBy separating all overrides after $ nickel export -f config-gcc.ncl path_libc='"/new/path"' other_config='"foo"' --overrides override1=1 override2=2 For passing values, there is also the terraform way with their Another thing nickel or the language could provide is 'parsers' from CLI, where giving WDYT? |
Also, as mentioned in #1475 This issue should remain open until there is a way to extract specific fields? |
Hi @bew , sorry, I missed this notification (I wonder if it actually notifies when commenting on a closed issue?).
Absolutely, this was just GitHub being zealous.
We were probably biased toward a classical command line format because clap would provide us with several things for free (help message, error message when the parsing is wrong, error message when a required field isn't there, etc.), making the initial implementation easier. That being said, this isn't set in stone - the customize mode is explicitly unstable - and your proposal does solve the name conflict issue, as well as being somehow consistent with Nickel syntax. Those are great suggestions, thanks for that! We'll discuss it in the next weekly meeting. As well as your proposed extensions. We'll just have to make sure it's compatible with the potential evolution of the CLI (for example, we would like to move from the default behavior being to do evaluation to having a dedicated About environment variables, that might be useful in some settings - I wouldn't replace the current customize mode with it, but it's possible to have in addition to the argument way.
I'm less of a fan of this proposal. I do agree that escaping strings on the CLI is annoying, but we have to consider consistency and principle of least surprise. Now, if you write |
As an update, we agreed that (at the least the first part of) @bew's proposal is a better way forward. We just need to find the bandwith to implement it now. |
Is your feature request related to a problem? Please describe.
It often happens that some configuration values are not known when writing Nickel code but only when we finally run the
nickel
CLI invocation. Or that those values vary. See for example #1202 and #413. Another related example is secrets (an SSH key or other credentials) that you don't want to hardcode into the configuration but to pass either via the CLI or environment variables.We might also want to override quickly the field of an existing configuration on-the-fly, without having to write a separate file which just imports the old one and do the override.
Similarly, it may happen that the configuration we want to extract is just part of a larger one: we need
<config>.ubuntu.system
exported to a YAML file.Currently, the only existing solution to do those kind of things is to inject Nickel code in the
nickel
invocation: for example:Describe the solution you'd like
While possible today, those operations aren't very elegant. They require to generate Nickel code with boilerplate (importing the original file, and applying whatever operations needed, such as merging), and can also have security implications: if a field is set to a value coming from an external source, the Nickel part is subject to Nickel injections (see #1202).
The proposal to add new CLI arguments to ease such operations: the overall goal is to make Nickel configuration composable with respect to shell operations, not only between Nickel configurations themselves.
Typically, one would have at least one argument to set a value of a configuration and one to select one output of the configuration:
Bikeshedding
There are several things to consider:
--arg
,--input
,--param
,--set
,--set-field
for arguments--access
,--select
,--field
,--path
,--field-path
for outputMy very personal view is that we should encourage the recursive records (aka partial configurations) approach, and thus support in priority passing data to records rather than to functions (also, this has the advantage of forcing users to name such inputs, while functions can be purely positional). And that we should differentiate between "passing an argument from the CLI" and "overriding an existing value", so we should have an additional
--override
CLI argument (if needed).The text was updated successfully, but these errors were encountered: