main.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. This file is part of go-ethereum
  3. go-ethereum is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. go-ethereum is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. /**
  15. * @authors
  16. * Jeffrey Wilcke <i@jev.io>
  17. */
  18. package main
  19. import (
  20. "fmt"
  21. "io"
  22. "os"
  23. "github.com/codegangsta/cli"
  24. "github.com/ethereum/go-ethereum/cmd/utils"
  25. "github.com/ethereum/go-ethereum/logger"
  26. "github.com/mattn/go-colorable"
  27. "github.com/mattn/go-isatty"
  28. )
  29. const (
  30. ClientIdentifier = "Geth console"
  31. Version = "0.9.27"
  32. )
  33. var (
  34. gitCommit string // set via linker flag
  35. nodeNameVersion string
  36. app = utils.NewApp(Version, "the ether console")
  37. )
  38. func init() {
  39. if gitCommit == "" {
  40. nodeNameVersion = Version
  41. } else {
  42. nodeNameVersion = Version + "-" + gitCommit[:8]
  43. }
  44. app.Action = run
  45. app.Flags = []cli.Flag{
  46. utils.IPCDisabledFlag,
  47. utils.IPCPathFlag,
  48. utils.VerbosityFlag,
  49. utils.JSpathFlag,
  50. }
  51. app.Before = func(ctx *cli.Context) error {
  52. utils.SetupLogger(ctx)
  53. return nil
  54. }
  55. }
  56. func main() {
  57. // Wrap the standard output with a colorified stream (windows)
  58. if isatty.IsTerminal(os.Stdout.Fd()) {
  59. if pr, pw, err := os.Pipe(); err == nil {
  60. go io.Copy(colorable.NewColorableStdout(), pr)
  61. os.Stdout = pw
  62. }
  63. }
  64. var interrupted = false
  65. utils.RegisterInterrupt(func(os.Signal) {
  66. interrupted = true
  67. })
  68. utils.HandleInterrupt()
  69. if err := app.Run(os.Args); err != nil {
  70. fmt.Fprintln(os.Stderr, "Error: ", err)
  71. }
  72. // we need to run the interrupt callbacks in case gui is closed
  73. // this skips if we got here by actual interrupt stopping the GUI
  74. if !interrupted {
  75. utils.RunInterruptCallbacks(os.Interrupt)
  76. }
  77. logger.Flush()
  78. }
  79. func run(ctx *cli.Context) {
  80. jspath := ctx.GlobalString(utils.JSpathFlag.Name)
  81. ipcpath := ctx.GlobalString(utils.IPCPathFlag.Name)
  82. repl := newJSRE(jspath, ipcpath)
  83. repl.welcome(ipcpath)
  84. repl.interactive()
  85. }