ads1_2021/code/golang/internal/setup/cli/cli.go

67 lines
2.0 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 optionsDebug = argparse.Options{
Help: "Blendet die Debugging-Befehle ein.",
Required: false,
Default: false,
}
var optionsColour = argparse.Options{
Help: "Ob Logging färblich angezeigt wird (default=true).",
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{
Help: Parser.NewCommand("help", ""),
Version: Parser.NewCommand("version", "Ruft Endpunkt auf, der die Version anzeigt."),
Run: Parser.NewCommand("run", "Ruft Endpunkt auf, der die Algorithmen laufen lässt."),
Quiet: Parser.Flag("q", "quiet", &optionsQuiet),
Debug: Parser.Flag("", "debug", &optionsDebug),
Colour: Parser.String("", "colour", &optionsColour),
ConfigFile: Parser.String("", "config", &optionsConfigFile),
}
err = Parser.Parse(args)
return &arguments, err
}