From 65c5a20e1c04c996f96f81cd959ab986b8482b6a Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 30 May 2014 16:56:56 +0200 Subject: [PATCH] Added config file setup. Fixes #59 * Also fixes asset path problems --- README.md | 10 ++++++---- ethereal/config.go | 20 ++++++++------------ ethereal/ethereum.go | 13 ++++++++++++- ethereum/config.go | 18 ++++++++---------- ethereum/ethereum.go | 2 +- 5 files changed, 35 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index c52b9ca5bb5b..c32b5103728d 100644 --- a/README.md +++ b/README.md @@ -27,13 +27,15 @@ General command line options ``` Shared between ethereum and ethereal --genaddr Generates a new address and private key (destructive action) --p Port on which the server will accept incomming connections +-id Set the custom identifier of the client (shows up on other clients) +-port Port on which the server will accept incomming connections -upnp Enable UPnP --x Desired amount of peers --r Start JSON RPC +-maxpeer Desired amount of peers +-rpc Start JSON RPC + -dir Data directory used to store configs and databases -import Import a private key +-genaddr Generates a new address and private key (destructive action) -h This Ethereum only diff --git a/ethereal/config.go b/ethereal/config.go index 5356405186de..6a42663e7942 100644 --- a/ethereal/config.go +++ b/ethereal/config.go @@ -5,7 +5,6 @@ import ( ) var Identifier string -var StartConsole bool //var StartMining bool var StartRpc bool @@ -19,25 +18,22 @@ var GenAddr bool var UseSeed bool var ImportKey string var ExportKey bool -var DataDir string var AssetPath string func Init() { - flag.StringVar(&Identifier, "i", "", "Custom client identifier") - flag.BoolVar(&StartConsole, "c", false, "debug and testing console") - //flag.BoolVar(&StartMining, "m", false, "start dagger mining") - flag.BoolVar(&StartRpc, "r", false, "start rpc server") - flag.BoolVar(&ShowGenesis, "g", false, "prints genesis header and exits") + flag.StringVar(&Identifier, "id", "", "Custom client identifier") + flag.StringVar(&OutboundPort, "port", "30303", "listening port") flag.BoolVar(&UseUPnP, "upnp", false, "enable UPnP support") + flag.IntVar(&MaxPeer, "maxpeer", 10, "maximum desired peers") + flag.IntVar(&RpcPort, "rpcport", 8080, "port to start json-rpc server on") + flag.BoolVar(&StartRpc, "rpc", false, "start rpc server") + flag.StringVar(&AssetPath, "asset_path", "", "absolute path to GUI assets directory") + + flag.BoolVar(&ShowGenesis, "genesis", false, "prints genesis header and exits") flag.BoolVar(&UseSeed, "seed", true, "seed peers") flag.BoolVar(&GenAddr, "genaddr", false, "create a new priv/pub key") flag.BoolVar(&ExportKey, "export", false, "export private key") - flag.IntVar(&RpcPort, "rpcport", 8080, "port to start json-rpc server on") - flag.StringVar(&OutboundPort, "p", "30303", "listening port") - flag.StringVar(&DataDir, "dir", ".ethereal", "ethereum data directory") flag.StringVar(&ImportKey, "import", "", "imports the given private key (hex)") - flag.IntVar(&MaxPeer, "x", 10, "maximum desired peers") - flag.StringVar(&AssetPath, "asset_path", "", "absolute path to GUI assets directory") flag.Parse() } diff --git a/ethereal/ethereum.go b/ethereal/ethereum.go index 2867e30d4b44..a7e43cd9aa6d 100644 --- a/ethereal/ethereum.go +++ b/ethereal/ethereum.go @@ -8,9 +8,11 @@ import ( "github.com/ethereum/go-ethereum/ethereal/ui" "github.com/ethereum/go-ethereum/utils" "github.com/go-qml/qml" + "github.com/rakyll/globalconf" "log" "os" "os/signal" + "path" "runtime" ) @@ -39,7 +41,16 @@ func main() { runtime.GOMAXPROCS(runtime.NumCPU()) ethchain.InitFees() - ethutil.ReadConfig(DataDir, ethutil.LogFile|ethutil.LogStd, Identifier) + + g, err := globalconf.NewWithOptions(&globalconf.Options{ + Filename: path.Join(ethutil.ApplicationFolder(".ethereal"), "conf.ini"), + }) + if err != nil { + fmt.Println(err) + } else { + g.ParseAll() + } + ethutil.ReadConfig(".ethereal", ethutil.LogFile|ethutil.LogStd, Identifier) // Instantiated a eth stack ethereum, err := eth.New(eth.CapDefault, UseUPnP) diff --git a/ethereum/config.go b/ethereum/config.go index 5da910f2bda1..39dc1172777d 100644 --- a/ethereum/config.go +++ b/ethereum/config.go @@ -20,7 +20,6 @@ var UseSeed bool var ImportKey string var ExportKey bool var LogFile string -var DataDir string var NonInteractive bool var StartJsConsole bool var InputFile string @@ -31,22 +30,21 @@ func Init() { flag.PrintDefaults() } - flag.StringVar(&Identifier, "i", "", "custom client identifier") - flag.BoolVar(&StartMining, "m", false, "start dagger mining") - flag.BoolVar(&ShowGenesis, "g", false, "prints genesis header and exits") - flag.BoolVar(&StartRpc, "r", false, "start rpc server") + flag.StringVar(&Identifier, "id", "", "Custom client identifier") + flag.StringVar(&OutboundPort, "port", "30303", "listening port") + flag.BoolVar(&UseUPnP, "upnp", false, "enable UPnP support") + flag.IntVar(&MaxPeer, "maxpeer", 10, "maximum desired peers") flag.IntVar(&RpcPort, "rpcport", 8080, "port to start json-rpc server on") + flag.BoolVar(&StartRpc, "rpc", false, "start rpc server") + flag.BoolVar(&StartJsConsole, "js", false, "exp") + + flag.BoolVar(&StartMining, "mine", false, "start dagger mining") flag.BoolVar(&NonInteractive, "y", false, "non-interactive mode (say yes to confirmations)") - flag.BoolVar(&UseUPnP, "upnp", false, "enable UPnP support") flag.BoolVar(&UseSeed, "seed", true, "seed peers") flag.BoolVar(&GenAddr, "genaddr", false, "create a new priv/pub key") flag.BoolVar(&ExportKey, "export", false, "export private key") - flag.StringVar(&OutboundPort, "p", "30303", "listening port") flag.StringVar(&LogFile, "logfile", "", "log file (defaults to standard output)") - flag.StringVar(&DataDir, "dir", ".ethereum", "ethereum data directory") flag.StringVar(&ImportKey, "import", "", "imports the given private key (hex)") - flag.IntVar(&MaxPeer, "x", 10, "maximum desired peers") - flag.BoolVar(&StartJsConsole, "js", false, "exp") flag.Parse() diff --git a/ethereum/ethereum.go b/ethereum/ethereum.go index 34bacb7b9969..7bb668235eaa 100644 --- a/ethereum/ethereum.go +++ b/ethereum/ethereum.go @@ -59,7 +59,7 @@ func main() { lt = ethutil.LogFile | ethutil.LogStd } - ethutil.ReadConfig(DataDir, lt, Identifier) + ethutil.ReadConfig(".ethereum", lt, Identifier) logger := ethutil.Config.Log