Parse flags for "import" subcommand

This commit is contained in:
The Magician 2024-09-25 17:49:01 +01:00
parent 768e4c9d79
commit c53d02ba38
1 changed files with 20 additions and 17 deletions

View File

@ -9,36 +9,39 @@ import (
"sevenkeys/figlet"
)
type ModeOfOperation string
const (
ModeImport ModeOfOperation = "import"
ModeInteractive = "interactive"
ImportSubcommand string = "import"
)
func main() {
var profile string
flag.StringVar(&profile, "profile", "production", "the database profile to use")
modePtr := flag.String("mode", "interactive", "the mode of operation")
flag.Parse()
mode := ModeOfOperation(*modePtr)
profile := os.Getenv("SEVENKEYS_PROFILE")
db := database.GetDatabaseFromConfig("config." + profile + ".json")
figlet.ReadFigletFonts()
cli.ShowSplashScreen()
cli.RunUpdateCheck(db)
switch mode {
case ModeImport:
// TODO: Decide in what form we need to retain this functionality if any
//cli.MainCliLoop(db)
importCmd := flag.NewFlagSet("import", flag.ExitOnError)
storageArea := importCmd.String("storagearea", "", "The name of the StorageArea where cards should be imported.")
if len(os.Args) < 2 {
fmt.Fprintln(os.Stderr, "Please specify a subcommand.")
os.Exit(1)
}
switch os.Args[1] {
case ImportSubcommand:
// TODO: Get filename, run import code
break
case ModeInteractive:
cli.MainCliLoop(db)
importCmd.Parse(os.Args[2:])
//storageAreaId := logic.GetStorageAreaIdByName(db, *storageArea)
fmt.Printf("Filename: %s\n", importCmd.Args()[0])
break
default:
fmt.Fprintf(os.Stderr, "Unrecognized mode: %s\n", mode)
fmt.Fprintf(os.Stderr, "Unrecognized subcommand: %s\n", os.Args[1])
break
}
}