flags.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // Copyright (c) 2013-2014, Jeffrey Wilcke. All rights reserved.
  2. //
  3. // This library is free software; you can redistribute it and/or
  4. // modify it under the terms of the GNU General Public
  5. // License as published by the Free Software Foundation; either
  6. // version 2.1 of the License, or (at your option) any later version.
  7. //
  8. // This library is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. // General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this library; if not, write to the Free Software
  15. // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  16. // MA 02110-1301 USA
  17. package main
  18. import (
  19. "flag"
  20. "fmt"
  21. "log"
  22. "os"
  23. "os/user"
  24. "path"
  25. "path/filepath"
  26. "runtime"
  27. "bitbucket.org/kardianos/osext"
  28. "github.com/ethereum/go-ethereum/logger"
  29. "github.com/ethereum/go-ethereum/vm"
  30. )
  31. var (
  32. Identifier string
  33. KeyRing string
  34. KeyStore string
  35. StartRpc bool
  36. StartWebSockets bool
  37. RpcPort int
  38. UseUPnP bool
  39. OutboundPort string
  40. ShowGenesis bool
  41. AddPeer string
  42. MaxPeer int
  43. GenAddr bool
  44. UseSeed bool
  45. SecretFile string
  46. ExportDir string
  47. NonInteractive bool
  48. Datadir string
  49. LogFile string
  50. ConfigFile string
  51. DebugFile string
  52. LogLevel int
  53. VmType int
  54. )
  55. // flags specific to gui client
  56. var AssetPath string
  57. //TODO: If we re-use the one defined in cmd.go the binary osx image crashes. If somebody finds out why we can dry this up.
  58. func defaultAssetPath() string {
  59. var assetPath string
  60. // If the current working directory is the go-ethereum dir
  61. // assume a debug build and use the source directory as
  62. // asset directory.
  63. pwd, _ := os.Getwd()
  64. if pwd == path.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "cmd", "mist") {
  65. assetPath = path.Join(pwd, "assets")
  66. } else {
  67. switch runtime.GOOS {
  68. case "darwin":
  69. // Get Binary Directory
  70. exedir, _ := osext.ExecutableFolder()
  71. assetPath = filepath.Join(exedir, "../Resources")
  72. case "linux":
  73. assetPath = "/usr/share/mist"
  74. case "windows":
  75. assetPath = "./assets"
  76. default:
  77. assetPath = "."
  78. }
  79. }
  80. return assetPath
  81. }
  82. func defaultDataDir() string {
  83. usr, _ := user.Current()
  84. return path.Join(usr.HomeDir, ".mist")
  85. }
  86. var defaultConfigFile = path.Join(defaultDataDir(), "conf.ini")
  87. func Init() {
  88. flag.Usage = func() {
  89. fmt.Fprintf(os.Stderr, "%s [options] [filename]:\noptions precedence: default < config file < environment variables < command line\n", os.Args[0])
  90. flag.PrintDefaults()
  91. }
  92. flag.IntVar(&VmType, "vm", 0, "Virtual Machine type: 0-1: standard, debug")
  93. flag.StringVar(&Identifier, "id", "", "Custom client identifier")
  94. flag.StringVar(&KeyRing, "keyring", "", "identifier for keyring to use")
  95. flag.StringVar(&KeyStore, "keystore", "db", "system to store keyrings: db|file (db)")
  96. flag.StringVar(&OutboundPort, "port", "30303", "listening port")
  97. flag.BoolVar(&UseUPnP, "upnp", true, "enable UPnP support")
  98. flag.IntVar(&MaxPeer, "maxpeer", 10, "maximum desired peers")
  99. flag.IntVar(&RpcPort, "rpcport", 8080, "port to start json-rpc server on")
  100. flag.BoolVar(&StartRpc, "rpc", false, "start rpc server")
  101. flag.BoolVar(&StartWebSockets, "ws", false, "start websocket server")
  102. flag.BoolVar(&NonInteractive, "y", false, "non-interactive mode (say yes to confirmations)")
  103. flag.BoolVar(&UseSeed, "seed", true, "seed peers")
  104. flag.BoolVar(&GenAddr, "genaddr", false, "create a new priv/pub key")
  105. flag.StringVar(&SecretFile, "import", "", "imports the file given (hex or mnemonic formats)")
  106. flag.StringVar(&ExportDir, "export", "", "exports the session keyring to files in the directory given")
  107. flag.StringVar(&LogFile, "logfile", "", "log file (defaults to standard output)")
  108. flag.StringVar(&Datadir, "datadir", defaultDataDir(), "specifies the datadir to use")
  109. flag.StringVar(&ConfigFile, "conf", defaultConfigFile, "config file")
  110. flag.StringVar(&DebugFile, "debug", "", "debug file (no debugging if not set)")
  111. flag.IntVar(&LogLevel, "loglevel", int(logger.InfoLevel), "loglevel: 0-5: silent,error,warn,info,debug,debug detail)")
  112. flag.StringVar(&AssetPath, "asset_path", defaultAssetPath(), "absolute path to GUI assets directory")
  113. flag.Parse()
  114. if VmType >= int(vm.MaxVmTy) {
  115. log.Fatal("Invalid VM type ", VmType)
  116. }
  117. }