pgcli
pgcli copied to clipboard
Add support for -c/--command option to execute commands and exit
Summary
This PR adds support for the -c/--command option to pgcli, implementing psql-compatible behavior for executing SQL commands or internal commands from the command line.
This is PR #1530, cleaned.
Features
- Single command execution:
pgcli -c "SELECT 1" - Multiple commands:
pgcli -c "SELECT 1" -c "SELECT 2" - Long form support:
pgcli --command "SELECT 1" - Mixed usage:
pgcli -c "cmd1" --command "cmd2" - Commands are executed sequentially
- Pager is automatically disabled in command mode
- Proper error handling and exit codes
Implementation Details
- Added new click option
-c/--commandthat accepts multiple values - Modified
run_cli()to check for command mode and execute commands before entering interactive mode - Updated
echo_via_pager()to disable pager when in command mode - Commands are executed using the existing
handle_watch_command()method
Testing
Comprehensive BDD tests included covering:
- Single command with
-cflag - Single command with
--commandflag - Multiple statements in one command
- Multiple
-coptions - Mixed
-cand--commandoptions - Error handling
Compatibility
This implementation follows psql's behavior and maintains backward compatibility with existing functionality.
Made with ❤️ and 🤖 Claude Code