Skip to content

Conversation

@DiegoDAF
Copy link

@DiegoDAF DiegoDAF commented Dec 5, 2025

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/--command that 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 -c flag
  • Single command with --command flag
  • Multiple statements in one command
  • Multiple -c options
  • Mixed -c and --command options
  • Error handling

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 -c/--command option to pgcli, similar to
psql's behavior. Users can now execute SQL commands or internal commands
from the command line and exit immediately after execution.

Features:
- Single command execution: pgcli -c "SELECT 1"
- Multiple commands: pgcli -c "SELECT 1" -c "SELECT 2"
- Long form: 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

Tests included for all scenarios.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@DiegoDAF DiegoDAF marked this pull request as ready for review December 5, 2025 18:22
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