feat:create cli subpackage

This commit is contained in:
Benex254
2024-06-19 20:43:23 +03:00
parent f93d524f68
commit 4a2c981dff
77 changed files with 161 additions and 212 deletions

10
fastanime/cli/__init__.py Normal file
View File

@@ -0,0 +1,10 @@
import click
from rich import print
from .commands import search, download, anilist
commands = {"search": search, "download": download, "anilist": anilist}
@click.group(commands=commands)
def run_cli():
print("Yellow")

View File

@@ -0,0 +1,3 @@
from .anilist import anilist
from .download import download
from .search import search

View File

@@ -0,0 +1,23 @@
import click
from .favourites import favourites
from .recent import recent
from .search import search
from .popular import popular
from .trending import trending
from .upcoming import upcoming
commands = {
"favourites": favourites,
"recent": recent,
"search": search,
"popular": popular,
"trending": trending,
"upcoming": upcoming,
}
@click.group(commands=commands)
def anilist():
pass

View File

@@ -0,0 +1,6 @@
import click
@click.command()
def favourites():
print("favourites")

View File

@@ -0,0 +1,6 @@
import click
@click.command()
def popular():
print("popular")

View File

@@ -0,0 +1,6 @@
import click
@click.command()
def recent():
print("recent")

View File

@@ -0,0 +1,6 @@
import click
@click.command()
def search():
print("search")

View File

@@ -0,0 +1,6 @@
import click
@click.command()
def trending():
print("trending")

View File

@@ -0,0 +1,6 @@
import click
@click.command()
def upcoming():
print("upcoming")

View File

@@ -0,0 +1,6 @@
import click
@click.command()
def download():
print("download")

View File

@@ -0,0 +1,6 @@
import click
@click.command()
def search():
print("Searching")

View File

@@ -0,0 +1,31 @@
import subprocess
import logging
logger = logging.getLogger(__name__)
def run_fzf(options: tuple[str], *custom_commands):
"""
Run fzf with a list of options and return the selected option.
"""
# Join the list of options into a single string with newlines
options_str = "\n".join(options)
# Run fzf as a subprocess
result = subprocess.run(
["fzf", *custom_commands],
input=options_str,
text=True,
stdout=subprocess.PIPE,
)
# Check if fzf was successful
if result.returncode == 0:
# Return the selected option
selection = result.stdout.strip()
logger.info(f"fzf: selected {selection}")
return selection
else:
# Handle the case where fzf fails or is canceled
logger.error("fzf was canceled or failed")
return None