Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions x/config/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ help text; `require.Empty(t, b.Undocumented())` in a test catches that.

Help also names each flag's env vars, and marks `required` fields `(required)` unless they
sit in an optional (pointer) section. A default is shown as its type's `MarshalText` renders it, so
hold a secret in `pkg/config.SecretString` or `SecretURL` to show it redacted.
hold a secret in `pkg/config.SecretString` or `SecretURL` to show it redacted. A type with
`UnmarshalText` but no `MarshalText` shows its default as `<cannot display>`.

## What gets a flag

Expand All @@ -74,10 +75,9 @@ hold a secret in `pkg/config.SecretString` or `SecretURL` to show it redacted.
| list of those | `--tags a,b` or `--tags a --tags b` |
| map of those | `--labels env=prod,region=us` |

Map keys parse like values, so `map[uint32]string` binds as `--chains 1=mainnet`. In a config file,
where keys are text, a key type the markup reads whole is used as it is, and any other is parsed as
its flag would be; two texts that parse to one key, such as `16` and `0x10`, are an error. Anything more
structured is config file only.
Map keys parse like values, so `map[uint32]string` binds as `--chains 1=mainnet`. A config file's
keys are parsed as their flag would be, too; two texts that parse to one key, such as `16` and `0x10`,
are an error. Anything more structured is config file only.

Lists and maps are CSV; quote an element or whole entry containing a comma:

Expand All @@ -86,6 +86,8 @@ Lists and maps are CSV; quote an element or whole entry containing a comma:
--labels '"env=a,b",region=us' env=a,b and region=us
```

A map key can't contain `=`, since an entry splits at its first `=`; set such keys in a config file.

## Types

pflag parses every flag, including each list element and map value, so a bad value fails as the
Expand Down
10 changes: 4 additions & 6 deletions x/config/cli/binder.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/spf13/cobra"

"github.com/smartcontractkit/chainlink-common/x/config/commentparsing"
"github.com/smartcontractkit/chainlink-common/x/config/markup"
)

Expand Down Expand Up @@ -49,8 +48,8 @@ func New(opts Options) (*Binder, error) {
// Register attaches target to cmd. Before cmd or a subcommand runs, target is filled from flags, env vars, and config
// files, then its `validate` tags are checked.
//
// Scalars, durations, []byte, and [encoding.TextUnmarshaler] types get a persistent flag and env vars; other fields
// are config file only.
// Scalars, durations, []byte, [encoding.TextUnmarshaler] types, and lists and maps of those get a persistent flag and
// env vars; other fields are config file only.
Comment thread
nolag marked this conversation as resolved.
//
// A command runs with its ancestors' structs too, so they must not share a key, flag, or env var; siblings may. A clash
// fails every command in the tree when it is executed.
Expand Down Expand Up @@ -140,8 +139,7 @@ func (b *Binder) commandConfig(c *cobra.Command) (commandConfig, error) {
claimed := map[string]string{}
for _, e := range cc.entries {
for _, k := range e.keys() {
leaf := commentparsing.DerefType(k.goType)
if err := cc.keys.add(k.fileKey, leaf, lang); err != nil {
if err := cc.keys.add(k.fileKey, k.fileType, lang); err != nil {
return commandConfig{}, fmt.Errorf("%s: %w", e.command().Name(), err)
}

Expand Down Expand Up @@ -271,7 +269,7 @@ func (b *Binder) loadConfigFiles(cmd *cobra.Command, keys *keyNode) (reflect.Val
return fmt.Errorf("invalid %s: %w", name, err)
}

keys.overlay(merged, v.Elem())
keys.overlay(merged, v.Elem(), lang)
return nil
}

Expand Down
Loading
Loading