ecal.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. - CLI interpreter (show base directory when starting)
  21. -- console can specify a base directory
  22. -- console can preload code
  23. - adding external stdlib functions
  24. - cron trigger (async) in-build function
  25. - web server (sync/async) in-build function with options
  26. - create executable binary (pack into single binary)
  27. - debug server support (vscode)
  28. */
  29. func main() {
  30. // Initialize the default command line parser
  31. flag.CommandLine.Init(os.Args[0], flag.ContinueOnError)
  32. // Define default usage message
  33. flag.Usage = func() {
  34. // Print usage for tool selection
  35. fmt.Println(fmt.Sprintf("Usage of %s <tool>", os.Args[0]))
  36. fmt.Println()
  37. fmt.Println(fmt.Sprintf("ECAL %v - Event Condition Action Language", config.ProductVersion))
  38. fmt.Println()
  39. fmt.Println("Available commands:")
  40. fmt.Println()
  41. fmt.Println(" console Interactive console (default)")
  42. fmt.Println(" run Execute ECAL code")
  43. fmt.Println(" debug Run a debug server")
  44. fmt.Println(" pack Create a single executable from ECAL code")
  45. fmt.Println()
  46. fmt.Println(fmt.Sprintf("Use %s <command> -help for more information about a given command.", os.Args[0]))
  47. fmt.Println()
  48. }
  49. // Parse the command bit
  50. err := flag.CommandLine.Parse(os.Args[1:])
  51. if len(flag.Args()) > 0 {
  52. arg := flag.Args()[0]
  53. if arg == "console" {
  54. err = tool.Interpret(true)
  55. } else if arg == "run" {
  56. err = tool.Interpret(false)
  57. } else {
  58. flag.Usage()
  59. }
  60. } else if err == nil {
  61. err = tool.Interpret(true)
  62. }
  63. if err != nil {
  64. fmt.Println(fmt.Sprintf("Error: %v", err))
  65. }
  66. }