Skip to content

Commit

Permalink
feat: allow to override the image default action
Browse files Browse the repository at this point in the history
A default action can be defined inside the image runx manifest.
Allow to define a different one in the local .docker/runx.yaml file.

Signed-off-by: Yves Brissaud <[email protected]>
  • Loading branch information
eunomie committed Oct 9, 2024
1 parent 4a49b6f commit 7550b60
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
15 changes: 13 additions & 2 deletions internal/commands/root/root.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package root

import (
"cmp"
"context"
"fmt"
"io"
Expand Down Expand Up @@ -95,7 +94,7 @@ func NewCmd(dockerCli command.Cli, isPlugin bool) *cobra.Command {
return nil
}

action = cmp.Or(action, rk.Config.Default)
action = selectAction(action, lc.Images[src], rk.Config.Default)

if list || action == "" {
if tui.IsATTY(dockerCli.In().FD()) {
Expand Down Expand Up @@ -176,6 +175,18 @@ func run(ctx context.Context, out io.Writer, rk *runkit.RunKit, action string) e
return runnable.Run(ctx)
}

func selectAction(action string, conf runkit.ConfigImage, defaultAction string) string {
if action != "" {
return action
}

if conf.Default != "" {
return conf.Default
}

return defaultAction
}

func commandName(isPlugin bool) string {
name := constants.SubCommandName
if !isPlugin {
Expand Down
7 changes: 6 additions & 1 deletion runkit/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ type (
ActionType string

LocalConfig struct {
Ref string `yaml:"ref,omitempty" json:"ref,omitempty"`
Ref string `yaml:"ref,omitempty" json:"ref,omitempty"`
Images map[string]ConfigImage `yaml:"images,omitempty" json:"images,omitempty"`
}

ConfigImage struct {
Default string `yaml:"default,omitempty" json:"default,omitempty"`
}
)

Expand Down

0 comments on commit 7550b60

Please sign in to comment.