ecal.go 1.7 KB

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