Skip to content

CLI

Entry-point functions, argument parsing, and the main execution loop.

Note

The CLI options and positional arguments are documented in Syntax & Options. This page covers the programmatic Python interface only.

Module overview

Command-line interface for execsql.

Parses arguments via Typer, then delegates to :func:_run for state initialisation, database connection, and script execution.

Submodules:

  • :mod:execsql.cli.help — Rich-formatted help output & console objects
  • :mod:execsql.cli.dsn — Connection-string (DSN URL) parser
  • :mod:execsql.cli.run — Core execution logic (_run, _connect_initial_db, _ping_db, _print_dry_run, _print_profile)
  • :mod:execsql.cli.lint — AST-based --lint static analyser and Rich result printer

Core execution

Initialise state, connect to the database, load the script, and run it.

Separated from argument parsing so it can be called directly in tests without going through the Typer CLI layer. All parameters mirror the corresponding CLI options; see Syntax & Options for descriptions.

When ping is True, the function connects to the database, prints connection details (DBMS name, server version, and location), and calls :func:_ping_db which raises SystemExit(0). No script is loaded or executed. script_name and command may both be None in ping mode.

When lint is True, the script is parsed and statically analysed for structural issues (unmatched IF/ENDIF/LOOP/BATCH blocks, potentially undefined variables, missing INCLUDE files, empty scripts) without connecting to a database or executing anything. Exits with code 0 if no errors were found, or code 1 if errors were found.