From d523b67e5eee6d752d944a062c6377c4ea5d4505 Mon Sep 17 00:00:00 2001 From: rsteube Date: Thu, 27 Oct 2022 00:04:09 +0200 Subject: [PATCH] fix tmp folder creation on each invocation --- scrape.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/scrape.go b/scrape.go index 0630671..a6b3ea8 100644 --- a/scrape.go +++ b/scrape.go @@ -11,17 +11,16 @@ import ( "github.com/spf13/pflag" ) -var tmpDir string = getTmpDir() - -func getTmpDir() string { +func Scrape(cmd *cobra.Command) { dir, err := os.MkdirTemp(os.TempDir(), "carascrape") if err != nil { panic(err.Error()) } - return dir + + scrape(cmd, dir) } -func Scrape(cmd *cobra.Command) { +func scrape(cmd *cobra.Command, tmpDir string) { out := &bytes.Buffer{} if len(cmd.Aliases) > 0 { @@ -110,7 +109,7 @@ var %vCmd = &cobra.Command{ for _, subcmd := range cmd.Commands() { if !subcmd.Hidden && subcmd.Deprecated == "" { - Scrape(subcmd) + scrape(subcmd, tmpDir) } } }