82 lines
2.5 KiB
Go
82 lines
2.5 KiB
Go
package cli
|
|
|
|
/* ---------------------------------------------------------------- *
|
|
* IMPORTS
|
|
* ---------------------------------------------------------------- */
|
|
|
|
import (
|
|
"github.com/akamensky/argparse"
|
|
|
|
"ads/internal/types"
|
|
)
|
|
|
|
/* ---------------------------------------------------------------- *
|
|
* GLOBAL VARIABLES
|
|
* ---------------------------------------------------------------- */
|
|
|
|
var Parser *argparse.Parser
|
|
|
|
/* ---------------------------------------------------------------- *
|
|
* LOCAL VARIABLES / CONSTANTS
|
|
* ---------------------------------------------------------------- */
|
|
|
|
var optionsQuiet = argparse.Options{
|
|
Help: "Blendet alle Konsole-Messages aus.",
|
|
Required: false,
|
|
Default: false,
|
|
}
|
|
|
|
var optionsChecks = argparse.Options{
|
|
Help: "Ob vor und nach Ausführung von Algorithmen Checks auf Inputs/Outputs ausgeführt werden sollen.",
|
|
Required: false,
|
|
// NOTE: no `Boolean` option available!
|
|
Default: "false",
|
|
}
|
|
|
|
var optionsDebug = argparse.Options{
|
|
Help: "Blendet die Debugging-Befehle ein.",
|
|
Required: false,
|
|
Default: false,
|
|
}
|
|
|
|
var optionsInteractive = argparse.Options{
|
|
Help: "Startet die App im interaktiven Modus.",
|
|
Required: false,
|
|
Default: false,
|
|
}
|
|
|
|
var optionsColour = argparse.Options{
|
|
Help: "Ob Logging färblich angezeigt wird.",
|
|
Required: false,
|
|
// NOTE: no `Boolean` option available!
|
|
Default: "true",
|
|
}
|
|
|
|
var optionsConfigFile = argparse.Options{
|
|
Help: "Pfad zur Configdatei (nur für run Endpunkt).",
|
|
Required: false,
|
|
Default: "code/config.yml",
|
|
}
|
|
|
|
/* ---------------------------------------------------------------- *
|
|
* METHODS parse cli
|
|
* ---------------------------------------------------------------- */
|
|
|
|
func ParseCli(args []string) (*types.CliArguments, error) {
|
|
var err error
|
|
Parser = argparse.NewParser("cli parser", "Liest Optionen + Flags von Kommandozeile.")
|
|
arguments := types.CliArguments{
|
|
ModeHelp: Parser.NewCommand("help", ""),
|
|
ModeVersion: Parser.NewCommand("version", "Ruft Endpunkt auf, der die Version anzeigt."),
|
|
ModeRun: Parser.NewCommand("run", "Ruft Endpunkt auf, der die Algorithmen laufen lässt."),
|
|
Quiet: Parser.Flag("q", "quiet", &optionsQuiet),
|
|
Debug: Parser.Flag("", "debug", &optionsDebug),
|
|
Interactive: Parser.Flag("", "it", &optionsInteractive),
|
|
Checks: Parser.String("", "checks", &optionsChecks),
|
|
Colour: Parser.String("", "colour", &optionsColour),
|
|
ConfigFile: Parser.String("", "config", &optionsConfigFile),
|
|
}
|
|
err = Parser.Parse(args)
|
|
return &arguments, err
|
|
}
|