Skip to content

Commit a64cd68

Browse files
authored
refactor: unify verbosity levels and remove quiet flag (#30) (#30)
* refactor: unify verbosity levels and remove quiet flag (#30) * fix: remove unused verbosity helper for lint
1 parent 0d7d504 commit a64cd68

38 files changed

Lines changed: 148 additions & 130 deletions

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ go mod download
2828
## 아키텍처
2929

3030
### CLI 구조 (Cobra 기반)
31-
- `cmd/root.go` - 루트 명령어 및 전역 플래그 (`--config`, `--verbose`, `--quiet`)
31+
- `cmd/root.go` - 루트 명령어 및 전역 플래그 (`--config`, `--verbose`)
3232
- `cmd/*.go` - 각 서브커맨드 (init, sync, unsync, list, add, version)
3333

3434
### 핵심 패키지 (`internal/gitvolume`)

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,7 @@ volumes:
144144
| ----------------- | ---------------- | ---------------------------------------------- |
145145
| `--dry-run` | `sync`, `unsync` | Show what would be done without making changes |
146146
| `--relative` | `sync` | Create relative symlinks instead of absolute |
147-
| `--verbose`, `-v` | All | Verbose output |
148-
| `--quiet`, `-q` | All | Suppress non-error output |
147+
| `--verbose`, `-v` | All | Verbosity level: 0=errors only, 1=normal (default), 2=detailed |
149148
| `--config`, `-c` | All | Custom config file path |
150149

151150
## 🛡️ Safety Features

cmd/global.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var globalListCmd = &cobra.Command{
2626
Long: `Displays a tree of all files currently stored in the global git-volume directory.`,
2727
SilenceUsage: true,
2828
RunE: func(cmd *cobra.Command, args []string) error {
29-
gv, err := gitvolume.New(gitvolume.Options{Quiet: quiet})
29+
gv, err := gitvolume.New(commandOptions(false))
3030
if err != nil {
3131
return err
3232
}

cmd/global_add.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Examples:
3434
Args: cobra.MinimumNArgs(1),
3535
SilenceUsage: true,
3636
RunE: func(cmd *cobra.Command, args []string) error {
37-
gv, err := gitvolume.New(gitvolume.Options{Quiet: quiet})
37+
gv, err := gitvolume.New(commandOptions(false))
3838
if err != nil {
3939
return err
4040
}

cmd/global_edit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Examples:
2121
Args: cobra.ExactArgs(1),
2222
SilenceUsage: true,
2323
RunE: func(cmd *cobra.Command, args []string) error {
24-
gv, err := gitvolume.New(gitvolume.Options{Quiet: quiet})
24+
gv, err := gitvolume.New(commandOptions(false))
2525
if err != nil {
2626
return err
2727
}

cmd/global_remove.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Examples:
2121
SilenceUsage: true,
2222
Aliases: []string{"rm"},
2323
RunE: func(cmd *cobra.Command, args []string) error {
24-
gv, err := gitvolume.New(gitvolume.Options{Quiet: quiet})
24+
gv, err := gitvolume.New(commandOptions(false))
2525
if err != nil {
2626
return err
2727
}

cmd/init.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var initCmd = &cobra.Command{
1616
git-volume.yaml configuration file in the current directory.`,
1717
SilenceUsage: true,
1818
RunE: func(cmd *cobra.Command, args []string) error {
19-
gv, err := gitvolume.New(gitvolume.Options{Quiet: quiet})
19+
gv, err := gitvolume.New(commandOptions(false))
2020
if err != nil {
2121
return err
2222
}

cmd/root.go

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ Copyright © 2026 laggu
44
package cmd
55

66
import (
7+
"fmt"
8+
9+
"github.com/laggu/git-volume/internal/gitvolume"
710
"github.com/spf13/cobra"
811
)
912

1013
// Global flags
1114
var (
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{
2224
by 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.
2837
func 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+
3249
func 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
}

cmd/status.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ var statusCmd = &cobra.Command{
1414
Short: "Show the status of all volumes",
1515
SilenceUsage: true,
1616
RunE: func(cmd *cobra.Command, args []string) error {
17-
gv, err := gitvolume.New(gitvolume.Options{
18-
ConfigPath: cfgFile,
19-
Quiet: quiet,
20-
})
17+
gv, err := gitvolume.New(commandOptions(true))
2118
if err != nil {
2219
return err
2320
}

cmd/sync.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@ It checks the current directory for git-volume.yaml first. If not found,
2424
it looks for it in the main Git worktree (inheritance).`,
2525
SilenceUsage: true,
2626
RunE: func(cmd *cobra.Command, args []string) error {
27-
gv, err := gitvolume.New(gitvolume.Options{
28-
ConfigPath: cfgFile,
29-
Verbose: verbose,
30-
Quiet: quiet,
31-
})
27+
gv, err := gitvolume.New(commandOptions(true))
3228
if err != nil {
3329
return err
3430
}

0 commit comments

Comments
 (0)