3737
3838
3939app = typer .Typer (
40- name = "b64tool" ,
41- help = ("Multi-format encoding/decoding CLI "
42- "with recursive layer detection" ),
43- no_args_is_help = True ,
44- pretty_exceptions_show_locals = False ,
40+ name = "b64tool" ,
41+ help = ("Multi-format encoding/decoding CLI "
42+ "with recursive layer detection" ),
43+ no_args_is_help = True ,
44+ pretty_exceptions_show_locals = False ,
4545)
4646
47- _console = Console (stderr = True )
47+ _console = Console (stderr = True )
4848
4949
5050def _version_callback (value : bool ) -> None :
@@ -60,201 +60,201 @@ def main(
6060 typer .Option (
6161 "--version" ,
6262 "-v" ,
63- help = "Show version and exit." ,
64- callback = _version_callback ,
65- is_eager = True ,
63+ help = "Show version and exit." ,
64+ callback = _version_callback ,
65+ is_eager = True ,
6666 ),
6767 ] = False ,
6868) -> None :
6969 pass
7070
7171
72- @app .command (name = "encode" )
72+ @app .command (name = "encode" )
7373def encode_cmd (
7474 data : Annotated [
7575 str | None ,
76- typer .Argument (help = "Data to encode." ),
76+ typer .Argument (help = "Data to encode." ),
7777 ] = None ,
7878 fmt : Annotated [
7979 EncodingFormat ,
8080 typer .Option (
8181 "--format" ,
8282 "-f" ,
83- help = "Target encoding format." ,
83+ help = "Target encoding format." ,
8484 ),
8585 ] = EncodingFormat .BASE64 ,
8686 file : Annotated [
8787 Path | None ,
8888 typer .Option (
8989 "--file" ,
9090 "-i" ,
91- help = "Read input from file." ,
91+ help = "Read input from file." ,
9292 ),
9393 ] = None ,
9494 form : Annotated [
9595 bool ,
9696 typer .Option (
9797 "--form" ,
98- help = "Use form-encoding for URL (space becomes +)." ,
98+ help = "Use form-encoding for URL (space becomes +)." ,
9999 ),
100100 ] = False ,
101101) -> None :
102102 try :
103103 raw = resolve_input_bytes (data , file )
104104 if fmt == EncodingFormat .URL and form :
105- result = encode_url (raw , form = True )
105+ result = encode_url (raw , form = True )
106106 else :
107107 result = encode (raw , fmt )
108108 print_encoded (result , fmt )
109109 except typer .BadParameter :
110110 raise
111111 except Exception as exc :
112112 _console .print (f"[red]Error:[/red] { exc } " )
113- raise typer .Exit (code = ExitCode .ERROR ) from None
113+ raise typer .Exit (code = ExitCode .ERROR ) from None
114114
115115
116- @app .command (name = "decode" )
116+ @app .command (name = "decode" )
117117def decode_cmd (
118118 data : Annotated [
119119 str | None ,
120- typer .Argument (help = "Data to decode." ),
120+ typer .Argument (help = "Data to decode." ),
121121 ] = None ,
122122 fmt : Annotated [
123123 EncodingFormat ,
124124 typer .Option (
125125 "--format" ,
126126 "-f" ,
127- help = "Source encoding format." ,
127+ help = "Source encoding format." ,
128128 ),
129129 ] = EncodingFormat .BASE64 ,
130130 file : Annotated [
131131 Path | None ,
132132 typer .Option (
133133 "--file" ,
134134 "-i" ,
135- help = "Read input from file." ,
135+ help = "Read input from file." ,
136136 ),
137137 ] = None ,
138138 form : Annotated [
139139 bool ,
140140 typer .Option (
141141 "--form" ,
142- help = "Use form-decoding for URL (+ becomes space)." ,
142+ help = "Use form-decoding for URL (+ becomes space)." ,
143143 ),
144144 ] = False ,
145145) -> None :
146146 try :
147147 text = resolve_input_text (data , file )
148148 if fmt == EncodingFormat .URL and form :
149- result = decode_url (text , form = True )
149+ result = decode_url (text , form = True )
150150 else :
151151 result = decode (text , fmt )
152152 print_decoded (result )
153153 except typer .BadParameter :
154154 raise
155155 except Exception as exc :
156156 _console .print (f"[red]Error:[/red] { exc } " )
157- raise typer .Exit (code = ExitCode .ERROR ) from None
157+ raise typer .Exit (code = ExitCode .ERROR ) from None
158158
159159
160- @app .command (name = "detect" )
160+ @app .command (name = "detect" )
161161def detect_cmd (
162162 data : Annotated [
163163 str | None ,
164- typer .Argument (help = "Data to analyze." ),
164+ typer .Argument (help = "Data to analyze." ),
165165 ] = None ,
166166 file : Annotated [
167167 Path | None ,
168168 typer .Option (
169169 "--file" ,
170170 "-i" ,
171- help = "Read input from file." ,
171+ help = "Read input from file." ,
172172 ),
173173 ] = None ,
174174 verbose : Annotated [
175175 bool ,
176176 typer .Option (
177177 "--verbose" ,
178178 "-V" ,
179- help = "Show per-format score breakdown." ,
179+ help = "Show per-format score breakdown." ,
180180 ),
181181 ] = False ,
182182) -> None :
183183 try :
184184 text = resolve_input_text (data , file )
185185 results = detect_encoding (text )
186186 scores = score_all_formats (text ) if verbose else None
187- print_detection (results , verbose_scores = scores )
187+ print_detection (results , verbose_scores = scores )
188188 except typer .BadParameter :
189189 raise
190190 except Exception as exc :
191191 _console .print (f"[red]Error:[/red] { exc } " )
192- raise typer .Exit (code = ExitCode .ERROR ) from None
192+ raise typer .Exit (code = ExitCode .ERROR ) from None
193193
194194
195- @app .command (name = "peel" )
195+ @app .command (name = "peel" )
196196def peel_cmd (
197197 data : Annotated [
198198 str | None ,
199- typer .Argument (help = "Data to recursively decode." ),
199+ typer .Argument (help = "Data to recursively decode." ),
200200 ] = None ,
201201 file : Annotated [
202202 Path | None ,
203203 typer .Option (
204204 "--file" ,
205205 "-i" ,
206- help = "Read input from file." ,
206+ help = "Read input from file." ,
207207 ),
208208 ] = None ,
209209 max_depth : Annotated [
210210 int ,
211211 typer .Option (
212212 "--max-depth" ,
213213 "-d" ,
214- help = "Maximum decoding layers." ,
214+ help = "Maximum decoding layers." ,
215215 ),
216216 ] = PEEL_MAX_DEPTH ,
217217 verbose : Annotated [
218218 bool ,
219219 typer .Option (
220220 "--verbose" ,
221221 "-V" ,
222- help = "Show per-format score breakdown at each layer." ,
222+ help = "Show per-format score breakdown at each layer." ,
223223 ),
224224 ] = False ,
225225) -> None :
226226 try :
227227 text = resolve_input_text (data , file )
228- result = peel (text , max_depth = max_depth , verbose = verbose )
229- print_peel_result (result , verbose = verbose )
228+ result = peel (text , max_depth = max_depth , verbose = verbose )
229+ print_peel_result (result , verbose = verbose )
230230 except typer .BadParameter :
231231 raise
232232 except Exception as exc :
233233 _console .print (f"[red]Error:[/red] { exc } " )
234- raise typer .Exit (code = ExitCode .ERROR ) from None
234+ raise typer .Exit (code = ExitCode .ERROR ) from None
235235
236236
237- @app .command (name = "chain" )
237+ @app .command (name = "chain" )
238238def chain_cmd (
239239 data : Annotated [
240240 str | None ,
241- typer .Argument (help = "Data to encode through chain." ),
241+ typer .Argument (help = "Data to encode through chain." ),
242242 ] = None ,
243243 steps : Annotated [
244244 str ,
245245 typer .Option (
246246 "--steps" ,
247247 "-s" ,
248- help = ("Comma-separated encoding formats "
249- "(e.g. base64,hex,url)." ),
248+ help = ("Comma-separated encoding formats "
249+ "(e.g. base64,hex,url)." ),
250250 ),
251251 ] = "base64" ,
252252 file : Annotated [
253253 Path | None ,
254254 typer .Option (
255255 "--file" ,
256256 "-i" ,
257- help = "Read input from file." ,
257+ help = "Read input from file." ,
258258 ),
259259 ] = None ,
260260) -> None :
@@ -275,7 +275,7 @@ def chain_cmd(
275275 raise
276276 except Exception as exc :
277277 _console .print (f"[red]Error:[/red] { exc } " )
278- raise typer .Exit (code = ExitCode .ERROR ) from None
278+ raise typer .Exit (code = ExitCode .ERROR ) from None
279279
280280
281281def _parse_chain_steps (raw : str ) -> list [EncodingFormat ]:
0 commit comments