Permalink
Browse files

Export main.Config, change meaning of GONUTS_IO_SERVER.

  • Loading branch information...
1 parent 59e7c40 commit a28d23ac5a93f9d5b219d5eb4a6c6cf71f27e3a2 @AlekSi committed Feb 23, 2013
Showing with 19 additions and 16 deletions.
  1. +1 −1 Makefile
  2. +10 −7 nut/base.go
  3. +1 −1 nut/check.go
  4. +1 −1 nut/generate.go
  5. +1 −1 nut/get.go
  6. +1 −1 nut/install.go
  7. +1 −1 nut/pack.go
  8. +2 −2 nut/publish.go
  9. +1 −1 nut/unpack.go
View
2 Makefile
@@ -25,4 +25,4 @@ integration_test_short: test
$(GO) test -v -short github.com/AlekSi/nut/integration_test -gocheck.v
integration_test: test
- GONUTS_IO_SERVER=localhost:8080 $(GO) test -v github.com/AlekSi/nut/integration_test -gocheck.v
+ GONUTS_IO_SERVER=http://localhost:8080 $(GO) test -v github.com/AlekSi/nut/integration_test -gocheck.v
View
17 nut/base.go
@@ -8,6 +8,7 @@ import (
"go/build"
"io/ioutil"
"log"
+ "net/url"
"os"
"os/exec"
"os/user"
@@ -17,7 +18,7 @@ import (
. "github.com/AlekSi/nut"
)
-type Config struct {
+type ConfigFile struct {
Token string
V bool
}
@@ -39,7 +40,7 @@ var (
// - no GAE for second-level domains.
NutImportPrefixes = map[string]string{"gonuts.io": "www.gonuts.io"}
- config Config
+ Config ConfigFile
vHelp string = fmt.Sprintf("be verbose (may be read from ~/%s)", ConfigFileName)
)
@@ -62,7 +63,7 @@ func init() {
NutDir = filepath.Join(WorkspaceDir, "nut")
u, err := user.Current()
- if err != nil {
+ if err == nil {
_, err = os.Stat(u.HomeDir)
}
if err != nil {
@@ -73,15 +74,15 @@ func init() {
path := filepath.Join(u.HomeDir, ConfigFileName)
b, err := ioutil.ReadFile(path)
if err == nil {
- err = json.Unmarshal(b, &config)
+ err = json.Unmarshal(b, &Config)
}
if err != nil && !os.IsNotExist(err) {
log.Printf("Warning: Can't load config from %s: %s\n", path, err)
- config = Config{}
+ Config = ConfigFile{}
}
if !os.IsNotExist(err) {
- b, err = json.MarshalIndent(config, "", " ")
+ b, err = json.MarshalIndent(Config, "", " ")
if err == nil {
err = ioutil.WriteFile(path, b, ConfigFilePerm)
}
@@ -92,7 +93,9 @@ func init() {
env := os.Getenv("GONUTS_IO_SERVER")
if env != "" {
- NutImportPrefixes["gonuts.io"] = env
+ u, err := url.Parse(env)
+ PanicIfErr(err)
+ NutImportPrefixes["gonuts.io"] = u.Host
}
}
View
2 nut/check.go
@@ -35,7 +35,7 @@ Examples:
func runCheck(cmd *Command) {
if !checkV {
- checkV = config.V
+ checkV = Config.V
}
args := cmd.Flag.Args()
View
2 nut/generate.go
@@ -37,7 +37,7 @@ Examples:
func runGenerate(cmd *Command) {
if !generateV {
- generateV = config.V
+ generateV = Config.V
}
if len(cmd.Flag.Args()) != 0 {
View
2 nut/get.go
@@ -109,7 +109,7 @@ func get(url *url.URL) (b []byte, err error) {
func runGet(cmd *Command) {
if !getV {
- getV = config.V
+ getV = Config.V
}
args := cmd.Flag.Args()
View
2 nut/install.go
@@ -41,7 +41,7 @@ Examples:
func runInstall(cmd *Command) {
if !installV {
- installV = config.V
+ installV = Config.V
}
for _, arg := range cmd.Flag.Args() {
View
2 nut/pack.go
@@ -38,7 +38,7 @@ Examples:
func runPack(cmd *Command) {
if !packV {
- packV = config.V
+ packV = Config.V
}
if len(cmd.Flag.Args()) != 0 {
View
4 nut/publish.go
@@ -36,10 +36,10 @@ Examples:
func runPublish(cmd *Command) {
if publishToken == "" {
- publishToken = config.Token
+ publishToken = Config.Token
}
if !publishV {
- publishV = config.V
+ publishV = Config.V
}
url, err := url.Parse("http://" + NutImportPrefixes["gonuts.io"])
View
2 nut/unpack.go
@@ -30,7 +30,7 @@ Examples:
func runUnpack(cmd *Command) {
if !unpackV {
- unpackV = config.V
+ unpackV = Config.V
}
if len(cmd.Flag.Args()) != 1 {

0 comments on commit a28d23a

Please sign in to comment.