ads1_2021/code/golang/main.go

97 lines
2.3 KiB
Go

package main
/* ---------------------------------------------------------------- *
* IMPORTS
* ---------------------------------------------------------------- */
import (
"embed"
"os"
"ads/internal/core/logging"
"ads/internal/setup"
"ads/internal/setup/cli"
"ads/internal/types"
endpoints_print "ads/internal/endpoints/print"
endpoints_run "ads/internal/endpoints/run"
)
/* ---------------------------------------------------------------- *
* GLOBAL VARIABLES
* ---------------------------------------------------------------- */
var (
// !!! NOTE: do not remove the following "comment", as it is a preprocessing instruction !!!
//go:embed assets/*
res embed.FS
assets = map[string]string{
"appconfig": "assets/config.yml",
"version": "assets/VERSION",
"logo": "assets/LOGO",
"help": "assets/HELP",
}
)
/* ---------------------------------------------------------------- *
* METHOD main
* ---------------------------------------------------------------- */
func main() {
var err error
var arguments *types.CliArguments
var (
cmdMissing bool
showChecks bool
)
// assets festlegen
setup.Res = res
setup.Assets = assets
// cli arguments parsen
arguments, err = cli.ParseCli(os.Args)
cmdMissing = cli.ParseCliCommandMissing(err)
// initialisiere basic optionen wie Logging
showChecks = false
if err == nil {
if !(arguments.ModeRun.Happened() && arguments.InteractiveMode()) {
logging.SetQuietMode(arguments.QuietModeOn())
logging.SetDebugMode(arguments.DebugModeOn())
}
logging.SetAnsiMode(arguments.ShowColour())
showChecks = arguments.ShowChecks()
}
// app config (intern) intialisieren
err = setup.AppConfigInitialise()
setup.SetAppConfigPerformChecks(showChecks)
if err == nil {
if arguments.ModeVersion.Happened() {
endpoints_print.Version()
return
} else if arguments.ModeRun.Happened() {
if arguments.InteractiveMode() {
endpoints_run.RunInteractive()
} else {
err = endpoints_run.RunNonInteractive(arguments.GetConfigFile())
if err != nil {
logging.Fatal(err)
}
}
return
} else if arguments.ModeHelp.Happened() {
endpoints_print.Help()
return
} else {
endpoints_run.RunInteractive()
}
} else if cmdMissing {
endpoints_run.RunInteractive()
} else {
logging.Fatal(err)
}
}