Skip to content

Commit d66d0dc

Browse files
fix: rootCmd args parsed as directory path — breaks watch cache loading (#109)
* fix: rootCmd args parsed as directory path — breaks watch cache loading rootCmd accepted MaximumNArgs(1) and used args[0] as the working directory. Since watch is the default behavior on rootCmd (not a subcommand), running `supermodel` with any trailing token would use that token as the directory. This caused the daemon to create and read from a wrong directory (e.g. ./watch/.supermodel/shards.json instead of ./.supermodel/shards.json). Fix: switch to NoArgs and add an explicit --dir flag. This matches the pattern used by all other subcommands that accept a directory. Fixes #108 * fix: remove stale [path] from Use string per CodeRabbit
1 parent 161c66e commit d66d0dc

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

cmd/root.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var noConfigCommands = map[string]bool{
3131
}
3232

3333
var rootCmd = &cobra.Command{
34-
Use: "supermodel [path]",
34+
Use: "supermodel",
3535
Short: "Give your AI coding agent a map of your codebase",
3636
Long: `Runs a full generate on startup (using cached graph if available), then
3737
enters daemon mode. Listens for file-change notifications from the
@@ -40,7 +40,7 @@ enters daemon mode. Listens for file-change notifications from the
4040
Press Ctrl+C to stop and remove graph files.
4141
4242
See https://supermodeltools.com for documentation.`,
43-
Args: cobra.MaximumNArgs(1),
43+
Args: cobra.NoArgs,
4444
SilenceUsage: true,
4545
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
4646
// Walk up to the root command name to get the subcommand.
@@ -68,10 +68,7 @@ See https://supermodeltools.com for documentation.`,
6868
if err := cfg.RequireAPIKey(); err != nil {
6969
return err
7070
}
71-
dir := "."
72-
if len(args) > 0 {
73-
dir = args[0]
74-
}
71+
dir := watchDir
7572
opts := shards.WatchOptions{
7673
CacheFile: watchCacheFile,
7774
Debounce: watchDebounce,
@@ -84,6 +81,7 @@ See https://supermodeltools.com for documentation.`,
8481
}
8582

8683
var (
84+
watchDir string
8785
watchCacheFile string
8886
watchDebounce time.Duration
8987
watchNotifyPort int
@@ -92,6 +90,7 @@ var (
9290
)
9391

9492
func init() {
93+
rootCmd.Flags().StringVar(&watchDir, "dir", ".", "project directory")
9594
rootCmd.Flags().StringVar(&watchCacheFile, "cache-file", "", "override cache file path")
9695
rootCmd.Flags().DurationVar(&watchDebounce, "debounce", 2*time.Second, "debounce duration before processing changes")
9796
rootCmd.Flags().IntVar(&watchNotifyPort, "notify-port", 7734, "UDP port for hook notifications")

0 commit comments

Comments
 (0)