ecal.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * ECAL
  3. *
  4. * Copyright 2020 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/ecal/cli/tool"
  16. "devt.de/krotik/ecal/config"
  17. )
  18. /*
  19. TODO:
  20. - create executable binary (pack into single binary)
  21. - debug support errors
  22. - pretty printer
  23. - local variable definition (let)
  24. - reload on start for debugger adapter
  25. */
  26. func main() {
  27. // Initialize the default command line parser
  28. flag.CommandLine.Init(os.Args[0], flag.ContinueOnError)
  29. // Define default usage message
  30. flag.Usage = func() {
  31. // Print usage for tool selection
  32. fmt.Println(fmt.Sprintf("Usage of %s <tool>", os.Args[0]))
  33. fmt.Println()
  34. fmt.Println(fmt.Sprintf("ECAL %v - Event Condition Action Language", config.ProductVersion))
  35. fmt.Println()
  36. fmt.Println("Available commands:")
  37. fmt.Println()
  38. fmt.Println(" console Interactive console (default)")
  39. fmt.Println(" run Execute ECAL code")
  40. fmt.Println(" debug Run in debug mode")
  41. fmt.Println(" pack Create a single executable from ECAL code")
  42. fmt.Println()
  43. fmt.Println(fmt.Sprintf("Use %s <command> -help for more information about a given command.", os.Args[0]))
  44. fmt.Println()
  45. }
  46. // Parse the command bit
  47. if err := flag.CommandLine.Parse(os.Args[1:]); err == nil {
  48. interpreter := tool.NewCLIInterpreter()
  49. if len(flag.Args()) > 0 {
  50. arg := flag.Args()[0]
  51. if arg == "console" {
  52. err = interpreter.Interpret(true)
  53. } else if arg == "run" {
  54. err = interpreter.Interpret(false)
  55. } else if arg == "debug" {
  56. debugInterpreter := tool.NewCLIDebugInterpreter(interpreter)
  57. err = debugInterpreter.Interpret()
  58. } else {
  59. flag.Usage()
  60. }
  61. } else if err == nil {
  62. err = interpreter.Interpret(true)
  63. }
  64. if err != nil {
  65. fmt.Println(fmt.Sprintf("Error: %v", err))
  66. }
  67. } else {
  68. flag.Usage()
  69. }
  70. }