diff --git a/pkg/core/cli.go b/pkg/core/cli.go index be8c91e..ede519d 100644 --- a/pkg/core/cli.go +++ b/pkg/core/cli.go @@ -16,7 +16,6 @@ package core import ( "io" "os" - "strings" ) // Cli is the CLI surface for the Core command tree. @@ -89,7 +88,7 @@ func (cl *Cli) Run(args ...string) Result[any] { } else { opts = append(opts, Option{K: key, V: true}) } - } else if !strings.HasPrefix(arg, "-") { + } else if !IsFlag(arg) { opts = append(opts, Option{K: "_arg", V: arg}) } } diff --git a/pkg/core/utils.go b/pkg/core/utils.go index 7fa5d81..99c9a8b 100644 --- a/pkg/core/utils.go +++ b/pkg/core/utils.go @@ -31,6 +31,15 @@ func JoinPath(segments ...string) string { return strings.Join(segments, "/") } +// IsFlag returns true if the argument starts with a dash. +// +// core.IsFlag("--verbose") // true +// core.IsFlag("-v") // true +// core.IsFlag("deploy") // false +func IsFlag(arg string) bool { + return strings.HasPrefix(arg, "-") +} + // FilterArgs removes empty strings and Go test runner flags from an argument list. // // clean := core.FilterArgs(os.Args[1:])