This repository has been archived by the owner on Jan 31, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from ipfs/address-feedback
feat: make env optional, prompt when not set
- Loading branch information
Showing
10 changed files
with
105 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package util | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"golang.org/x/term" | ||
) | ||
|
||
func Getenv(key, fallback string) string { | ||
if value, ok := os.LookupEnv(key); ok { | ||
return value | ||
} | ||
return fallback | ||
} | ||
|
||
func GetenvBool(key string) bool { | ||
return strings.ToLower(Getenv(key, "false")) == "true" | ||
} | ||
|
||
func GetenvPrompt(key string, prompt ...string) string { | ||
value := Getenv(key, "") | ||
for value == "" { | ||
if len(prompt) > 0 { | ||
fmt.Printf("%s is not set. %s: ", key, prompt[0]) | ||
} else { | ||
fmt.Printf("%s is not set. Please enter a value: ", key) | ||
} | ||
fmt.Scanln(&value) | ||
} | ||
return value | ||
} | ||
|
||
func GetenvPromptSecret(key string, prompt ...string) string { | ||
value := Getenv(key, "") | ||
for value == "" { | ||
if len(prompt) > 0 { | ||
fmt.Printf("%s is not set. %s: ", key, prompt[0]) | ||
} else { | ||
fmt.Printf("%s is not set. Please enter a secret value: ", key) | ||
} | ||
bytes, err := term.ReadPassword(int(os.Stdin.Fd())) | ||
if err != nil { | ||
panic(err) | ||
} | ||
fmt.Println() | ||
value = string(bytes) | ||
} | ||
return value | ||
} |