Skip to content

Commit

Permalink
Merge pull request #1 from EmperorPenguin18/testing
Browse files Browse the repository at this point in the history
PR for 0.2
  • Loading branch information
EmperorPenguin18 authored May 27, 2022
2 parents 86194b8 + b8569d8 commit 5cd44d0
Show file tree
Hide file tree
Showing 8 changed files with 400 additions and 158 deletions.
6 changes: 3 additions & 3 deletions PKGBUILD
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# Maintainer: Sebastien MacDougall-Landry

pkgname=scrycli
pkgver=0.1
pkgver=0.2
pkgrel=1
pkgdesc='CLI tool for Scryfall'
url='https://github.com/EmperorPenguin18/scrycli/'
source=("$pkgname-$pkgver.tar.gz::https://github.com/EmperorPenguin18/scrycli/archive/refs/tags/$pkgver.tar.gz")
arch=('x86_64')
license=('GPL3')
makedepends=('pandoc')
depends=('libscry')
depends=('libscry' 'chafa')
sha256sums=('72fb7097fc196a663b49408c2a405ab67b2fea1b47a72f9f5163fae6de283c98')

build () {
cd "$srcdir/$pkgname-$pkgver"
g++ -std=c++20 scrycli.cc -ldl -o scrycli
g++ -O3 src/*.cc -o scrycli
pandoc scrycli.1.md -s -t man -o scrycli.1
}

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# scrycli
CLI tool for Scryfall
## Dependencies
[libscry](https://github.com/EmperorPenguin18/libscry)
[libscry](https://github.com/EmperorPenguin18/libscry), chafa
## Installation

Arch
Expand All @@ -18,14 +18,14 @@ Other Linux
```
git clone https://github.com/EmperorPenguin18/scrycli
cd scrycli
make
make release
make install #as root
```

## Usage

```
scrycli SEARCH
scrycli [OPTION...] SEARCH...
```
Read the man page for more info

Expand Down
13 changes: 11 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
build: scrycli.cc scrycli.1.md
g++ -std=c++20 scrycli.cc -ldl -o scrycli
build: src/*.cc scrycli.1.md
g++ -g -Og -D DEBUG src/*.cc -o scrycli
pandoc scrycli.1.md -s -t man -o scrycli.1
gzip -f scrycli.1

release: src/*.cc scrycli.1.md
g++ -O3 src/*.cc -o scrycli
pandoc scrycli.1.md -s -t man -o scrycli.1
gzip -f scrycli.1

Expand All @@ -12,3 +17,7 @@ install: scrycli
uninstall:
@rm /usr/bin/scrycli
@rm /usr/share/man/man1/scrycli.1.gz

clean:
rm -f scrycli
rm -f scrycli.1.gz
18 changes: 11 additions & 7 deletions scrycli.1.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
% SCRYCLI(1) scrycli 0.1
% Sebastien MacDougall-Landry
% November 2021
% May 2022

# NAME
scrycli - get Magic: The Gathering card data on the terminal

# SYNOPSIS
**scrycli** *SEARCH*
**scrycli** *[OPTION...]* *SEARCH...*

# DESCRIPTION
**scrycli** uses libscry to fetch card data from Scryfall and cache it. Works as a terminal counterpart to the Scryfall website.

# OPTIONS
**-i**
: Shows the image of the resulting card(s) in the terminal. Looks best in kitty. Will have different behaviour depending on what mode is used.

# EXAMPLES
**scrycli vannifar**
: Outputs just the card Prime Speaker Vannifar.
**scrycli -i vannifar**
: Outputs just the card Prime Speaker Vannifar, with image.

**scrycli color=g+type:legendary+type:creature+legal:commander**
**scrycli color=g type:legendary type:creature legal:commander**
: Outputs all legal mono-green commanders.

**scrycli is:funny**
Expand All @@ -28,7 +32,7 @@ Scrycli will usually exit with 0 unless you encounter a bug.


# BUGS
If there are no results to your search, the program crashes.
Images are displayed in a very unsophisticated way

# COPYRIGHT
Copyright © 2021 Sebastien MacDougall-Landry. License GPLv3+: GNU GPL version 3 or later . This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
Copyright © 2022 Sebastien MacDougall-Landry. License GPLv3+: GNU GPL version 3 or later . This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
143 changes: 0 additions & 143 deletions scrycli.cc

This file was deleted.

131 changes: 131 additions & 0 deletions src/main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
//Scrycli by Sebastien MacDougall-Landry
//License is available at
//https://github.com/EmperorPenguin18/scrycli/blob/main/LICENSE

#include "scrycli.h"

using namespace std;

const char *argp_program_version = "scrycli 0.2";
const char *argp_program_bug_address = "https://github.com/EmperorPenguin18/scrycli/issues";
static char doc[] = "scrycli uses libscry to fetch card data from Scryfall and cache it. Works as a terminal counterpart to the Scryfall website.";
static char args_doc[] = "SEARCH...";
static struct argp_option options[] = {
{ "image", 'i', 0, 0, "Show images of cards in the terminal"},
{ "random", 'r', 0, 0, "See a random card"},
{ "advanced", 'a', 0, 0, "Input search terms interactively"},
{ "set", 's', 0, 0, "Look at a list of sets"},
{ "terse", 't', 0, 0, "Only output the names of cards"},
{ 0 }
};

enum modes{ NORMAL_MODE, SINGLE_MODE, RANDOM_MODE, ADVANCED_MODE, SET_MODE, TERSE_MODE };
struct arguments {
enum modes mode;
bool imageMode;
};

bool stopchecking = false;

static error_t parse_opt(int key, char *arg, struct argp_state *state) {
struct arguments *arguments = (struct arguments*)state->input;
switch (key) {
case 'i': arguments->imageMode = true; break;
case 'r': arguments->mode = RANDOM_MODE; break;
case 'a': arguments->mode = ADVANCED_MODE; break;
case 's': arguments->mode = SET_MODE; break;
case 't': arguments->mode = TERSE_MODE; break;
case ARGP_KEY_ARG: return 0;
default: return ARGP_ERR_UNKNOWN;
}
return 0;
}

static struct argp argp = { options, parse_opt, args_doc, doc, 0, 0, 0 };

bool symbol = false;

static char* cat_args(int argc, char **argv) {
char* output = (char*)calloc(1, 1);
size_t length = 0;
for (int i = 1; i < argc; i++) {
#ifdef DEBUG
fprintf(stderr, "Arg: %s\n", argv[i]);
#endif
length += strlen(argv[i])+1;
output = (char*)realloc(output, length+1);
if (symbol == false) {
if (strchr(argv[i], ':') != NULL) {
symbol = true;
} else if (strchr(argv[i], '<') != NULL) {
symbol = true;
} else if (strchr(argv[i], '>') != NULL) {
symbol = true;
}
#ifdef DEBUG
fprintf(stderr, "Symbol: %d\n", symbol);
#endif
}
if (argv[i][0] != '-' || stopchecking) {
#ifdef DEBUG
fprintf(stderr, "Adding\n");
#endif
strcat(output, argv[i]);
strcat(output, " ");
}
if (strcmp(argv[i], "--") == 0) stopchecking = true;
}
return output;
}

int main(int argc, char **argv) {
if (argc > 1) {
struct arguments arguments;
arguments.mode = NORMAL_MODE;
arguments.imageMode = false;
argp_parse(&argp, argc, argv, 0, 0, &arguments);
ScryCli scrycli(35, 10);
char* search = cat_args(argc, argv);
#ifdef DEBUG
fprintf(stderr, "Query: %s\n", search);
#endif
if (arguments.mode == NORMAL_MODE && symbol == false)
arguments.mode = SINGLE_MODE;

#ifdef DEBUG
fprintf(stderr, "Mode: %d\n", arguments.mode);
#endif
if (arguments.mode == NORMAL_MODE) {
if (arguments.imageMode == false) {
cout << scrycli.multi(search);
} else {
cout << scrycli.multi_image(search);
}
} else if (arguments.mode == SINGLE_MODE) {
if (arguments.imageMode == false) {
cout << scrycli.single(search);
} else {
cout << scrycli.single_image(search);
}
} else if (arguments.mode == RANDOM_MODE) {
if (arguments.imageMode == false) {
fprintf(stderr, "Random mode not implemented yet\n");
} else {
fprintf(stderr, "Random mode not implemented yet\n");
}
} else if (arguments.mode == ADVANCED_MODE) {
if (arguments.imageMode == false) {
fprintf(stderr, "Advanced mode not implemented yet\n");
} else {
fprintf(stderr, "Advanced mode not implemented yet\n");
}
} else if (arguments.mode == SET_MODE) {
fprintf(stderr, "Set mode not implemented yet\n");
} else if (arguments.mode == TERSE_MODE) {
fprintf(stderr, "Terse mode not implemented yet\n");
}

free(search);
}
return 0;
}
Loading

0 comments on commit 5cd44d0

Please sign in to comment.