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" "sevenkeys/figlet"
) )
type ModeOfOperation string
const ( const (
ModeImport ModeOfOperation = "import" ImportSubcommand string = "import"
ModeInteractive = "interactive"
) )
func main() { func main() {
var profile string profile := os.Getenv("SEVENKEYS_PROFILE")
flag.StringVar(&profile, "profile", "production", "the database profile to use")
modePtr := flag.String("mode", "interactive", "the mode of operation")
flag.Parse()
mode := ModeOfOperation(*modePtr)
db := database.GetDatabaseFromConfig("config." + profile + ".json") db := database.GetDatabaseFromConfig("config." + profile + ".json")
figlet.ReadFigletFonts() figlet.ReadFigletFonts()
cli.ShowSplashScreen() cli.ShowSplashScreen()
cli.RunUpdateCheck(db) cli.RunUpdateCheck(db)
switch mode { // TODO: Decide in what form we need to retain this functionality if any
case ModeImport: //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 // TODO: Get filename, run import code
break importCmd.Parse(os.Args[2:])
case ModeInteractive: //storageAreaId := logic.GetStorageAreaIdByName(db, *storageArea)
cli.MainCliLoop(db)
fmt.Printf("Filename: %s\n", importCmd.Args()[0])
break break
default: default:
fmt.Fprintf(os.Stderr, "Unrecognized mode: %s\n", mode) fmt.Fprintf(os.Stderr, "Unrecognized subcommand: %s\n", os.Args[1])
break break
} }
} }