22
33from __future__ import annotations
44
5+ from collections .abc import Sequence
56import importlib .metadata
67import logging
78import optparse
89from pathlib import Path , PurePosixPath
910import sys
10- from typing import Sequence
1111
1212from .bots import load_bot
1313from .common import PROGRAM , Config , UnreachableError , ensure_state_home
@@ -41,7 +41,12 @@ def new_parser() -> optparse.OptionParser:
4141 )
4242
4343 def add_command (name : str , short : str | None = None , ** kwargs ) -> None :
44- def callback (_option , _opt , _value , parser ) -> None :
44+ def callback (
45+ _option : object ,
46+ _opt : object ,
47+ _value : object ,
48+ parser : optparse .OptionParser ,
49+ ) -> None :
4550 parser .values .command = name
4651
4752 parser .add_option (
@@ -128,20 +133,20 @@ class ToolPrinter(ToolVisitor):
128133 def on_list_files (
129134 self , _paths : Sequence [PurePosixPath ], _reason : str | None
130135 ) -> None :
131- print ( "Listing available files..." )
136+ pass
132137
133138 def on_read_file (
134139 self , path : PurePosixPath , _contents : str | None , _reason : str | None
135140 ) -> None :
136- print ( f"Reading { path !r } ..." )
141+ pass
137142
138143 def on_write_file (
139144 self , path : PurePosixPath , _contents : str , _reason : str | None
140145 ) -> None :
141- print ( f"Updated { path !r } ." )
146+ pass
142147
143148 def on_delete_file (self , path : PurePosixPath , _reason : str | None ) -> None :
144- print ( f"Deleted { path !r } ." )
149+ pass
145150
146151
147152def edit (* , path : Path | None = None , text : str | None = None ) -> str :
@@ -153,26 +158,23 @@ def edit(*, path: Path | None = None, text: str | None = None) -> str:
153158 # https://unix.stackexchange.com/q/604260
154159 elif path is None :
155160 assert text , "Empty path and text"
156- print (text )
157161 sys .exit (198 )
158162 else :
159163 if text is not None :
160164 with open (path , "w" ) as f :
161165 f .write (text )
162- print (path )
163166 sys .exit (199 )
164167
165168
166169_PROMPT_PLACEHOLDER = "Enter your prompt here..."
167170
168171
169- def main () -> None : # noqa: PLR0912 PLR0915
172+ def main () -> None : # noqa: PLR0912
170173 config = Config .load ()
171174 (opts , args ) = new_parser ().parse_args ()
172175
173176 log_path = ensure_state_home () / "log"
174177 if opts .log :
175- print (log_path )
176178 return
177179 logging .basicConfig (level = config .log_level , filename = str (log_path ))
178180
@@ -210,19 +212,16 @@ def main() -> None: # noqa: PLR0912 PLR0915
210212 reset = config .auto_reset if opts .reset is None else opts .reset ,
211213 sync = opts .sync ,
212214 )
213- print (f"Refined { name } ." )
214215 elif command == "finalize" :
215216 name = drafter .exit_draft (
216217 revert = opts .revert , clean = opts .clean , delete = opts .delete
217218 )
218- verb = "Reverted" if opts .revert else "Finalized"
219- print (f"{ verb } { name } ." )
220219 elif command == "show-drafts" :
221220 table = drafter .history_table (args [0 ] if args else None )
222221 if table :
223- print ( table . to_json () if opts . json else table )
222+ pass
224223 elif command == "show-prompts" :
225- raise NotImplementedError () # TODO
224+ raise NotImplementedError () # TODO: Implement
226225 elif command == "show-templates" :
227226 if args :
228227 name = args [0 ]
@@ -232,21 +231,17 @@ def main() -> None: # noqa: PLR0912 PLR0915
232231 edit (path = tpl .local_path (), text = tpl .source )
233232 else :
234233 edit (path = Template .local_path_for (name ))
235- else :
236- if not tpl :
237- raise ValueError (f"No template named { name !r} " )
238- print (tpl .source )
234+ elif not tpl :
235+ raise ValueError (f"No template named { name !r} " )
239236 else :
240237 table = templates_table ()
241- print (table .to_json () if opts .json else table )
242238 else :
243239 raise UnreachableError ()
244240
245241
246242if __name__ == "__main__" :
247243 try :
248244 main ()
249- except Exception as err :
245+ except Exception :
250246 _logger .exception ("Program failed." )
251- print (f"Error: { err } " , file = sys .stderr )
252247 sys .exit (1 )
0 commit comments