ecal.go 2.0 KB

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