Open
Description
- do not touch the config file if no mutations are present, print the config file instead
- printing the config file should support customizing the output format. (toml, json, human?)
- we need hints! what can we edit and what are the valid values?
- examples in
--help
, and examples in documentation
Some more context, originally posted to #1259 (review):
Flags:
--print [ default | toml | json ]
the output format (defaults to `default`)
-s, --save [to]
save modifications (if any), print a warning to stderr if there are no changes
Printing
- Specifying no keys will print the full config
- Specifying keys will print just the value for those keys
--print default
proxies totoml
$ merod config
(print the full config in the default printing format: toml)
$ merod config --print json
(print the full config in json)
$ merod config sync server.admin
[server.admin]
enabled = true
[sync]
timeout_ms = 30000
interval_ms = 30000
$ merod config sync server.admin --print json
{
"server": {
"admin": {
"enabled": true
}
},
"sync": {
"interval_ms": 30000,
"timeout_ms": 30000
}
}
Editing
- Specifying an item in the format
<key>=<value>
will;- Edit the values in-memory
- Deserialize it to the config file to perform validation
- Show a diff between the old and new values
- if
-s, --save
is specified and there are edits, save the config file
- We do not save by default, instead, it's more of presenting a confirmation to the user
--print default
prints the diff,toml
andjson
prints the full config in the respective representations- Consider printing
diff(1)
-style diffs, which may be facilitated bysimilar
$ merod config discovery.mdns=false sync.interval_ms=50000 sync.timeout_ms=50000
[discovery]
-mdns = true
+mdns = false
[sync]
-interval_ms = 30000
+interval_ms = 50000
-timeout_ms = 30000
+timeout_ms = 50000
note: if this looks right, use `-s, --save` to persist these modifications
$ merod config discovery.mdns=false sync.interval_ms=50000 sync.timeout_ms=50000 --print json
{...snip...
note: if this looks right, use `-s, --save` to persist these modifications
the note
should be in stderr
Hints
- Specifying any key in the format
<key>?
will print the schema for that key in the config - If any other keys are specified with values, it will NOT be saved, nor should their schema be printed
- We only print the schema one level deep
--print default
prints the human readable format, withtoml
andjson
printing their respective representations- Colors here will help make this more readable, alternatively, a table will do just fine too
- Might be facilitated by
JSONSchema
or however else (!! no hard-coding, that'll be a maintenance nightmare)
$ merod config discovery.mdns=true discovery? discovery.relay?
discovery: object # Discovery configuration
.mdns: boolean # Enable local discovery
.rendezvous: object # Rendezvous configuration
.relay: object # Relay configuration
discovery.relay: object # Relay configuration
.registrations_limit: object # Max number of active relay registrations to maintain
here, the discovery.mdns=true
directive is ignored because there's at least one hint request, maybe we print a warning to stderr indicating that