Skip to content

Commit 723cb2a

Browse files
+ Improved CLI documentation
1 parent c4b490c commit 723cb2a

File tree

1 file changed

+100
-16
lines changed

1 file changed

+100
-16
lines changed

src/thread/cli/base.py

Lines changed: 100 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616

1717
cli_base = typer.Typer(
1818
no_args_is_help = True,
19+
rich_markup_mode = 'rich',
1920
context_settings = {
20-
'help_option_names': ['-h', '--help']
21+
'help_option_names': ['-h', '--help', 'help']
2122
}
2223
)
2324

@@ -41,12 +42,91 @@ def callback(
4142
verbose: bool = VerboseOption,
4243
quiet: bool = QuietOption
4344
):
44-
"""Thread CLI"""
45+
"""
46+
[b]Thread CLI[/b]\b\n
47+
[white]Use thread from the terminal![/white]
48+
49+
[blue][u] [/u][/blue]
50+
51+
Learn more from our [link=https://github.com/caffeine-addictt/thread/blob/main/docs/command-line.md]documentation![/link]
52+
"""
4553
verbose_args_processor(debug, verbose, quiet)
4654

4755

4856

49-
@cli_base.command(context_settings = {'allow_extra_args': True})
57+
# Help and Others
58+
@cli_base.command(rich_help_panel = 'Help and Others')
59+
def help():
60+
"""Get [yellow]help[/yellow] from the community. :question:"""
61+
typer.echo('Feel free to search for or ask questions here!')
62+
try:
63+
logger.info('Attempting to open in web browser...')
64+
65+
import webbrowser
66+
webbrowser.open(
67+
'https://github.com/caffeine-addictt/thread/issues',
68+
new = 2
69+
)
70+
typer.echo('Opening in web browser!')
71+
72+
except Exception as e:
73+
logger.warn('Failed to open web browser')
74+
logger.debug(f'{e}')
75+
typer.echo('https://github.com/caffeine-addictt/thread/issues')
76+
77+
78+
79+
@cli_base.command(rich_help_panel = 'Help and Others')
80+
def docs():
81+
"""View our [yellow]documentation.[/yellow] :book:"""
82+
typer.echo('Thanks for using Thread, here is our documentation!')
83+
try:
84+
logger.info('Attempting to open in web browser...')
85+
import webbrowser
86+
webbrowser.open(
87+
'https://github.com/caffeine-addictt/thread/blob/main/docs/command-line.md',
88+
new = 2
89+
)
90+
typer.echo('Opening in web browser!')
91+
92+
except Exception as e:
93+
logger.warn('Failed to open web browser')
94+
logger.debug(f'{e}')
95+
typer.echo('https://github.com/caffeine-addictt/thread/blob/main/docs/command-line.md')
96+
97+
98+
99+
@cli_base.command(rich_help_panel = 'Help and Others')
100+
def report():
101+
"""[yellow]Report[/yellow] an issue. :bug:"""
102+
typer.echo('Sorry you run into an issue, report it here!')
103+
try:
104+
logger.info('Attempting to open in web browser...')
105+
import webbrowser
106+
webbrowser.open(
107+
'https://github.com/caffeine-addictt/thread/issues',
108+
new = 2
109+
)
110+
typer.echo('Opening in web browser!')
111+
112+
except Exception as e:
113+
logger.warn('Failed to open web browser')
114+
logger.debug(f'{e}')
115+
typer.echo('https://github.com/caffeine-addictt/thread/issues')
116+
117+
118+
119+
# Utils and Configs
120+
@cli_base.command(rich_help_panel = 'Utils and Configs')
121+
def config(configuration: str):
122+
"""
123+
[blue]Configure[/blue] the system. :wrench:
124+
"""
125+
typer.echo('Coming soon!')
126+
127+
128+
129+
@cli_base.command(context_settings = {'allow_extra_args': True}, no_args_is_help = True)
50130
def process(
51131
ctx: typer.Context,
52132
func: str = typer.Argument(help = '(path.to.file:function_name) OR (lambda x: x)'),
@@ -65,14 +145,18 @@ def process(
65145
quiet: bool = QuietOption
66146
):
67147
"""
68-
Execute parallel processing\n
69-
Kwargs can be parsed by adding overflow arguments in pairs\n
70-
$ thread process ... k1 v1 k2 v2\n
71-
=> kwargs = {k1: v1, k2: v2}\n\n
72-
73-
Single kwargs will be ignored\n
74-
$ thread process ... a1\n
75-
=> kwargs = {}
148+
[bold]Utilise parallel processing on a dataset[/bold]
149+
150+
\b\n
151+
[bold]:glowing_star: Examples[/bold]
152+
Kwargs can be parsed by adding overflow arguments in pairs
153+
[green]$ thread process ... k1 v1 k2 v2[/green]
154+
=> kwargs = {k1: v1, k2: v2}
155+
156+
Single kwargs will be ignored
157+
[green]$ thread process ... a1[/green]
158+
=> kwargs = {}
159+
76160
"""
77161
verbose_args_processor(debug, verbose, quiet)
78162
kwargs = kwargs_processor(ctx)
@@ -169,8 +253,8 @@ def process(
169253
start_t = time.perf_counter()
170254
newProcess.start()
171255

172-
logger.info('Started parallel process')
173-
logger.info('Waiting for parallel process to complete, this may take a while...')
256+
typer.echo('Started parallel process')
257+
typer.echo('Waiting for parallel process to complete, this may take a while...')
174258

175259
with Progress(
176260
TextColumn('[bold blue]{task.description}', justify = 'right'),
@@ -191,13 +275,13 @@ def process(
191275

192276
result = newProcess.get_return_values()
193277

194-
logger.info(f'Completed in {(time.perf_counter() - start_t):.5f}s')
278+
typer.echo(f'Completed in {(time.perf_counter() - start_t):.5f}s')
195279
if fileout:
196-
logger.info(f'Writing file to {output}...')
280+
typer.echo(f'Writing file to {output}...')
197281
try:
198282
with open(output, 'w') as f:
199283
json.dump(result, f, indent = 2)
200-
logger.info(f'Wrote to file')
284+
typer.echo(f'Wrote to file')
201285
except Exception as e:
202286
logger.error('Failed to write to file')
203287
logger.debug(str(e))

0 commit comments

Comments
 (0)