Skip to content

Commit

Permalink
feat: override options on the CLI
Browse files Browse the repository at this point in the history
Pass --opt key=value to override any option on the command line

Signed-off-by: Yves Brissaud <[email protected]>
  • Loading branch information
eunomie committed Oct 9, 2024
1 parent 08ebcb0 commit c760f0a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 16 deletions.
10 changes: 10 additions & 0 deletions docs/reference/docker_runx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ options:
experimentalcli: false
kubernetes: false
swarm: false
- option: opt
value_type: stringArray
default_value: '[]'
description: Set an option value
deprecated: false
hidden: false
experimental: false
experimentalcli: false
kubernetes: false
swarm: false
deprecated: false
hidden: false
experimental: false
Expand Down
11 changes: 6 additions & 5 deletions docs/reference/runx.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ Docker Run, better

### Options

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


<!---MARKER_GEN_END-->
Expand Down
20 changes: 15 additions & 5 deletions internal/commands/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var (
docs bool
list bool
ask bool
opts []string
)

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

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

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

localOpts := getValuesLocal(src, action)

opts, err := prompt.Ask(runnable.Action, localOpts)
for _, opt := range opts {
if key, value, ok := strings.Cut(opt, "="); ok {
localOpts[key] = value
} else {
return fmt.Errorf("invalid option value %s", opt)
}
}

options, err := prompt.Ask(runnable.Action, localOpts)
if err != nil {
return err
}

if err = runnable.SetOptionValues(opts); err != nil {
if err = runnable.SetOptionValues(options); err != nil {
return err
}

Expand Down
10 changes: 4 additions & 6 deletions internal/runkit/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ import (
)

const (
RunxAnnotation = "vnd.docker.reference.type"
RunxManifestType = "runx-manifest"
RunxConfigType = "application/vnd.runx.config+yaml"
RunxDocType = "application/vnd.runx.readme+txt"
RunxFileNameAnnotation = "vnd.runx.filename"
RunxLayerFile = "application/vnd.runx.file.gzip"
RunxAnnotation = "vnd.docker.reference.type"
RunxManifestType = "runx-manifest"
RunxConfigType = "application/vnd.runx.config+yaml"
RunxDocType = "application/vnd.runx.readme+txt"
)

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

0 comments on commit c760f0a

Please sign in to comment.