Add option to only add unique cards

This commit is contained in:
Florian Baumann 2022-11-28 12:02:28 +01:00
parent a7606055c9
commit 39b13c0763
2 changed files with 8 additions and 0 deletions

View File

@ -9,6 +9,7 @@ import (
func init() { func init() {
addCmd.Flags().Int64VarP(&count, "count", "c", 1, "Amount of cards to add") addCmd.Flags().Int64VarP(&count, "count", "c", 1, "Amount of cards to add")
addCmd.Flags().BoolVarP(&unique, "unique", "u", false, "Only add card if not existent yet")
rootCmd.AddCommand(addCmd) rootCmd.AddCommand(addCmd)
} }
@ -39,6 +40,12 @@ var addCmd = &cobra.Command{
// If duplicate key, increase count of card // If duplicate key, increase count of card
if mongo.IsDuplicateKeyError(err) { if mongo.IsDuplicateKeyError(err) {
if unique {
LogMessage(fmt.Sprintf("Not adding \"%s\" to Collection because it already exists.", c.Name), "red")
continue
}
modify_count_of_card(coll, c, count) modify_count_of_card(coll, c, count)
continue continue
} }

View File

@ -13,6 +13,7 @@ var limit float64
var name string var name string
var since string var since string
var rarity, set, sort string var rarity, set, sort string
var unique bool
var rootCmd = &cobra.Command{ var rootCmd = &cobra.Command{
Version: Version, Version: Version,