Skip to content

Commit

Permalink
woops
Browse files Browse the repository at this point in the history
  • Loading branch information
obscuren committed May 30, 2014
1 parent 17c825f commit 9e8127a
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion ethutil/config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package ethutil

import (
"flag"
"fmt"
"github.com/rakyll/globalconf"
"log"
"os"
"os/user"
Expand All @@ -20,6 +22,8 @@ type config struct {
ClientString string
Pubkey []byte
Identifier string

conf *globalconf.GlobalConf
}

const defaultConf = `
Expand Down Expand Up @@ -67,11 +71,12 @@ func ApplicationFolder(base string) string {
// Read config
//
// Initialize the global Config variable with default settings
func ReadConfig(base string, logTypes LoggerType, id string) *config {
func ReadConfig(base string, logTypes LoggerType, g *globalconf.GlobalConf, id string) *config {
if Config == nil {
path := ApplicationFolder(base)

Config = &config{ExecPath: path, Debug: true, Ver: "0.5.0 RC11"}
Config.conf = g
Config.Identifier = id
Config.Log = NewLogger(logTypes, LogLevelDebug)
Config.SetClientString("/Ethereum(G)")
Expand All @@ -90,6 +95,16 @@ func (c *config) SetClientString(str string) {
Config.ClientString = fmt.Sprintf("%s nv%s/%s", str, c.Ver, id)
}

func (c *config) SetIdentifier(id string) {
c.Identifier = id
c.Set("id", id)
}

func (c *config) Set(key, value string) {
f := &flag.Flag{Name: key, Value: &confValue{value}}
c.conf.Set("", f)
}

type LoggerType byte

const (
Expand Down Expand Up @@ -190,3 +205,10 @@ func (log *Logger) Fatal(v ...interface{}) {

os.Exit(1)
}

type confValue struct {
value string
}

func (self confValue) String() string { return self.value }
func (self confValue) Set(s string) error { self.value = s; return nil }

0 comments on commit 9e8127a

Please sign in to comment.