-
Notifications
You must be signed in to change notification settings - Fork 600
Add support for -t/--tuples-only option to print rows without extra output #1545
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
DiegoDAF
wants to merge
3
commits into
dbcli:main
Choose a base branch
from
DiegoDAF:feature/tuples-only-option
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+63
−1
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| from unittest.mock import patch | ||
|
|
||
| from click.testing import CliRunner | ||
|
|
||
| from pgcli.main import cli, PGCli | ||
|
|
||
|
|
||
| def test_tuples_only_flag_passed_to_pgcli(): | ||
| """Test that -t passes tuples_only=True to PGCli.""" | ||
| runner = CliRunner() | ||
| with patch.object(PGCli, "__init__", autospec=True, return_value=None) as mock_pgcli: | ||
| runner.invoke(cli, ["-t", "mydb"]) | ||
| call_kwargs = mock_pgcli.call_args[1] | ||
| assert call_kwargs["tuples_only"] is True | ||
|
|
||
|
|
||
| def test_tuples_only_long_form(): | ||
| """Test that --tuples-only passes tuples_only=True to PGCli.""" | ||
| runner = CliRunner() | ||
| with patch.object(PGCli, "__init__", autospec=True, return_value=None) as mock_pgcli: | ||
| runner.invoke(cli, ["--tuples-only", "mydb"]) | ||
| call_kwargs = mock_pgcli.call_args[1] | ||
| assert call_kwargs["tuples_only"] is True | ||
|
|
||
|
|
||
| def test_tuples_only_not_set_by_default(): | ||
| """Test that tuples_only is False when -t is not used.""" | ||
| runner = CliRunner() | ||
| with patch.object(PGCli, "__init__", autospec=True, return_value=None) as mock_pgcli: | ||
| runner.invoke(cli, ["mydb"]) | ||
| call_kwargs = mock_pgcli.call_args[1] | ||
| assert call_kwargs["tuples_only"] is False | ||
|
|
||
|
|
||
| def test_tuples_only_sets_csv_noheader_format(): | ||
| """Test that tuples_only=True sets table_format to csv-noheader.""" | ||
| pgcli = PGCli(tuples_only=True) | ||
| assert pgcli.table_format == "csv-noheader" | ||
|
|
||
|
|
||
| def test_default_table_format_without_tuples_only(): | ||
| """Test that table_format uses config default when tuples_only is False.""" | ||
| pgcli = PGCli() | ||
| assert pgcli.table_format != "csv-noheader" # Uses config default |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
-t/--tuples-onlyis used, this branch only switches the formatter tocsv-noheader; the output path still appends command status informat_output(pgcli/main.py:1968-1970) and prints timing whenever enabled (pgcli/main.py:901, with the default config settingtiming = True). PostgreSQL documents--tuples-onlyas turning off column names and row-count footers, so with the default config a query still emitsSELECT nandTime: ..., which breaks users relying on this option for rows-only output. Please carry the tuples-only state through to suppress status/timing, or avoid exposing it as psql-style tuples-only.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @codex, fair point on the psql semantics. This is intentional for this PR:
-twas deliberately narrowed during review to be a startup shortcut for the output format only (like a CLI\T), not psql's full tuples-only. Suppressing the status footer and timing is kept to separate, composable flags (--no-timings/--no-status) rather than bundled into-t, so each concern stays granular. So the scope here is "format shortcut", and rows-only-with-no-footers is achieved by combining flags. Open to revisiting the naming if-t/--tuples-onlyreads as too psql-flavored for that scope.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To use Codex here, create an environment for this repo.