DefineSource.script constructor

const DefineSource.script(
  1. String path, {
  2. List<String> args,
})

A Dart script in this worktree that prints the value, or a JSON array of values to choose from.

Knob('serverPort',
    from: ValueSource.script('tool/local_env.dart',
        args: ['port', 'server'])),

A script, not a command, because a command would have to name an executable and no config file can know which one. A dart on PATH is routinely older than the SDK the project pins — this repo's own is — so a config saying dart would be saying "whichever SDK happens to be first", which is not a thing anybody means. Run with the same dart that compiles and runs this config file, from the worktree root.

Selection belongs in args, not here. An earlier draft had a pick: naming a key in a JSON object the script printed; it would have grown a path syntax the first time somebody's output was nested. Passing the selection as an argument puts it in the tool that owns the data, where it can be a real function of that tool's model.

Run when the values are needed, not when the config is read: the answer to "which port is this worktree on" changes when the stack goes up or down, which is not a moment the config file knows about.

Implementation

const factory DefineSource.script(String path, {List<String> args}) =
    ScriptSource;