feat(cli): support --version and -v flags on root command

Use Cobra's built-in version support so `multica --version` and
`multica -v` print the same output as `multica version`.

Closes MUL-743
This commit is contained in:
Jiayuan Zhang
2026-04-14 21:12:53 +08:00
parent 2ecddc8fc8
commit ad5dd453be

View File

@@ -3,6 +3,7 @@ package main
import (
"fmt"
"os"
"runtime"
"github.com/spf13/cobra"
)
@@ -22,6 +23,9 @@ var rootCmd = &cobra.Command{
}
func init() {
rootCmd.Version = fmt.Sprintf("%s (commit: %s, built: %s)\ngo: %s, os/arch: %s/%s", version, commit, date, runtime.Version(), runtime.GOOS, runtime.GOARCH)
rootCmd.SetVersionTemplate("multica {{.Version}}\n")
rootCmd.PersistentFlags().String("server-url", "", "Multica server URL (env: MULTICA_SERVER_URL)")
rootCmd.PersistentFlags().String("workspace-id", "", "Workspace ID (env: MULTICA_WORKSPACE_ID)")
rootCmd.PersistentFlags().String("profile", "", "Configuration profile name (e.g. dev) — isolates config, daemon state, and workspaces")