diff --git a/internal/commands/root/root.go b/internal/commands/root/root.go index 8025a60..a4884eb 100644 --- a/internal/commands/root/root.go +++ b/internal/commands/root/root.go @@ -1,7 +1,6 @@ package root import ( - "cmp" "context" "fmt" "io" @@ -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()) { @@ -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 { diff --git a/runkit/types.go b/runkit/types.go index caa924c..7c05e87 100644 --- a/runkit/types.go +++ b/runkit/types.go @@ -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"` } )