mirror of
https://github.com/dmunozv04/iSponsorBlockTV.git
synced 2026-01-27 12:50:52 +03:00
rework cli
This commit is contained in:
@@ -8,3 +8,4 @@ ssdp==1.3.0
|
|||||||
textual==0.58.0
|
textual==0.58.0
|
||||||
textual-slider==0.1.1
|
textual-slider==0.1.1
|
||||||
xmltodict==0.13.0
|
xmltodict==0.13.0
|
||||||
|
rich_click==1.8.3
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import argparse
|
import rich_click as click
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
@@ -126,35 +126,59 @@ class Config:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def app_start():
|
@click.group(invoke_without_command=True)
|
||||||
# If env has a data dir use that, otherwise use the default
|
@click.option('--data', '-d', default=lambda: os.getenv("iSPBTV_data_dir") or user_data_dir("iSponsorBlockTV", "dmunozv04"), help='data directory')
|
||||||
default_data_dir = os.getenv("iSPBTV_data_dir") or user_data_dir(
|
@click.option('--debug', is_flag=True, help='debug mode')
|
||||||
"iSponsorBlockTV", "dmunozv04"
|
#legacy commands as arguments
|
||||||
)
|
@click.option('--setup', is_flag=True, help='Setup the program graphically', hidden=True)
|
||||||
parser = argparse.ArgumentParser(description="iSponsorblockTV")
|
@click.option('--setup-cli', is_flag=True, help='Setup the program in the command line', hidden=True)
|
||||||
parser.add_argument(
|
@click.pass_context
|
||||||
"--data-dir", "-d", default=default_data_dir, help="data directory"
|
def cli(ctx, data, debug, setup, setup_cli):
|
||||||
)
|
"""iSponsorblockTV"""
|
||||||
parser.add_argument(
|
ctx.ensure_object(dict)
|
||||||
"--setup", "-s", action="store_true", help="setup the program graphically"
|
ctx.obj['data_dir'] = data
|
||||||
)
|
ctx.obj['debug'] = debug
|
||||||
parser.add_argument(
|
if debug:
|
||||||
"--setup-cli",
|
|
||||||
"-sc",
|
|
||||||
action="store_true",
|
|
||||||
help="setup the program in the command line",
|
|
||||||
)
|
|
||||||
parser.add_argument("--debug", action="store_true", help="debug mode")
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
config = Config(args.data_dir)
|
|
||||||
if args.debug:
|
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
if args.setup: # Set up the config file graphically
|
if ctx.invoked_subcommand is None:
|
||||||
setup_wizard.main(config)
|
if setup:
|
||||||
sys.exit()
|
ctx.invoke(setup_command)
|
||||||
if args.setup_cli: # Set up the config file
|
elif setup_cli:
|
||||||
config_setup.main(config, args.debug)
|
ctx.invoke(setup_cli_command)
|
||||||
else:
|
else:
|
||||||
config.validate()
|
ctx.invoke(start)
|
||||||
main.main(config, args.debug)
|
|
||||||
|
@cli.command()
|
||||||
|
@click.pass_context
|
||||||
|
def setup(ctx):
|
||||||
|
"""Setup the program graphically"""
|
||||||
|
config = Config(ctx.obj['data_dir'])
|
||||||
|
setup_wizard.main(config)
|
||||||
|
sys.exit()
|
||||||
|
setup_command = setup
|
||||||
|
@cli.command()
|
||||||
|
@click.pass_context
|
||||||
|
def setup_cli(ctx):
|
||||||
|
"""Setup the program in the command line"""
|
||||||
|
config = Config(ctx.obj['data_dir'])
|
||||||
|
config_setup.main(config, ctx.obj['debug'])
|
||||||
|
setup_cli_command = setup_cli
|
||||||
|
@cli.command()
|
||||||
|
@click.pass_context
|
||||||
|
def start(ctx):
|
||||||
|
"""Start the main program"""
|
||||||
|
config = Config(ctx.obj['data_dir'])
|
||||||
|
config.validate()
|
||||||
|
main.main(config, ctx.obj['debug'])
|
||||||
|
|
||||||
|
# Create fake "self" group to show pyapp options in help menu
|
||||||
|
#Subcommands remove, restore, update
|
||||||
|
pyapp_group = click.RichGroup("self", help="pyapp options (update, remove, restore)")
|
||||||
|
pyapp_group.add_command(click.RichCommand("update", help="Update the package to the latest version"))
|
||||||
|
pyapp_group.add_command(click.Command("remove", help="Remove the package, wiping the installation but not the data"))
|
||||||
|
pyapp_group.add_command(click.RichCommand("restore", help="Restore the package to its original state by reinstalling it"))
|
||||||
|
if os.getenv("PYAPP"):
|
||||||
|
cli.add_command(pyapp_group)
|
||||||
|
|
||||||
|
def app_start():
|
||||||
|
cli(obj={})
|
||||||
Reference in New Issue
Block a user