Compare commits

...

4 Commits
main ... 1.3.1

Author SHA1 Message Date
Florian Baumann
d052e1a995 Add card input validation 2022-11-28 16:47:56 +01:00
Florian Baumann
0099fed6e6 fix add-card-wrapper.fish 2022-11-28 16:42:32 +01:00
Florian Baumann
c444a621b1 Add option to only add unique cards 2022-11-28 12:02:28 +01:00
Florian Baumann
bb262495b1 demo 2022-11-03 10:40:16 +01:00
6 changed files with 80 additions and 4 deletions

View File

@ -1,13 +1,23 @@
#!/usr/bin/env fish
function serra_add ()
# split input args
set -l args (string split " " $argv)
# check if user wants to exit
if [ "$args[2]" = "exit" ]
exit 0
end
# if usage contains a number at the end, add multiple ones
# if not, add a single one
if test -n "$args[3]"
./serra add $args[1]/$args[2] --count=$args[3]
echo ./serra add $args[1]/$args[2] --count=$args[3] >> add.log
serra add $args[1]/$args[2] --count=$args[3] -u
echo serra add $args[1]/$args[2] --count=$args[3] >> add.log
else
./serra add $args[1]/$args[2]
echo ./serra add $args[1]/$args[2] >> add.log
serra add $args[1]/$args[2] -u
echo serra add $args[1]/$args[2] >> add.log
end
end

BIN
demo.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

51
demo.tape Normal file
View File

@ -0,0 +1,51 @@
# VHS documentation
#
# Output:
# Output <path>.gif Create a GIF output at the given <path>
# Output <path>.mp4 Create an MP4 output at the given <path>
# Output <path>.webm Create a WebM output at the given <path>
#
# Settings:
# Set FontSize <number> Set the font size of the terminal
# Set FontFamily <string> Set the font family of the terminal
# Set Height <number> Set the height of the terminal
# Set Width <number> Set the width of the terminal
# Set LetterSpacing <float> Set the font letter spacing (tracking)
# Set LineHeight <float> Set the font line height
# Set Theme <string> Set the theme of the terminal (JSON)
# Set Padding <number> Set the padding of the terminal
# Set Framerate <number> Set the framerate of the recording
# Set PlaybackSpeed <float> Set the playback speed of the recording
#
# Sleep:
# Sleep <time> Sleep for a set amount of <time> in seconds
#
# Type:
# Type[@<time>] "<characters>" Type <characters> into the terminal with a
# <time> delay between each character
#
# Keys:
# Backspace[@<time>] [number] Press the Backspace key
# Down[@<time>] [number] Press the Down key
# Enter[@<time>] [number] Press the Enter key
# Space[@<time>] [number] Press the Space key
# Tab[@<time>] [number] Press the Tab key
# Left[@<time>] [number] Press the Left Arrow key
# Right[@<time>] [number] Press the Right Arrow key
# Up[@<time>] [number] Press the Up Arrow key
# Down[@<time>] [number] Press the Down Arrow key
# Ctrl+<key> Press the Control key + <key> (e.g. Ctrl+C)
#
# Display:
# Hide Hide the subsequent commands from the output
# Show Show the subsequent commands in the output
Output demo.gif
Set FontSize 32
Set Width 1200
Set Height 600
Type "serra --version" Sleep 500ms Enter
Sleep 5s

View File

@ -9,6 +9,7 @@ import (
func init() {
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)
}
@ -39,6 +40,12 @@ var addCmd = &cobra.Command{
// If duplicate key, increase count of card
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)
continue
}

View File

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

View File

@ -8,6 +8,7 @@ import (
"io/ioutil"
"log"
"net/http"
"strings"
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
@ -156,6 +157,12 @@ type Set struct {
}
func fetch_card(path string) (*Card, error) {
if !strings.Contains(path, "/") {
err := errors.New(fmt.Sprintf("Card must follow format <set>/<number>, for example: ath/15"))
return &Card{}, err
}
// TODO better URL Building...
resp, err := http.Get(fmt.Sprintf("https://api.scryfall.com/cards/%s/", path))
if err != nil {