8000 `merod config` revamp · Issue #1069 · calimero-network/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
merod config revamp #1069
Open
Open
@miraclx

Description

@miraclx
  1. do not touch the config file if no mutations are present, print the config file instead
  2. printing the config file should support customizing the output format. (toml, json, human?)
  3. we need hints! what can we edit and what are the valid values?
  4. 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 to toml
$ 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;
    1. Edit the values in-memory
    2. Deserialize it to the config file to perform validation
    3. Show a diff between the old and new values
    4. 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 and json prints the full config in the respective representations
  • Consider printing diff(1)-style diffs, which may be facilitated by similar
$ 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, with toml and json 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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0