Skip to content

Commit

Permalink
feat: Migration from threadCore
Browse files Browse the repository at this point in the history
  • Loading branch information
caffeine-addictt committed Feb 4, 2024
1 parent b772991 commit df4f55e
Show file tree
Hide file tree
Showing 6 changed files with 506 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/thread-cli/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""
## ThreadCLI Library
Documentation: https://thread.ngjx.org
---
Released under the GPG-3 License
Copyright (c) 2020, thread.ngjx.org. All rights reserved.
"""

__version__ = "0.1.0"
from .utils.logging import CoreLogger, logging

# Export Core
from .base import cli_base as app
from .process import process as process_cli

app.commands(
name="process",
no_args_is_help=True,
context_settings={"allow_extra_args": True},
)(process_cli)


# Setup Logging
logging.setLoggerClass(CoreLogger)


# Wildcard export
__all__ = ["app"]
117 changes: 117 additions & 0 deletions src/thread-cli/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import typer
import logging

from . import __version__
from .utils import DebugOption, VerboseOption, QuietOption, verbose_args_processor
logger = logging.getLogger('base')


cli_base = typer.Typer(
no_args_is_help = True,
rich_markup_mode = 'rich',
context_settings = {
'help_option_names': ['-h', '--help', 'help']
}
)


def version_callback(value: bool):
if value:
typer.echo(f'v{__version__}')
raise typer.Exit()


@cli_base.callback(invoke_without_command = True)
def callback(
version: bool = typer.Option(
None, '--version',
callback = version_callback,
help = 'Get the current installed version',
is_eager = True
),

debug: bool = DebugOption,
verbose: bool = VerboseOption,
quiet: bool = QuietOption
):
"""
[b]Thread CLI[/b]\b\n
[white]Use thread from the terminal![/white]
[blue][u] [/u][/blue]
Learn more from our [link=https://github.com/python-thread/thread/blob/main/docs/command-line.md]documentation![/link]
"""
verbose_args_processor(debug, verbose, quiet)



# Help and Others
@cli_base.command(rich_help_panel = 'Help and Others')
def help():
"""Get [yellow]help[/yellow] from the community. :question:"""
typer.echo('Feel free to search for or ask questions here!')
try:
logger.info('Attempting to open in web browser...')

import webbrowser
webbrowser.open(
'https://github.com/python-thread/thread/issues',
new = 2
)
typer.echo('Opening in web browser!')

except Exception as e:
logger.warn('Failed to open web browser')
logger.debug(f'{e}')
typer.echo('https://github.com/python-thread/thread/issues')



@cli_base.command(rich_help_panel = 'Help and Others')
def docs():
"""View our [yellow]documentation.[/yellow] :book:"""
typer.echo('Thanks for using Thread, here is our documentation!')
try:
logger.info('Attempting to open in web browser...')
import webbrowser
webbrowser.open(
'https://github.com/python-thread/thread/blob/main/docs/command-line.md',
new = 2
)
typer.echo('Opening in web browser!')

except Exception as e:
logger.warn('Failed to open web browser')
logger.debug(f'{e}')
typer.echo('https://github.com/python-thread/thread/blob/main/docs/command-line.md')



@cli_base.command(rich_help_panel = 'Help and Others')
def report():
"""[yellow]Report[/yellow] an issue. :bug:"""
typer.echo('Sorry you run into an issue, report it here!')
try:
logger.info('Attempting to open in web browser...')
import webbrowser
webbrowser.open(
'https://github.com/python-thread/thread/issues',
new = 2
)
typer.echo('Opening in web browser!')

except Exception as e:
logger.warn('Failed to open web browser')
logger.debug(f'{e}')
typer.echo('https://github.com/python-thread/thread/issues')



# Utils and Configs
@cli_base.command(rich_help_panel = 'Utils and Configs')
def config(configuration: str):
"""
[blue]Configure[/blue] the system. :wrench:
"""
typer.echo('Coming soon!')
Loading

0 comments on commit df4f55e

Please sign in to comment.