refactor: migrate docker-options subcommands to go
Ports the user-facing CLI subcommands and lifecycle triggers from bash to go, mirroring the layout used by the ports plugin. The on-disk format (`DOCKER_OPTIONS_BUILD/DEPLOY/RUN` files), the `docker-args-build/deploy/run` triggers, and every exported helper consumed by other plugins are unchanged. Reserves the `--process` and `--global` flags on add, remove, and clear so usage today exits with a not-yet-implemented error and the surface is locked in ahead of the process-scoping work tracked in #2441.
This commit is contained in:
45
plugins/docker-options/internal-functions.go
Normal file
45
plugins/docker-options/internal-functions.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package dockeroptions
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var availablePhases = []string{"build", "deploy", "run"}
|
||||
|
||||
func parsePhases(phasesArg string) ([]string, error) {
|
||||
if phasesArg == "" {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
phases := strings.Split(phasesArg, ",")
|
||||
for _, phase := range phases {
|
||||
valid := false
|
||||
for _, allowed := range availablePhases {
|
||||
if phase == allowed {
|
||||
valid = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !valid {
|
||||
return nil, fmt.Errorf("Phase(s) must be one of [%s]", strings.Join(availablePhases, " "))
|
||||
}
|
||||
}
|
||||
|
||||
return phases, nil
|
||||
}
|
||||
|
||||
// ErrIfReservedFlagsUsed returns a not-yet-implemented error when --process or --global are passed.
|
||||
// Both flags are reserved for the upcoming process-scoped docker options work (issue #2441).
|
||||
func ErrIfReservedFlagsUsed(processes []string, global bool) error {
|
||||
if len(processes) == 0 && !global {
|
||||
return nil
|
||||
}
|
||||
|
||||
if len(processes) > 0 && global {
|
||||
return errors.New("--process and --global flags are mutually exclusive")
|
||||
}
|
||||
|
||||
return errors.New("--process and --global flags are reserved for a future release and not yet implemented")
|
||||
}
|
||||
Reference in New Issue
Block a user