From c53d02ba38ce8d25efe6b5eaa9eb14ff542213e5 Mon Sep 17 00:00:00 2001 From: The Magician Date: Wed, 25 Sep 2024 17:49:01 +0100 Subject: [PATCH] Parse flags for "import" subcommand --- sevenkeys/main.go | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/sevenkeys/main.go b/sevenkeys/main.go index a4e3310..3830fed 100644 --- a/sevenkeys/main.go +++ b/sevenkeys/main.go @@ -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 } }