ecal.go 2.0 KB

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