- cmd_build.go + cmd_project.go: core build accepts action-style overrides for build name, tags, obfuscate, NSIS, Deno frontend command, WebView2 mode, build-cache enable - --build-cache without explicit cache config seeds default cache layout (.core/cache, cache/go-build, cache/go-mod) before builder setup - release.yml: generated workflow exposes + forwards RFC controls so CI can use them without editing .core/build.yaml - Tests across cmd_project, cmd_workflow, workflow Verified: go test ./... passes Co-Authored-By: Virgil <virgil@lethean.io>
86 lines
1.8 KiB
Go
86 lines
1.8 KiB
Go
package cmdutil
|
|
|
|
import (
|
|
"context"
|
|
"strconv"
|
|
|
|
"dappco.re/go/core"
|
|
"dappco.re/go/core/cli/pkg/cli"
|
|
)
|
|
|
|
// ContextOrBackground returns the active CLI context when available.
|
|
func ContextOrBackground() context.Context {
|
|
if ctx, ok := currentCLIContext(); ok && ctx != nil {
|
|
return ctx
|
|
}
|
|
|
|
return context.Background()
|
|
}
|
|
|
|
func currentCLIContext() (ctx context.Context, ok bool) {
|
|
defer func() {
|
|
if recover() != nil {
|
|
ctx = nil
|
|
ok = false
|
|
}
|
|
}()
|
|
|
|
return cli.Context(), true
|
|
}
|
|
|
|
// OptionString returns the first non-empty option value for the provided keys.
|
|
func OptionString(opts core.Options, keys ...string) string {
|
|
for _, key := range keys {
|
|
if value := opts.String(key); value != "" {
|
|
return value
|
|
}
|
|
}
|
|
return ""
|
|
}
|
|
|
|
// OptionBoolDefault returns the parsed boolean value for the first matching key.
|
|
// Missing values fall back to defaultValue.
|
|
func OptionBoolDefault(opts core.Options, defaultValue bool, keys ...string) bool {
|
|
for _, key := range keys {
|
|
result := opts.Get(key)
|
|
if !result.OK {
|
|
continue
|
|
}
|
|
|
|
switch value := result.Value.(type) {
|
|
case bool:
|
|
return value
|
|
case string:
|
|
parsed, err := strconv.ParseBool(value)
|
|
if err == nil {
|
|
return parsed
|
|
}
|
|
}
|
|
}
|
|
|
|
return defaultValue
|
|
}
|
|
|
|
// OptionBool returns the parsed boolean value for the first matching key.
|
|
func OptionBool(opts core.Options, keys ...string) bool {
|
|
return OptionBoolDefault(opts, false, keys...)
|
|
}
|
|
|
|
// OptionHas reports whether any of the provided keys was supplied.
|
|
func OptionHas(opts core.Options, keys ...string) bool {
|
|
for _, key := range keys {
|
|
if opts.Has(key) {
|
|
return true
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
// ResultFromError adapts a Go error into a Core result.
|
|
func ResultFromError(err error) core.Result {
|
|
if err != nil {
|
|
return core.Result{Value: err, OK: false}
|
|
}
|
|
return core.Result{OK: true}
|
|
}
|