Skip to content
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

diff: add option/flag for headers in output #1395

Conversation

janriemer
Copy link

This implements a new option for diff: It is now possible to decide, whether the CSV headers in the compared CSVs should be in the diff output. If neither CSVs have headers and this option is not active (which means the output should have headers), the all_generic strategy from rename is used (_col_1, _col_2, etc.).

Closes #1326

Example 1 (no diff, no headers in result):

csv_left.csv

col1,col2,col3
1,foo,bar

csv_right.csv

1,foo,bar
qsv diff --no-headers-result --no-headers-right csv_left.csv csv_right.csv

Output (nothing will be printed here, because there are no differences and we don't want to print headers in the result):



Example 2 (has diff, no headers in result):

csv_left.csv

col1,col2,col3
1,foo,bar

csv_right.csv

1,foo,baz
qsv diff --no-headers-result --no-headers-right csv_left.csv csv_right.csv

Output:

-,1,foo,bar
+,1,foo,baz

Example 3 (has diff, add generic headers):

csv_left.csv

1,foo,bar

csv_right.csv

1,foo,baz
qsv diff --no-headers-left --no-headers-right csv_left.csv csv_right.csv

Output:

diffresult,_col_1,_col_2,_col_3
-,1,foo,bar
+,1,foo,baz

Jan Riemer added 2 commits October 31, 2023 16:23
Provide a single method for renaming into `all_generic` pattern
and expose it publicly for reuse.
Jan Riemer added 2 commits October 31, 2023 18:23
This implements a new option for `diff`: It is now possible to decide,
whether the CSV headers in the compared CSVs should be in the diff
output. If neither CSVs have headers and this option is _not_ active
(which means the output _should_ have headers), the `all_generic`
strategy from `rename` is used (`_col_1`, `_col_2`, etc.).

Example 1 (no diff, no headers in result):
csv_left.csv    col1,col2,col3
                1,foo,bar

csv_right.csv   1,foo,bar

qsv diff --no-headers-result --no-headers-right csv_left.csv csv_right.csv

Output: <nothing will be printed here, because there are no differences
        and we don't want to print headers in the result>
------------------------------------------------------------------------
Example 2 (has diff, no headers in result):
csv_left.csv    col1,col2,col3
                1,foo,bar

csv_right.csv   1,foo,baz

qsv diff --no-headers-result --no-headers-right csv_left.csv csv_right.csv

Output:         -,1,foo,bar
                +,1,foo,baz
------------------------------------------------------------------------
Example 3 (has diff, add generic headers):
csv_left.csv    1,foo,bar

csv_right.csv   1,foo,baz

qsv diff --no-headers-left --no-headers-right csv_left.csv csv_right.csv

Output:         diffresult,_col_1,_col_2,_col_3
                -,1,foo,bar
                +,1,foo,baz
@janriemer janriemer force-pushed the diff-boolean-header-option-for-diff-result branch from e275b75 to fc5189c Compare October 31, 2023 17:23
@jqnatividad jqnatividad self-requested a review November 1, 2023 02:16
Copy link
Collaborator

@jqnatividad jqnatividad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! You did what was requested in #1326 and more!

@jqnatividad jqnatividad merged commit 02c77fa into dathere:master Nov 1, 2023
11 checks passed
@janriemer janriemer deleted the diff-boolean-header-option-for-diff-result branch November 1, 2023 19:15
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.

diff: only show headers when there are differences
2 participants