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

[stdin/-f] The -n -f flag is sticky for all files listed as arguments. #2187

Open
frosencrantz opened this issue Dec 22, 2023 · 5 comments
Open

Comments

@frosencrantz
Copy link
Contributor

Small description
The -n -f flag is sticky for all files listed as arguments.

Expected result
The -n -f type flag only applies to the next file listed as an argument.

Actual result with screenshot

https://asciinema.org/a/uY82MQyWCbFr0axdg9oS42y4I

Steps to reproduce with sample data and a .vd

The jsonl file is still being read as a csv. Though if you try to open the jsonl file after vd has started it works properly.

cat sample_data/benchmark.csv | vd -n -f csv - sample_data/benchmark.jsonl

Additional context
Please include the version of VisiData and Python. Latest develop branch.Python 3.9.2

@saulpw saulpw added By Design and removed bug labels Dec 23, 2023
@saulpw
Copy link
Owner

saulpw commented Dec 23, 2023

This is by design; -n should apply to all subsequent arguments (until -g). And likewise -f csv. This does have the effect that once a -f/--filetype argument is specified, subsequent files can't be parsed according to their extension. So I could see a request for a way to "cancel" an option, like -f "". Is that what you really need in this case?

@frosencrantz
Copy link
Contributor Author

The -g and -n flags are confusing to me.

So I could see a request for a way to "cancel" an option, like -f "". Is that what you really need in this case?

Yes that would be very useful then. The order of the arguments makes a difference in how vd displays which sheet first and ordering of the others. I might read from stdin, and have that as the initial sheet, but want to include related data as separate arguments, but the related data might have other formats, like a directory or different files of various formats.

@saulpw
Copy link
Owner

saulpw commented Dec 23, 2023

The -g and -n flags are confusing to me.

Options handling is complicated. I wish it were simpler but there are so many cases to take into account.

The key thing here is that options within vd can be global defaults, which can be overridden by specific sheet class, which can be overridden by a specific sheet instance. When you specify options on the CLI, they become the global defaults, which then apply to every sheet which hasn't overridden them specifically. But if you still want the original global defaults to apply, whether the builtin defaults or your personal defaults like options.foo = 'bar' in .visidatarc (equivalent to vd.options.foo = 'bar'), then you have to specify -n so that they are applied directly to the sheet. -g is offered as the antidote to -n so that you can provide a mix of global and sheet-specific defaults on the CLI.

If this is not clear, can you explain what is confusing? This will help us figure out what needs to be explained better in general.

@frosencrantz
Copy link
Contributor Author

Thanks, @saulpw that helps. The -n flag will be sticky for the remainder of the args. Your suggestion for a way to clear an option would be useful.

@saulpw
Copy link
Owner

saulpw commented Jan 5, 2024

@frosencrantz btw I just tested it and passing -f "" on the CLI already works:

vd -f csv sample_data/benchmark.csv -f "" sample_data/benchmark.jsonl

We need to document this in https://www.visidata.org/docs/loading/#loading-multiple-datasets-simultaneously

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants