Skip to content

Conversation

@DiegoDAF
Copy link

@DiegoDAF DiegoDAF commented Dec 5, 2025

Summary

This PR adds support for the -f/--file option to pgcli, implementing psql-compatible behavior for executing SQL commands from files.

Features

  • Single file execution: pgcli -f file.sql
  • Multiple files: pgcli -f file1.sql -f file2.sql
  • Long form support: pgcli --file file.sql
  • Files are executed sequentially
  • Pager is automatically disabled in file mode
  • Proper error handling and exit codes

Implementation Details

  • Added new click option -f/--file that accepts multiple file paths
  • File paths are validated to ensure they exist and are readable
  • Modified run_cli() to check for file mode and execute file contents before entering interactive mode
  • Updated echo_via_pager() to disable pager when in file mode
  • File contents are read and executed using the existing handle_watch_command() method

Testing

Comprehensive BDD tests included covering:

  • Single file with -f flag
  • Single file with --file flag
  • Multiple statements in one file
  • Multiple -f options for different files
  • Files with special commands
  • Error handling for invalid SQL

Compatibility

This implementation follows psql's behavior and maintains backward compatibility with existing functionality.

Made with ❤️ and 🤖 Claude Code

This commit adds support for the -f/--file option to pgcli, similar to
psql's behavior. Users can now execute SQL commands from files and exit
immediately after execution.

Features:
- Single file execution: pgcli -f file.sql
- Multiple files: pgcli -f file1.sql -f file2.sql
- Long form: pgcli --file file.sql
- Files are executed sequentially
- Pager is automatically disabled in file mode
- Proper error handling and exit codes

Tests included for all scenarios.

Made with ❤️ and 🤖 Claude Code

Co-Authored-By: Claude <[email protected]>
@DiegoDAF DiegoDAF marked this pull request as ready for review December 5, 2025 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant