diff --git a/src/cli/cli.go b/src/cli/cli.go index 412c5654..acd2a189 100644 --- a/src/cli/cli.go +++ b/src/cli/cli.go @@ -313,18 +313,11 @@ func send(c *cli.Context) (err error) { return } - cr, err := croc.New(crocOptions) - if err != nil { - return - } - - // save the config - saveConfig(c, crocOptions) - // if operating system is UNIX, then use environmental variable to set the code if runtime.GOOS == "linux" { - cr.Options.SharedSecret = os.Getenv("CROC_SECRET") - if cr.Options.SharedSecret == "" { + log.Debug("forcing code phrase from environmental variable") + crocOptions.SharedSecret = os.Getenv("CROC_SECRET") + if crocOptions.SharedSecret == "" { fmt.Printf(`To use croc you need to set a code phrase using your environmental variables: export CROC_SECRET="yourcodephrasetouse" @@ -333,6 +326,14 @@ export CROC_SECRET="yourcodephrasetouse" } } + cr, err := croc.New(crocOptions) + if err != nil { + return + } + + // save the config + saveConfig(c, crocOptions) + err = cr.Send(minimalFileInfos, emptyFoldersToTransfer, totalNumberFolders) return @@ -525,6 +526,17 @@ func receive(c *cli.Context) (err error) { return err } } + // if operating system is UNIX, then use environmental variable to set the code + if runtime.GOOS == "linux" { + crocOptions.SharedSecret = os.Getenv("CROC_SECRET") + if crocOptions.SharedSecret == "" { + fmt.Printf(`To use croc you need to set a code phrase using your environmental variables: + + export CROC_SECRET="yourcodephrasetouse" + `) + os.Exit(0) + } + } cr, err := croc.New(crocOptions) if err != nil { @@ -548,18 +560,6 @@ func receive(c *cli.Context) (err error) { log.Debugf("wrote %s", configFile) } - // if operating system is UNIX, then use environmental variable to set the code - if runtime.GOOS == "linux" { - cr.Options.SharedSecret = os.Getenv("CROC_SECRET") - if cr.Options.SharedSecret == "" { - fmt.Printf(`To use croc you need to set a code phrase using your environmental variables: - - export CROC_SECRET="yourcodephrasetouse" - `) - os.Exit(0) - } - } - err = cr.Receive() return }