mirror of
https://github.com/Benexl/FastAnime.git
synced 2026-01-18 23:55:40 -08:00
feat:create cli subpackage
This commit is contained in:
10
fastanime/cli/__init__.py
Normal file
10
fastanime/cli/__init__.py
Normal 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")
|
||||
3
fastanime/cli/commands/__init__.py
Normal file
3
fastanime/cli/commands/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from .anilist import anilist
|
||||
from .download import download
|
||||
from .search import search
|
||||
23
fastanime/cli/commands/anilist/__init__.py
Normal file
23
fastanime/cli/commands/anilist/__init__.py
Normal 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
|
||||
6
fastanime/cli/commands/anilist/favourites.py
Normal file
6
fastanime/cli/commands/anilist/favourites.py
Normal file
@@ -0,0 +1,6 @@
|
||||
import click
|
||||
|
||||
|
||||
@click.command()
|
||||
def favourites():
|
||||
print("favourites")
|
||||
6
fastanime/cli/commands/anilist/popular.py
Normal file
6
fastanime/cli/commands/anilist/popular.py
Normal file
@@ -0,0 +1,6 @@
|
||||
import click
|
||||
|
||||
|
||||
@click.command()
|
||||
def popular():
|
||||
print("popular")
|
||||
6
fastanime/cli/commands/anilist/recent.py
Normal file
6
fastanime/cli/commands/anilist/recent.py
Normal file
@@ -0,0 +1,6 @@
|
||||
import click
|
||||
|
||||
|
||||
@click.command()
|
||||
def recent():
|
||||
print("recent")
|
||||
6
fastanime/cli/commands/anilist/search.py
Normal file
6
fastanime/cli/commands/anilist/search.py
Normal file
@@ -0,0 +1,6 @@
|
||||
import click
|
||||
|
||||
|
||||
@click.command()
|
||||
def search():
|
||||
print("search")
|
||||
6
fastanime/cli/commands/anilist/trending.py
Normal file
6
fastanime/cli/commands/anilist/trending.py
Normal file
@@ -0,0 +1,6 @@
|
||||
import click
|
||||
|
||||
|
||||
@click.command()
|
||||
def trending():
|
||||
print("trending")
|
||||
6
fastanime/cli/commands/anilist/upcoming.py
Normal file
6
fastanime/cli/commands/anilist/upcoming.py
Normal file
@@ -0,0 +1,6 @@
|
||||
import click
|
||||
|
||||
|
||||
@click.command()
|
||||
def upcoming():
|
||||
print("upcoming")
|
||||
6
fastanime/cli/commands/download.py
Normal file
6
fastanime/cli/commands/download.py
Normal file
@@ -0,0 +1,6 @@
|
||||
import click
|
||||
|
||||
|
||||
@click.command()
|
||||
def download():
|
||||
print("download")
|
||||
6
fastanime/cli/commands/search.py
Normal file
6
fastanime/cli/commands/search.py
Normal file
@@ -0,0 +1,6 @@
|
||||
import click
|
||||
|
||||
|
||||
@click.command()
|
||||
def search():
|
||||
print("Searching")
|
||||
31
fastanime/cli/utils/fzf.py
Normal file
31
fastanime/cli/utils/fzf.py
Normal 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
|
||||
Reference in New Issue
Block a user