gamesheet_sdk.admin.cli.helpers module

CLI helper functions shared across commands.

gamesheet_sdk.admin.cli.helpers.build_authenticated_session(config)[source]

Build an AuthenticatedSession from saved tokens.

Parameters:

config (Config) – The application config.

Returns:

An AuthenticatedSession ready to use.

Return type:

AuthenticatedSession

Raises:

Exit – If no tokens are saved.

gamesheet_sdk.admin.cli.helpers.run_action_or_exit(session, action, *args)[source]

Run an action function with error handling.

Wraps the action call in the session’s context manager and catches AuthenticationError and GameSheetError. On either exception, prints a user-friendly error message to stderr and exits with code 1. The session context manager ensures proper cleanup (e.g., closing connections) regardless of success or failure. :param session: The authenticated session to use as a context manager. :type session: AuthenticatedSession :param action: A callable that takes session and *args and returns a result. Typically a domain

action function (e.g., list_associations, list_leagues).

Parameters:

args (Any) – Positional arguments forwarded to action after session.

Returns:

The result of action(session, *args) on success.

Return type:

Any

Raises:

Exit – If action raises AuthenticationError or GameSheetError. Exit code is 1 in both cases.

gamesheet_sdk.admin.cli.helpers.run_team_update(ctx, season_id, team_id, title, division_id, external_id, logo_path, *, remove_logo, output_format, output_path)[source]

Run team update action and render output.

Shared implementation for teams update and divisions teams update commands. :param ctx: The click context containing the config. :type ctx: Context :param season_id: Season ID containing the team. :type season_id: str :param team_id: Team ID to update. :type team_id: str :param title: New team name/title. :type title: str | None :param division_id: New division ID. :type division_id: str | None :param external_id: New external identifier. :type external_id: str | None :param logo_path: Path to a new logo image file. :type logo_path: str | None :param remove_logo: Remove the team’s logo. :type remove_logo: bool :param output_format: Output format for rendering. :type output_format: str :param output_path: Optional output file path. :type output_path: str | None :raises Exit: If no fields are provided for update. :returns: None :rtype: None

gamesheet_sdk.admin.cli.helpers.run_team_create(ctx, season_id, title, division_id, external_id, logo_path, output_format, output_path)[source]

Run team create action and render output with success message.

Shared implementation for teams create and divisions teams create commands. :param ctx: The click context containing the config. :type ctx: Context :param season_id: Season ID to create the team in. :type season_id: str :param title: Team name/title. :type title: str :param division_id: Division ID the team belongs to. :type division_id: str :param external_id: Optional external identifier. :type external_id: str | None :param logo_path: Optional path to a logo image file. :type logo_path: str | None :param output_format: Output format for rendering. :type output_format: str :param output_path: Optional output file path. :type output_path: str | None :returns: None :rtype: None

gamesheet_sdk.admin.cli.helpers.run_team_delete(ctx, season_id, team_id)[source]

Run team delete action with success message.

Shared implementation for teams delete and divisions teams delete commands. :param ctx: The click context containing the config. :type ctx: Context :param season_id: Season ID containing the team. :type season_id: str :param team_id: Team ID to delete. :type team_id: str

gamesheet_sdk.admin.cli.helpers.run_roster_assign_with_output(action, session, resource_type, resource_id, target_id, output_format, output_path, *args, **kwargs)[source]

Run roster assign action with error handling and output rendering.

Parameters:
  • action (Any) – The assign action function to call.

  • session (AuthenticatedSession) – Authenticated session.

  • resource_type (str) – Type of resource being assigned (player/coach).

  • resource_id (str) – ID of the resource being assigned.

  • target_id (str) – ID of the target team.

  • output_format (str) – Output format for rendering.

  • output_path (str | None) – Optional output file path.

  • args (Any) – Positional arguments forwarded to action.

  • kwargs (Any) – Keyword arguments forwarded to action.

Raises:

Exit – If the action raises an exception.

gamesheet_sdk.admin.cli.helpers.run_roster_unassign(action, session, resource_type, resource_id, target_id, *args)[source]

Run roster unassign action with error handling.

Parameters:
  • action (Any) – The unassign action function to call.

  • session (AuthenticatedSession) – Authenticated session.

  • resource_type (str) – Type of resource being unassigned (player/coach).

  • resource_id (str) – ID of the resource being unassigned.

  • target_id (str) – ID of the target team.

  • args (Any) – Positional arguments forwarded to action.

Raises:

Exit – If the action raises an exception.

gamesheet_sdk.admin.cli.helpers.run_roster_update_with_output(action, session, resource_type, output_format, output_path, *args, **kwargs)[source]

Run roster update action with error handling and output rendering.

Parameters:
  • action (Any) – The update action function to call.

  • session (AuthenticatedSession) – Authenticated session.

  • resource_type (str) – Type of resource being updated (player/coach).

  • output_format (str) – Output format for rendering.

  • output_path (str | None) – Optional output file path.

  • args (Any) – Positional arguments forwarded to action.

  • kwargs (Any) – Keyword arguments forwarded to action.

Raises:

Exit – If the action raises an exception.

gamesheet_sdk.admin.cli.helpers.run_roster_create_with_output(action, session, resource_type, output_format, output_path, *args, success_message=None, **kwargs)[source]

Run roster create action with error handling and output rendering.

Parameters:
  • action (Any) – The create action function to call.

  • session (AuthenticatedSession) – Authenticated session.

  • resource_type (str) – Type of resource being created (player/coach).

  • output_format (str) – Output format for rendering.

  • output_path (str | None) – Optional output file path.

  • args (Any) – Positional arguments forwarded to action.

  • success_message (str | None) – Optional custom success message (uses result.id formatting if contains {id}).

  • kwargs (Any) – Keyword arguments forwarded to action.

Raises:

Exit – If the action raises an exception.