Coverage for src / sentry_tool / cli.py: 90.00%

30 statements  

« prev     ^ index     » next       coverage.py v7.13.2, created at 2026-02-17 21:46 -0500

1from typing import Annotated 

2 

3import typer 

4 

5from sentry_tool.__about__ import __version__ 

6from sentry_tool.commands import config, events, issues, projects, traces 

7from sentry_tool.monitoring import setup_logging, setup_sentry 

8from sentry_tool.utils import set_active_profile, set_active_project 

9 

10app = typer.Typer( 

11 help="Sentry Tool - Query and manage Sentry issues.", 

12 no_args_is_help=True, 

13) 

14 

15app.add_typer(config.config_app, name="config") 

16 

17app.command("list")(issues.list_issues) 

18app.command("show")(issues.show_issue) 

19app.command("event")(events.show_event) 

20app.command("events")(events.list_events) 

21app.command("tags")(events.show_tags) 

22app.command("transactions")(traces.list_transactions) 

23app.command("trace")(traces.lookup_trace) 

24app.command("transaction")(traces.show_transaction) 

25app.command("list-projects")(projects.list_projects) 

26app.command("open")(projects.open_sentry) 

27 

28 

29def version_callback(value: bool) -> None: 

30 if value: 

31 typer.echo(f"sentry-tool {__version__}") 

32 raise typer.Exit() 

33 

34 

35@app.callback() 

36def callback( 

37 version: Annotated[ 

38 bool, 

39 typer.Option( 

40 "--version", 

41 "-V", 

42 help="Show version and exit", 

43 callback=version_callback, 

44 is_eager=True, 

45 ), 

46 ] = False, 

47 profile: Annotated[ 

48 str | None, 

49 typer.Option("--profile", "-P", help="Use named profile from config"), 

50 ] = None, 

51 project: Annotated[ 

52 str | None, 

53 typer.Option("--project", "-p", help="Override project slug from profile"), 

54 ] = None, 

55) -> None: 

56 """Handle global options before subcommand dispatch.""" 

57 set_active_profile(profile) 

58 set_active_project(project) 

59 

60 

61def cli() -> None: 

62 """Configure logging and Sentry, then run the CLI app.""" 

63 setup_logging() 

64 setup_sentry(environment="local") 

65 app()