-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Allow cli input for variables * chore: example update
- Loading branch information
1 parent
879c5b4
commit f3cc23a
Showing
4 changed files
with
51 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package setters | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"io" | ||
"os" | ||
"strings" | ||
) | ||
|
||
const CLI_ENVIRONMENT_SETTER_KEY = "from_cli" | ||
|
||
// CLIEnvironmentSetter will pull an env var from the provided io.Reader (stdin) | ||
type CLIEnvironmentSetter struct { | ||
Key string | ||
Value string | ||
} | ||
|
||
func NewCLIEnvironmentSetter(key string, rd io.Reader) (*CLIEnvironmentSetter, error) { | ||
// Get the value from the io.Reader | ||
fmt.Printf("%s: ", key) | ||
reader := bufio.NewReader(rd) | ||
val, err := reader.ReadString('\n') | ||
if err != nil { | ||
return nil, err | ||
} | ||
val = strings.Replace(val, "\n", "", -1) // Remove any newline characters | ||
|
||
// Save and return the setter | ||
return &CLIEnvironmentSetter{ | ||
Key: key, | ||
Value: val, | ||
}, nil | ||
} | ||
|
||
func (s CLIEnvironmentSetter) SetEnv() error { | ||
return os.Setenv(s.Key, s.Value) | ||
} |
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