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

--no-headers doesn't work on most formats #566

Open
zellyn opened this issue Jul 9, 2023 · 6 comments
Open

--no-headers doesn't work on most formats #566

zellyn opened this issue Jul 9, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@zellyn
Copy link

zellyn commented Jul 9, 2023

Version 3.33

sqlite-utils query library.db 'select asin from audible' --fmt plain --no-headers | head -3
asin
0062804006
0062891421
@simonw simonw added the bug Something isn't working label Jul 9, 2023
@simonw
Copy link
Owner

simonw commented Jul 9, 2023

Thanks, looks like a bug.

@simonw
Copy link
Owner

simonw commented Jul 9, 2023

On consulting https://pypi.org/project/tabulate/ it looks like most of those formats don't actually makes sense without headers - so the right thing here might be to raise an error if --fmt and --no-headers are used at the same time.

@tobych
Copy link

tobych commented Apr 29, 2024

Seems to me that this is not a bug, and that @zellyn might be misunderstanding what --no-headers is for.

The help text for --no-headers reads: "Omit CSV headers".

(Well, it applies to TSV files, too. So the help text could be improved.)

I reckon raising an error if --no-header is used without either --csv or --tsv would be good.

Furthermore, the options seem a bit messy to me. I mean, you could specify --csv, --tsv, and --fmt all at once. I'd suggest at least check that none of that is happening. And make it clear in the help text that --fmt is using the tabulate library. Don't try to hide it: that abstraction is leaking already.

@zellyn
Copy link
Author

zellyn commented Apr 29, 2024

My use case for using --no-headers is almost 100% “I'm about to pass this through xargs or some other unix utility.

But you're right that it doesn't make sense for most of the formats that are generating some kind of markup rendering.

@tobych
Copy link

tobych commented Apr 29, 2024

@zellyn Which formats are you working with? I've not looked closely at the list of formats tabulate can write, and which have headers. Are you trying to skip headers from a format that sqlite-utils is delegating to tabulate for? Perhaps the tabulate library has an option for omitting a header: sqlite-utils could pass that (or arbitrary) options to tabulate.

Do bear in mind that if you're using a system that has the tail command, you can use tail -n +2 as a filter to remove the first line of a text stream:

$ printf "1\n2\n3\n" | tail -n +2
2
3

@zellyn
Copy link
Author

zellyn commented Apr 30, 2024

Yeah, I've done the tail thing for sure. I've mostly gotten around this now by using tsv and only selecting one column, which basically is plain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants