ecal.go 1.9 KB

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