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