-
Notifications
You must be signed in to change notification settings - Fork 1
/
mkcmd.py
54 lines (43 loc) · 1.66 KB
/
mkcmd.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import logging
from typer import Option, Typer
from language_map import get_language
from txt2cmd.filer import read, write
from txt2cmd.Txt2Cmd import ChatTxt2Cmd
app = Typer()
@app.command()
def new(
prompt: str,
out_file: str = Option(None, "--out-file", help="File to write the result to."),
log_level: str = Option("INFO", "--log-level", help="The level of logger output."),
) -> None:
"""Generate a new script based on a given prompt
Args:
prompt (str): User defined prompt for script contents
out_file (str, optional): Filename to write script contents. Defaults to None.
log_level (str, optional): Output log level. Defaults to "INFO".
"""
logging.basicConfig(level=log_level)
cc = ChatTxt2Cmd()
response = cc.generate_script(prompt, get_language(out_file))
write(response, file=out_file)
@app.command()
def update(
in_file: str,
prompt: str,
out_file: str = Option(None, "--out-file", help="File to write the result to."),
log_level: str = Option("INFO", "--log-level", help="The level of logger output."),
) -> None:
"""Update a given script based on user prompt
Args:
in_file (str): Filename of script to update
prompt (str): User defined prompt for script contents
out_file (str, optional): Filename to write script contents. Defaults to None.
log_level (str, optional): Output log level. Defaults to "INFO".
"""
logging.basicConfig(level=log_level)
content = read(in_file)
cc = ChatTxt2Cmd()
response = cc.generate_script(prompt, get_language(in_file), content)
write(response, file=out_file)
if __name__ == "__main__":
app()