@@ -4,14 +4,16 @@ Copyright © 2026 laggu
44package cmd
55
66import (
7+ "fmt"
8+
9+ "github.com/laggu/git-volume/internal/gitvolume"
710 "github.com/spf13/cobra"
811)
912
1013// Global flags
1114var (
12- cfgFile string
13- verbose bool
14- quiet bool
15+ cfgFile string
16+ verbosity int
1517)
1618
1719// rootCmd represents the base command when called without any subcommands
@@ -22,16 +24,32 @@ var rootCmd = &cobra.Command{
2224by dynamically mounting them using a git-volume.yaml manifest.
2325
2426"Keep code in Git, mount environments as volumes."` ,
27+ PersistentPreRunE : func (cmd * cobra.Command , args []string ) error {
28+ if verbosity < gitvolume .VerbosityQuiet || verbosity > gitvolume .VerbosityDetailed {
29+ return fmt .Errorf ("invalid --verbose level %d (allowed: 0, 1, 2)" , verbosity )
30+ }
31+
32+ return nil
33+ },
2534}
2635
2736// Execute adds all child commands to the root command and sets flags appropriately.
2837func Execute () error {
2938 return rootCmd .Execute ()
3039}
3140
41+ func commandOptions (useConfig bool ) gitvolume.Options {
42+ opts := gitvolume.Options {Verbosity : verbosity }
43+ if useConfig {
44+ opts .ConfigPath = cfgFile
45+ }
46+ return opts
47+ }
48+
3249func init () {
3350 rootCmd .PersistentFlags ().StringVarP (& cfgFile , "config" , "c" , "" , "config file path (default: auto-detected)" )
34- rootCmd .PersistentFlags ().BoolVarP (& verbose , "verbose" , "v" , false , "verbose output" )
35- rootCmd .PersistentFlags ().BoolVarP (& quiet , "quiet" , "q" , false , "suppress non-error output" )
36- rootCmd .MarkFlagsMutuallyExclusive ("verbose" , "quiet" )
51+ rootCmd .PersistentFlags ().IntVarP (& verbosity , "verbose" , "v" , gitvolume .VerbosityNormal , "verbosity level (0=errors only, 1=normal, 2=detailed)" )
52+ if flag := rootCmd .PersistentFlags ().Lookup ("verbose" ); flag != nil {
53+ flag .NoOptDefVal = "2"
54+ }
3755}
0 commit comments