generated from snivilised/arcadia
-
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(command,proxy): allow config path to be configured by env (#151)
- Loading branch information
1 parent
614face
commit 6c0d91d
Showing
5 changed files
with
115 additions
and
72 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
"cmock", | ||
"cmocks", | ||
"cobrass", | ||
"configurator", | ||
"cubiest", | ||
"deadcode", | ||
"deepcopy", | ||
|
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,61 @@ | ||
package command | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/snivilised/cobrass/src/assistant/configuration" | ||
xi18n "github.com/snivilised/extendio/i18n" | ||
"github.com/snivilised/pixa/src/app/proxy/common" | ||
"github.com/snivilised/pixa/src/i18n" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type configRunner struct { | ||
vc configuration.ViperConfig | ||
ci *common.ConfigInfo | ||
} | ||
|
||
func (c configRunner) Run() error { | ||
c.vc.SetConfigName(c.ci.Name) | ||
c.vc.SetConfigType(c.ci.ConfigType) | ||
c.vc.AddConfigPath(c.path()) | ||
c.vc.AutomaticEnv() | ||
|
||
err := c.vc.ReadInConfig() | ||
|
||
handleLangSetting(c.vc) | ||
|
||
if err != nil { | ||
msg := xi18n.Text(i18n.UsingConfigFileTemplData{ | ||
ConfigFileName: c.vc.ConfigFileUsed(), | ||
}) | ||
|
||
fmt.Fprintln(os.Stderr, msg) | ||
|
||
fmt.Printf("💥 error reading config path: '%v' \n", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (c configRunner) path() string { | ||
configPath := c.ci.ConfigPath | ||
|
||
if configPath == "" { | ||
configPath, _ = c.vc.Get("PIXA-HOME").(string) | ||
|
||
fmt.Printf("---> ✨ PIXA-HOME found in environment: '%v'\n", configPath) | ||
} | ||
|
||
if configPath == "" { | ||
home, err := os.UserHomeDir() | ||
cobra.CheckErr(err) | ||
|
||
defaultPath := filepath.Join("snivilised", "pixa") | ||
configPath = filepath.Join(home, defaultPath) | ||
} | ||
|
||
return configPath | ||
} |
This file was deleted.
Oops, something went wrong.
37 changes: 37 additions & 0 deletions
37
src/app/proxy/common/config.defs.go → src/app/proxy/common/config-defs.go
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