summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--configureENV.go101
2 files changed, 4 insertions, 98 deletions
diff --git a/.gitignore b/.gitignore
index 34cfcd8..5a341c6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
go.*
+*.swp
diff --git a/configureENV.go b/configureENV.go
index b5358ad..9df536b 100644
--- a/configureENV.go
+++ b/configureENV.go
@@ -3,113 +3,18 @@ package fhelp
import (
"os"
"path/filepath"
-
- "go.wit.com/log"
)
-// BEFORE YOU READ ANYTHING UNDERSTAND THIS IS THE DEFAULT:
+// THIS IS THE DEFAULT:
//
// ~/.config/ # put things you might care about here
// ~/.cache/ # this is never imporant and can be deleted at any time
//
-//
// Additionally:
//
-// NEVER WRITE OUT ANYTHING TO ~/ EVER. The ONLY DIRECTORIES YOU ARE EVER ALLOWED TO USE ARE ~/.config and ~/.cache/ (maybe ~/.local but really, why?)
-//
-// There are no exceptions to this unless you are a jerk or don't know better (in which you will be easily forgiven -- don't worry. there isn't a manual)
-//
-//
-// ADVICE FOR ALL FUTURE PROGRAMMERS:
-//
-//
-// Config files are a perfect way to stop things from proceeding. You do NOT want options in your programs. Configuration options, if you do
-// things correctly, should never actually be needed. Nonetheless, there are initial states. ISOLATE ALL OPTIONS TO THE ITIAL STATES.
-// then, never let anthing change anything. If your code is correct, then all is good.
-//
-//
-// This defines the "default" behavior for forge when doing GO lang development
+// NEVER WRITE OUT ANYTHING TO ~/
+// NEVER EVER
//
-// Since this code is common, it's in a seperate package so it can be used elsewhere
-//
-// The default behavior is:
-//
-// * If your current directory or parent directory has a go.work file, make that your default spot
-// * Otherwise, set the default to ~/go/src
-//
-// This routine ensures the following ENV vars are set:
-//
-// FORGE_REPOSPB == where the repos.pb protobuf cache file is stored (normally ~/.cache/forge/repos.pb)
-// FORGE_GOSRC == based on the path, what the user probably want for developing in GO (Defaults to ~/go/src)
-// FORGE_GOWORK == true or false depending on the GOSRC result
-//
-// returns:
-// string # ~/go/src or the path to the go.work file
-// bool # true if the user is using a go.work file
-// err # if everything goes wrong, the error
-//
-
-func ConfigureENV() error {
- err := doConfigureENV()
- if os.Getenv("FORGE_VERBOSE") == "true" {
- DumpENV("fhelp:")
- }
- return err
-}
-
-func DumpENV(what string) {
- log.Printf("%s FORGE_REPOSDIR = %s\n", what, os.Getenv("FORGE_REPOSDIR"))
- log.Printf("%s FORGE_REPOSPB = %s\n", what, os.Getenv("FORGE_REPOSPB"))
- log.Printf("%s FORGE_PATCHDIR = %s\n", what, os.Getenv("FORGE_PATCHDIR"))
- log.Printf("%s FORGE_URL = %s\n", what, os.Getenv("FORGE_URL"))
- log.Printf("%s FORGE_GOWORK = %s\n", what, os.Getenv("FORGE_GOWORK"))
- log.Printf("%s FORGE_VERBOSE = %s\n", what, os.Getenv("FORGE_VERBOSE"))
- log.Printf("%s HOSTNAME = %s\n", what, os.Getenv("HOSTNAME"))
-}
-
-// set the ENV vars
-// always set them to _something_ even when everything seems to be failing
-func doConfigureENV() error {
- var anyerr error
- if os.Getenv("FORGE_REPOSDIR") == "" {
- reposDir, err := getReposDir()
- if err != nil {
- return err
- }
- os.Setenv("FORGE_REPOSDIR", reposDir)
- }
-
- if os.Getenv("FORGE_REPOSPB") == "" {
- pbdir, err := getCacheDir()
- if err != nil {
- return err
- }
- os.Setenv("FORGE_REPOSPB", filepath.Join(pbdir, "repos.pb"))
- }
-
- if os.Getenv("FORGE_PATCHDIR") == "" {
- pbdir, err := getCacheDir()
- if err != nil {
- return err
- }
- os.Setenv("FORGE_PATCHDIR", pbdir)
- }
-
- // setting FORGE_URL
- if os.Getenv("FORGE_URL") == "" {
- os.Setenv("FORGE_URL", "https://forge.wit.com/")
- }
-
- // hostname is needed. allow ENV to pass it in
- if os.Getenv("HOSTNAME") == "" {
- if hname, err := os.Hostname(); err == nil {
- os.Setenv("HOSTNAME", hname)
- } else {
- os.Setenv("HOSTNAME", "unconfigured.hostname.forge")
- }
- }
- return anyerr
-}
func getConfigDir() (string, error) {
homeDir, err := os.UserHomeDir()