From ee713c5146e1ae8cd59c76d3d146c1e86b38cfd6 Mon Sep 17 00:00:00 2001 From: Zack Date: Thu, 23 May 2024 08:27:52 -0700 Subject: [PATCH 1/2] improve ux around receiving --- src/cli/cli.go | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/cli/cli.go b/src/cli/cli.go index 14c4265c..40c165a4 100644 --- a/src/cli/cli.go +++ b/src/cli/cli.go @@ -507,7 +507,26 @@ func receive(c *cli.Context) (err error) { crocOptions.OnlyLocal = rememberedOptions.OnlyLocal } } + if crocOptions.SharedSecret == "" && os.Getenv("CROC_SECRET") != "" { + crocOptions.SharedSecret = os.Getenv("CROC_SECRET") + } else if runtime.GOOS == "linux" && crocOptions.SharedSecret != "" { + crocOptions.SharedSecret = os.Getenv("CROC_SECRET") + if crocOptions.SharedSecret == "" { + fmt.Printf(`On linux, to receive with croc you either need +to set a code phrase using your environmental variables: + + export CROC_SECRET="****" + croc +Or you can specify the code phrase when you run croc without +declaring the secret on the command line: + + croc + Enter receive code: **** + `) + os.Exit(0) + } + } if crocOptions.SharedSecret == "" { l, err := readline.NewEx(&readline.Config{ Prompt: "Enter receive code: ", @@ -526,17 +545,6 @@ 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 { From 66f0d1264a728593307ca49810452ef2cd555c68 Mon Sep 17 00:00:00 2001 From: Zack Date: Thu, 23 May 2024 08:33:00 -0700 Subject: [PATCH 2/2] improve the ux around sending --- src/cli/cli.go | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/cli/cli.go b/src/cli/cli.go index 40c165a4..99a976a6 100644 --- a/src/cli/cli.go +++ b/src/cli/cli.go @@ -304,6 +304,25 @@ func send(c *cli.Context) (err error) { return errors.New("must specify file: croc send [filename(s) or folder]") } + // if operating system is UNIX, then use environmental variable to set the code + if (runtime.GOOS == "linux" && c.IsSet("code")) || os.Getenv("CROC_SECRET") != "" { + crocOptions.SharedSecret = os.Getenv("CROC_SECRET") + if crocOptions.SharedSecret == "" { + fmt.Printf(`On linux, to send with a custom code phrase, +you need to set the environmental variable CROC_SECRET: + + export CROC_SECRET="****" + croc send file.txt + +Or you can have the code phrase automaticlaly generated: + + croc send file.txt + +`) + os.Exit(0) + } + } + if len(crocOptions.SharedSecret) == 0 { // generate code phrase crocOptions.SharedSecret = utils.GetRandomName() @@ -313,19 +332,6 @@ func send(c *cli.Context) (err error) { return } - // if operating system is UNIX, then use environmental variable to set the code - if runtime.GOOS == "linux" { - 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" - `) - os.Exit(0) - } - } - cr, err := croc.New(crocOptions) if err != nil { return @@ -507,6 +513,7 @@ func receive(c *cli.Context) (err error) { crocOptions.OnlyLocal = rememberedOptions.OnlyLocal } } + if crocOptions.SharedSecret == "" && os.Getenv("CROC_SECRET") != "" { crocOptions.SharedSecret = os.Getenv("CROC_SECRET") } else if runtime.GOOS == "linux" && crocOptions.SharedSecret != "" {