Skip to content

Commit

Permalink
Add option to control the cache location.
Browse files Browse the repository at this point in the history
  • Loading branch information
n-g committed Jun 27, 2024
1 parent 90fe717 commit b8c110f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions internal/cli/fncobra/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ func doMain(opts MainOpts) (colors.Style, error) {
"If set to true, we also output debug log messages for API responses.")
rootCmd.PersistentFlags().BoolVar(&enableErrorTracing, "error_tracing", enableErrorTracing,
"If set to true, prints a trace of foundation errors leading to the root cause with source info.")
rootCmd.PersistentFlags().StringVar(&dirs.CacheDir, "cache_dir", dirs.CacheDir,
"Where to place cache contents.")

storedrun.SetupFlags(rootCmd.PersistentFlags())

Expand All @@ -178,6 +180,7 @@ func doMain(opts MainOpts) (colors.Style, error) {
"debug_to_console",
"debug_to_file",
"debug_api_response",
"cache_dir",
} {
_ = rootCmd.PersistentFlags().MarkHidden(noisy)
}
Expand Down
7 changes: 7 additions & 0 deletions internal/workspace/dirs/dirs.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@ import (
"strings"
)

var CacheDir string

func Cache() (string, error) {
if CacheDir != "" {
return filepath.Join(CacheDir, "ns"), nil
}

dir, err := os.UserCacheDir()
if err != nil {
return dir, err
}

return filepath.Join(dir, "ns"), nil
}

Expand Down

0 comments on commit b8c110f

Please sign in to comment.