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

31 statements  

« prev     ^ index     » next       coverage.py v7.13.2, created at 2026-02-28 19:20 -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("spans")(traces.show_spans) 

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

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

28 

29 

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

31 if value: 

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

33 raise typer.Exit() 

34 

35 

36@app.callback() 

37def callback( 

38 version: Annotated[ 

39 bool, 

40 typer.Option( 

41 "--version", 

42 "-V", 

43 help="Show version and exit", 

44 callback=version_callback, 

45 is_eager=True, 

46 ), 

47 ] = False, 

48 profile: Annotated[ 

49 str | None, 

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

51 ] = None, 

52 project: Annotated[ 

53 str | None, 

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

55 ] = None, 

56) -> None: 

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

58 set_active_profile(profile) 

59 set_active_project(project) 

60 

61 

62def cli() -> None: 

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

64 setup_logging() 

65 setup_sentry(environment="local") 

66 app()