brawler.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Brawler
  3. *
  4. * Copyright 2019 Matthias Ladkau. All rights reserved.
  5. *
  6. * This Source Code Form is subject to the terms of the MIT
  7. * License, If a copy of the MIT License was not distributed with this
  8. * file, You can obtain one at https://opensource.org/licenses/MIT.
  9. */
  10. package main
  11. import (
  12. "flag"
  13. "fmt"
  14. "os"
  15. "devt.de/krotik/brawler/engine"
  16. "devt.de/krotik/brawler/rumble/api"
  17. "devt.de/krotik/brawler/rumble/stdlib/util"
  18. )
  19. /*
  20. DefaultEngineName is the name of Brawler's default engine
  21. */
  22. const DefaultEngineName = "default"
  23. /*
  24. Main entry point for Brawler.
  25. */
  26. func main() {
  27. var err error
  28. fmt.Println(fmt.Sprintf("Brawler %v", engine.ProductVersion))
  29. api.RegisterRumbleFunc(&util.FileSplitFunc{})
  30. api.RegisterRumbleFunc(&util.FileSplitFunc{})
  31. api.RegisterRumbleFunc(&util.PathConcatFunc{})
  32. api.RegisterRumbleFunc(&util.ConcatFunc{})
  33. api.RegisterRumbleFunc(&util.SplitFunc{})
  34. api.RegisterRumbleFunc(&util.HashFunc{})
  35. api.RegisterRumbleFunc(&util.DispStringFunc{})
  36. api.RegisterRumbleFunc(&util.TimeStampFunc{})
  37. api.RegisterRumbleFunc(&util.TimeStringFunc{})
  38. api.RegisterRumbleFunc(&util.TimeCompareFunc{})
  39. flag.Usage = func() {
  40. // Print usage for tool selection
  41. fmt.Println()
  42. fmt.Println(fmt.Sprintf("Usage of %s [tool]", os.Args[0]))
  43. fmt.Println()
  44. fmt.Println("The tools are:")
  45. fmt.Println()
  46. fmt.Println(" console Load files and start interactive console (default)")
  47. fmt.Println(" debug-server Start a debug web server")
  48. fmt.Println(" run Load files and exit")
  49. fmt.Println()
  50. fmt.Println(fmt.Sprintf("Use %s [tool] --help for more information about a tool.", os.Args[0]))
  51. fmt.Println()
  52. }
  53. flag.Parse()
  54. if len(flag.Args()) > 0 {
  55. arg := flag.Args()[0]
  56. if arg == "help" {
  57. flag.Usage()
  58. } else if arg == "debug-server" {
  59. err = debugServer()
  60. } else if arg == "run" {
  61. err = interpreter(false)
  62. } else {
  63. err = interpreter(true)
  64. }
  65. } else {
  66. err = interpreter(true)
  67. }
  68. if err != nil {
  69. fmt.Println(fmt.Sprintf("Error: %v", err))
  70. }
  71. }