Coverage for src / ezxl / cli / main.py: 95.12%

39 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-10-17 10:25 +0000

1# /////////////////////////////////////////////////////////////// 

2# EZXL - CLI Main Entry Point 

3# Project: ezxl 

4# /////////////////////////////////////////////////////////////// 

5 

6""" 

7Main CLI entry point for EzXl Excel automation library. 

8 

9This module provides the command-line interface for managing EzXl 

10configuration and performing various operations. 

11""" 

12 

13from __future__ import annotations 

14 

15# /////////////////////////////////////////////////////////////// 

16# IMPORTS 

17# /////////////////////////////////////////////////////////////// 

18# Third-party imports 

19import click 

20from rich.panel import Panel 

21from rich.text import Text 

22 

23# Local imports 

24from .._version import __version__ 

25from ._console import console 

26from .commands import _docs, _info, _version 

27 

28# /////////////////////////////////////////////////////////////// 

29# CLI GROUP 

30# /////////////////////////////////////////////////////////////// 

31 

32 

33@click.group( 

34 name="ezxl", 

35 invoke_without_command=True, 

36 context_settings={"help_option_names": ["-h", "--help"]}, 

37) 

38@click.version_option( 

39 __version__, 

40 "-v", 

41 "--version", 

42 prog_name="EzXl CLI", 

43 message="%(prog)s version %(version)s", 

44) 

45@click.pass_context 

46def cli(ctx: click.Context) -> None: 

47 """ 

48 EzXl CLI - Excel Automation Library 

49 

50 Command-line interface for managing EzXl Excel automation operations. 

51 

52 Use 'ezxl <command> --help' for more information on a specific command. 

53 """ 

54 # If no subcommand is invoked, display the welcome screen and help 

55 if ctx.invoked_subcommand is None: 

56 _display_welcome() 

57 click.echo(ctx.get_help()) 

58 

59 

60def _display_welcome() -> None: 

61 """Display welcome message with Rich.""" 

62 try: 

63 welcome_text = Text() 

64 welcome_text.append("🚀 ", style="bold bright_green") 

65 welcome_text.append("EzXl CLI", style="bold bright_blue") 

66 welcome_text.append(" - Excel Automation Library", style="dim white") 

67 

68 panel = Panel( 

69 welcome_text, 

70 title="[bold bright_blue]Welcome[/bold bright_blue]", 

71 border_style="bright_blue", 

72 padding=(1, 2), 

73 ) 

74 console.print(panel) 

75 except (OSError, RuntimeError, ValueError): 

76 # Fallback if Rich is not available 

77 click.echo("EzXl CLI - Excel Automation Library") 

78 

79 

80# /////////////////////////////////////////////////////////////// 

81# COMMAND GROUPS 

82# /////////////////////////////////////////////////////////////// 

83 

84 

85# Register commands and groups 

86cli.add_command(_version.version_command) 

87cli.add_command(_info.info_command) 

88cli.add_command(_docs.docs_command) 

89 

90 

91# /////////////////////////////////////////////////////////////// 

92# MAIN ENTRY POINT 

93# /////////////////////////////////////////////////////////////// 

94 

95 

96def main() -> None: 

97 """ 

98 Main entry point for the CLI. 

99 

100 This function is called when the CLI is invoked from the command line. 

101 """ 

102 try: 

103 cli() 

104 except click.ClickException as e: 

105 e.show() 

106 raise SystemExit(e.exit_code) from e 

107 except KeyboardInterrupt as e: 

108 console.print("\n[yellow]Interrupted by user[/yellow]") 

109 raise SystemExit(1) from e 

110 except (OSError, RuntimeError, ValueError) as e: 

111 console.print(f"[bold red]Error:[/bold red] {e}") 

112 raise SystemExit(1) from e 

113 

114 

115if __name__ == "__main__": 

116 main()