Skip to content

Commit 0fdb2e8

Browse files
committed
fix: correct all indentation errors in main_callback
- Fix indentation for debug_manager calls (lines 226-264) - Fix indentation for custom_gettext function (lines 273-341) - Fix indentation for hasattr check (lines 322-341) - Ensure all code inside main_callback is properly indented - This fixes NameError: name 'debug' is not defined
1 parent 5f40583 commit 0fdb2e8

1 file changed

Lines changed: 87 additions & 83 deletions

File tree

src/main.py

Lines changed: 87 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -246,107 +246,111 @@ def main_callback(
246246
"Config Content": config_lang if config_lang else "None",
247247
}
248248

249-
debug_manager.print_config_info(config_info)
250-
debug_manager.print_environment_info()
251-
debug_manager.print_system_info()
252-
253-
# Re-initialize translation in callback to handle runtime language changes
254-
i18n.init_translation(selected_lang)
255-
builtins._ = i18n._ # Update builtins._ after re-initialization
256-
257-
# Print translation information
258-
translation_info = {
259-
"Language Code": selected_lang,
260-
"Locale Directory": i18n.LOCALE_BASE_DIR,
261-
"Text Domain": i18n.TEXT_DOMAIN,
262-
"Current Language": i18n.translator_instance.get_current_language(),
263-
}
264-
debug_manager.print_translation_info(selected_lang, translation_info)
265-
266-
# Try to inject our translations into Click's gettext domain
267-
try:
268-
import gettext
269-
import click
249+
debug_manager.print_config_info(config_info)
250+
debug_manager.print_environment_info()
251+
debug_manager.print_system_info()
252+
253+
# Re-initialize translation in callback to handle runtime language changes
254+
i18n.init_translation(selected_lang)
255+
builtins._ = i18n._ # Update builtins._ after re-initialization
256+
257+
# Print translation information
258+
translation_info = {
259+
"Language Code": selected_lang,
260+
"Locale Directory": i18n.LOCALE_BASE_DIR,
261+
"Text Domain": i18n.TEXT_DOMAIN,
262+
"Current Language": i18n.translator_instance.get_current_language(),
263+
}
264+
debug_manager.print_translation_info(selected_lang, translation_info)
270265

271-
_ = i18n.get_translator()
266+
# Try to inject our translations into Click's gettext domain
267+
try:
268+
import gettext
269+
import click
272270

273-
def custom_gettext(message):
274-
if debug:
275-
console.print(
276-
f"[dim cyan]DEBUG: Click requesting translation for: '{message}'[/dim cyan]"
277-
)
271+
_ = i18n.get_translator()
272+
273+
def custom_gettext(message):
274+
if debug:
275+
console.print(
276+
f"[dim cyan]DEBUG: Click requesting translation for: '{message}'[/dim cyan]"
277+
)
278278

279-
translated = _(message)
279+
translated = _(message)
280280

281-
if debug:
282-
console.print(
283-
f"[dim cyan]DEBUG: Our translation result: '{translated}'[/dim cyan]"
284-
)
281+
if debug:
282+
console.print(
283+
f"[dim cyan]DEBUG: Our translation result: '{translated}'[/dim cyan]"
284+
)
285285

286-
if translated != message:
286+
if translated != message:
287+
if debug:
288+
console.print(
289+
f"[dim green]DEBUG: Using our translation: '{translated}'[/dim green]"
290+
)
291+
return translated
287292
if debug:
288293
console.print(
289-
f"[dim green]DEBUG: Using our translation: '{translated}'[/dim green]"
294+
f"[dim yellow]DEBUG: Using original message: '{message}'[/dim yellow]"
290295
)
291-
return translated
296+
return message
297+
298+
click.core._ = custom_gettext
292299
if debug:
293300
console.print(
294-
f"[dim yellow]DEBUG: Using original message: '{message}'[/dim yellow]"
301+
"[dim green]DEBUG: Replaced Click's gettext function[/dim green]"
295302
)
296-
return message
297303

298-
click.core._ = custom_gettext
299-
if debug:
300-
console.print(
301-
"[dim green]DEBUG: Replaced Click's gettext function[/dim green]"
302-
)
303-
304-
except Exception as e:
305-
if debug:
306-
console.print(
307-
f"[dim red]DEBUG: Failed to replace Click's gettext function: {e}[/dim red]"
308-
)
304+
except Exception as e:
305+
if debug:
306+
console.print(
307+
f"[dim red]DEBUG: Failed to replace Click's gettext function: {e}[/dim red]"
308+
)
309309

310-
if ping:
311-
from src.options.ping import run_ping
310+
if ping:
311+
from src.options.ping import run_ping
312312

313-
run_ping()
314-
raise typer.Exit()
315-
if field:
316-
from src.options.field import run_field
313+
run_ping()
314+
raise typer.Exit()
315+
if field:
316+
from src.options.field import run_field
317317

318-
run_field()
319-
raise typer.Exit()
318+
run_field()
319+
raise typer.Exit()
320320

321-
# Dynamically modify the help text for completion commands
322-
if hasattr(app, "registered_commands") and isinstance(
323-
app.registered_commands, dict
324-
):
325-
debug_manager.debug("Dynamically modifying help texts for completion commands.")
326-
for command_name, command_obj in app.registered_commands.items():
327-
original_help = command_obj.help
328-
if command_name == "install-completion":
329-
command_obj.help = i18n._("Install completion for the current shell.")
330-
elif command_name == "show-completion":
331-
command_obj.help = i18n._(
332-
"Show completion for the current shell, to copy it or customize the installation."
333-
)
334-
elif command_name == "help":
335-
command_obj.help = i18n._("Show this message and exit.")
321+
# Dynamically modify the help text for completion commands
322+
if hasattr(app, "registered_commands") and isinstance(
323+
app.registered_commands, dict
324+
):
325+
debug_manager.debug(
326+
"Dynamically modifying help texts for completion commands."
327+
)
328+
for command_name, command_obj in app.registered_commands.items():
329+
original_help = command_obj.help
330+
if command_name == "install-completion":
331+
command_obj.help = i18n._(
332+
"Install completion for the current shell."
333+
)
334+
elif command_name == "show-completion":
335+
command_obj.help = i18n._(
336+
"Show completion for the current shell, to copy it or customize the installation."
337+
)
338+
elif command_name == "help":
339+
command_obj.help = i18n._("Show this message and exit.")
336340

337-
if debug_manager.debug_enabled:
338-
debug_manager.debug(
339-
f"Command '{command_name}': Original help='{original_help}', New help='{command_obj.help}'"
340-
)
341+
if debug_manager.debug_enabled:
342+
debug_manager.debug(
343+
f"Command '{command_name}': Original help='{original_help}', New help='{command_obj.help}'"
344+
)
341345

342-
# If no subcommand is invoked and no explicit help is requested,
343-
# display only the "Commands" section.
344-
if ctx.invoked_subcommand is None and not any(
345-
arg in ["-h", "--help"] for arg in sys.argv
346-
):
347-
if not ping and not field:
348-
# Capture the full help output by explicitly calling the app with --help
349-
help_output_capture = StringIO()
346+
# If no subcommand is invoked and no explicit help is requested,
347+
# display only the "Commands" section.
348+
if ctx.invoked_subcommand is None and not any(
349+
arg in ["-h", "--help"] for arg in sys.argv
350+
):
351+
if not ping and not field:
352+
# Capture the full help output by explicitly calling the app with --help
353+
help_output_capture = StringIO()
350354
with redirect_stdout(help_output_capture):
351355
try:
352356
# Call the app with --help to get the full help output

0 commit comments

Comments
 (0)