main.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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.IPCPathFlag,
  47. utils.VerbosityFlag,
  48. utils.JSpathFlag,
  49. }
  50. app.Before = func(ctx *cli.Context) error {
  51. utils.SetupLogger(ctx)
  52. return nil
  53. }
  54. }
  55. func main() {
  56. // Wrap the standard output with a colorified stream (windows)
  57. if isatty.IsTerminal(os.Stdout.Fd()) {
  58. if pr, pw, err := os.Pipe(); err == nil {
  59. go io.Copy(colorable.NewColorableStdout(), pr)
  60. os.Stdout = pw
  61. }
  62. }
  63. var interrupted = false
  64. utils.RegisterInterrupt(func(os.Signal) {
  65. interrupted = true
  66. })
  67. utils.HandleInterrupt()
  68. if err := app.Run(os.Args); err != nil {
  69. fmt.Fprintln(os.Stderr, "Error: ", err)
  70. }
  71. // we need to run the interrupt callbacks in case gui is closed
  72. // this skips if we got here by actual interrupt stopping the GUI
  73. if !interrupted {
  74. utils.RunInterruptCallbacks(os.Interrupt)
  75. }
  76. logger.Flush()
  77. }
  78. func run(ctx *cli.Context) {
  79. jspath := ctx.GlobalString(utils.JSpathFlag.Name)
  80. ipcpath := utils.IpcSocketPath(ctx)
  81. repl := newJSRE(jspath, ipcpath)
  82. repl.welcome(ipcpath)
  83. repl.interactive()
  84. }