ecal.go 1.8 KB

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