diff --git a/sevenkeys/main.go b/sevenkeys/main.go index 2dd5bee..5b629f8 100644 --- a/sevenkeys/main.go +++ b/sevenkeys/main.go @@ -2,9 +2,11 @@ package main import ( "bufio" + "encoding/json" "errors" "flag" "fmt" + "io/ioutil" "log" "os" "sevenkeys/database" @@ -12,6 +14,8 @@ import ( "sevenkeys/logic" "sevenkeys/logic/scryfall" "strings" + + "github.com/mtgban/go-mtgban/cardtrader" ) func GetStringResponse(prompt string) string { @@ -37,9 +41,12 @@ const ( ImportSubcommand string = "import" SearchPrintingsSubcommand string = "search-printings" SearchStorageSubcommand string = "search-storage" + AddSubcommand string = "add" RemoveSubcommand string = "remove" ReplaceSubcommand string = "replace" DeckSubcommand string = "deck" + + GetProductIdSubcommand string = "products" ) func main() { @@ -189,6 +196,28 @@ func main() { logic.Check(err) fmt.Println(id) break + case AddSubcommand: + addCmd := flag.NewFlagSet(AddSubcommand, flag.ExitOnError) + + cardPrintingId := addCmd.String("card-printing-id", "", "The ID of the card printing to add to storage.") + storageArea := addCmd.String("storagearea", "", + "The name of the StorageArea where cards should be imported.") + + addCmd.Parse(flag.Args()[1:]) + + storageAreaId, err := logic.GetStorageAreaId(db, *storageArea) + if err == logic.ErrCouldNotGetStorageAreaId { + fmt.Fprintf(os.Stderr, "[sevenkeys] No storage area was selected, exiting.\n") + os.Exit(1) + } + logic.Check(err) + + cardLocation := database.CardLocation{ + CardPrintingId: *cardPrintingId, + StorageAreaId: storageAreaId, + } + logic.StoreCard(db, cardLocation) + break case RemoveSubcommand: removeCmd := flag.NewFlagSet(RemoveSubcommand, flag.ExitOnError) @@ -231,6 +260,45 @@ func main() { //filename := deckCmd.Args()[0] break + case GetProductIdSubcommand: + blbBlueprintsBytes, err := ioutil.ReadFile("blb_blueprints.json") + logic.Check(err) + + var blbBlueprints []cardtrader.Blueprint + err = json.Unmarshal(blbBlueprintsBytes, &blbBlueprints) + logic.Check(err) + + productsBytes, err := ioutil.ReadFile("products.json") + logic.Check(err) + + var products []cardtrader.Product + err = json.Unmarshal(productsBytes, &products) + logic.Check(err) + + for _, product := range products { + var productBlueprint cardtrader.Blueprint + for _, blueprint := range blbBlueprints { + if blueprint.Id == product.BlueprintId { + productBlueprint = blueprint + break + } + } + + fmt.Printf("%s %s %d ", + productBlueprint.Name, + product.Properties.Number, + product.Id, + ) + + if product.Properties.MTGFoil { + fmt.Printf("FOIL ") + } else { + fmt.Printf("NONFOIL ") + } + + fmt.Printf("x%d\n", product.Quantity) + } + break default: fmt.Fprintf(os.Stderr, "Unrecognized subcommand: %s\n", os.Args[1]) break