Skip to content

Commit c760f0a

Browse files
committed
feat: override options on the CLI
Pass --opt key=value to override any option on the command line Signed-off-by: Yves Brissaud <[email protected]>
1 parent 08ebcb0 commit c760f0a

File tree

4 files changed

+35
-16
lines changed

4 files changed

+35
-16
lines changed

docs/reference/docker_runx.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ options:
4545
experimentalcli: false
4646
kubernetes: false
4747
swarm: false
48+
- option: opt
49+
value_type: stringArray
50+
default_value: '[]'
51+
description: Set an option value
52+
deprecated: false
53+
hidden: false
54+
experimental: false
55+
experimentalcli: false
56+
kubernetes: false
57+
swarm: false
4858
deprecated: false
4959
hidden: false
5060
experimental: false

docs/reference/runx.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ Docker Run, better
1414

1515
### Options
1616

17-
| Name | Type | Default | Description |
18-
|:---------------|:-------|:--------|:------------------------------------------------------------------|
19-
| `--ask` | `bool` | | Do not read local configuration option values and always ask them |
20-
| `-d`, `--docs` | `bool` | | Print the documentation of the image |
21-
| `-l`, `--list` | `bool` | | List available actions |
17+
| Name | Type | Default | Description |
18+
|:---------------|:--------------|:--------|:------------------------------------------------------------------|
19+
| `--ask` | `bool` | | Do not read local configuration option values and always ask them |
20+
| `-d`, `--docs` | `bool` | | Print the documentation of the image |
21+
| `-l`, `--list` | `bool` | | List available actions |
22+
| `--opt` | `stringArray` | | Set an option value |
2223

2324

2425
<!---MARKER_GEN_END-->

internal/commands/root/root.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ var (
2828
docs bool
2929
list bool
3030
ask bool
31+
opts []string
3132
)
3233

3334
func NewCmd(dockerCli command.Cli, isPlugin bool) *cobra.Command {
@@ -99,9 +100,9 @@ func NewCmd(dockerCli command.Cli, isPlugin bool) *cobra.Command {
99100

100101
if list || action == "" {
101102
if tui.IsATTY(dockerCli.In().FD()) {
102-
action := prompt.SelectAction(rk.Config.Actions)
103-
if action != "" {
104-
return run(cmd.Context(), dockerCli.Err(), src, rk, action)
103+
selectedAction := prompt.SelectAction(rk.Config.Actions)
104+
if selectedAction != "" {
105+
return run(cmd.Context(), dockerCli.Err(), src, rk, selectedAction)
105106
}
106107
} else {
107108
_, _ = fmt.Fprintln(dockerCli.Out(), tui.Markdown(mdActions(rk)))
@@ -149,6 +150,7 @@ func NewCmd(dockerCli command.Cli, isPlugin bool) *cobra.Command {
149150
f.BoolVarP(&docs, "docs", "d", false, "Print the documentation of the image")
150151
f.BoolVarP(&list, "list", "l", false, "List available actions")
151152
f.BoolVar(&ask, "ask", false, "Do not read local configuration option values and always ask them")
153+
f.StringArrayVar(&opts, "opt", nil, "Set an option value")
152154

153155
return cmd
154156
}
@@ -180,12 +182,20 @@ func run(ctx context.Context, out io.Writer, src string, rk *runkit.RunKit, acti
180182

181183
localOpts := getValuesLocal(src, action)
182184

183-
opts, err := prompt.Ask(runnable.Action, localOpts)
185+
for _, opt := range opts {
186+
if key, value, ok := strings.Cut(opt, "="); ok {
187+
localOpts[key] = value
188+
} else {
189+
return fmt.Errorf("invalid option value %s", opt)
190+
}
191+
}
192+
193+
options, err := prompt.Ask(runnable.Action, localOpts)
184194
if err != nil {
185195
return err
186196
}
187197

188-
if err = runnable.SetOptionValues(opts); err != nil {
198+
if err = runnable.SetOptionValues(options); err != nil {
189199
return err
190200
}
191201

internal/runkit/image.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ import (
1010
)
1111

1212
const (
13-
RunxAnnotation = "vnd.docker.reference.type"
14-
RunxManifestType = "runx-manifest"
15-
RunxConfigType = "application/vnd.runx.config+yaml"
16-
RunxDocType = "application/vnd.runx.readme+txt"
17-
RunxFileNameAnnotation = "vnd.runx.filename"
18-
RunxLayerFile = "application/vnd.runx.file.gzip"
13+
RunxAnnotation = "vnd.docker.reference.type"
14+
RunxManifestType = "runx-manifest"
15+
RunxConfigType = "application/vnd.runx.config+yaml"
16+
RunxDocType = "application/vnd.runx.readme+txt"
1917
)
2018

2119
func Image(runxConfig, runxDoc []byte) (v1.Image, *v1.Descriptor, error) {

0 commit comments

Comments
 (0)