Skip to content

Commit df4f55e

Browse files
feat: Migration from threadCore
1 parent b772991 commit df4f55e

6 files changed

Lines changed: 506 additions & 0 deletions

File tree

src/thread-cli/__init__.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""
2+
## ThreadCLI Library
3+
Documentation: https://thread.ngjx.org
4+
5+
6+
---
7+
8+
Released under the GPG-3 License
9+
10+
Copyright (c) 2020, thread.ngjx.org. All rights reserved.
11+
"""
12+
13+
__version__ = "0.1.0"
14+
from .utils.logging import CoreLogger, logging
15+
16+
# Export Core
17+
from .base import cli_base as app
18+
from .process import process as process_cli
19+
20+
app.commands(
21+
name="process",
22+
no_args_is_help=True,
23+
context_settings={"allow_extra_args": True},
24+
)(process_cli)
25+
26+
27+
# Setup Logging
28+
logging.setLoggerClass(CoreLogger)
29+
30+
31+
# Wildcard export
32+
__all__ = ["app"]

src/thread-cli/base.py

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import typer
2+
import logging
3+
4+
from . import __version__
5+
from .utils import DebugOption, VerboseOption, QuietOption, verbose_args_processor
6+
logger = logging.getLogger('base')
7+
8+
9+
cli_base = typer.Typer(
10+
no_args_is_help = True,
11+
rich_markup_mode = 'rich',
12+
context_settings = {
13+
'help_option_names': ['-h', '--help', 'help']
14+
}
15+
)
16+
17+
18+
def version_callback(value: bool):
19+
if value:
20+
typer.echo(f'v{__version__}')
21+
raise typer.Exit()
22+
23+
24+
@cli_base.callback(invoke_without_command = True)
25+
def callback(
26+
version: bool = typer.Option(
27+
None, '--version',
28+
callback = version_callback,
29+
help = 'Get the current installed version',
30+
is_eager = True
31+
),
32+
33+
debug: bool = DebugOption,
34+
verbose: bool = VerboseOption,
35+
quiet: bool = QuietOption
36+
):
37+
"""
38+
[b]Thread CLI[/b]\b\n
39+
[white]Use thread from the terminal![/white]
40+
41+
[blue][u] [/u][/blue]
42+
43+
Learn more from our [link=https://github.com/python-thread/thread/blob/main/docs/command-line.md]documentation![/link]
44+
"""
45+
verbose_args_processor(debug, verbose, quiet)
46+
47+
48+
49+
# Help and Others
50+
@cli_base.command(rich_help_panel = 'Help and Others')
51+
def help():
52+
"""Get [yellow]help[/yellow] from the community. :question:"""
53+
typer.echo('Feel free to search for or ask questions here!')
54+
try:
55+
logger.info('Attempting to open in web browser...')
56+
57+
import webbrowser
58+
webbrowser.open(
59+
'https://github.com/python-thread/thread/issues',
60+
new = 2
61+
)
62+
typer.echo('Opening in web browser!')
63+
64+
except Exception as e:
65+
logger.warn('Failed to open web browser')
66+
logger.debug(f'{e}')
67+
typer.echo('https://github.com/python-thread/thread/issues')
68+
69+
70+
71+
@cli_base.command(rich_help_panel = 'Help and Others')
72+
def docs():
73+
"""View our [yellow]documentation.[/yellow] :book:"""
74+
typer.echo('Thanks for using Thread, here is our documentation!')
75+
try:
76+
logger.info('Attempting to open in web browser...')
77+
import webbrowser
78+
webbrowser.open(
79+
'https://github.com/python-thread/thread/blob/main/docs/command-line.md',
80+
new = 2
81+
)
82+
typer.echo('Opening in web browser!')
83+
84+
except Exception as e:
85+
logger.warn('Failed to open web browser')
86+
logger.debug(f'{e}')
87+
typer.echo('https://github.com/python-thread/thread/blob/main/docs/command-line.md')
88+
89+
90+
91+
@cli_base.command(rich_help_panel = 'Help and Others')
92+
def report():
93+
"""[yellow]Report[/yellow] an issue. :bug:"""
94+
typer.echo('Sorry you run into an issue, report it here!')
95+
try:
96+
logger.info('Attempting to open in web browser...')
97+
import webbrowser
98+
webbrowser.open(
99+
'https://github.com/python-thread/thread/issues',
100+
new = 2
101+
)
102+
typer.echo('Opening in web browser!')
103+
104+
except Exception as e:
105+
logger.warn('Failed to open web browser')
106+
logger.debug(f'{e}')
107+
typer.echo('https://github.com/python-thread/thread/issues')
108+
109+
110+
111+
# Utils and Configs
112+
@cli_base.command(rich_help_panel = 'Utils and Configs')
113+
def config(configuration: str):
114+
"""
115+
[blue]Configure[/blue] the system. :wrench:
116+
"""
117+
typer.echo('Coming soon!')

0 commit comments

Comments
 (0)