Extract daemon logic from cmd/daemon/ into internal/daemon/ package and create a new unified CLI entry point at cmd/multica/ using cobra. The CLI supports `daemon` as a long-running subcommand plus ctrl subcommands for agent/runtime management, config, status, and version. Server, migrate, and seed binaries remain unchanged. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
21 lines
447 B
Go
21 lines
447 B
Go
package cli
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// FlagOrEnv returns the flag value if set, otherwise the environment variable value,
|
|
// otherwise the fallback.
|
|
func FlagOrEnv(cmd *cobra.Command, flagName, envKey, fallback string) string {
|
|
if cmd.Flags().Changed(flagName) {
|
|
val, _ := cmd.Flags().GetString(flagName)
|
|
return val
|
|
}
|
|
if v := strings.TrimSpace(os.Getenv(envKey)); v != "" {
|
|
return v
|
|
}
|
|
return fallback
|
|
}
|