Skip to content

combine csv and tsv functions behind [to/from]-[csv/tsv] commands #969

@drmason13

Description

@drmason13

Following on from #943 where a separator arg was added to from-csv.

I've now realized that from-tsv is just a specific case of from-csv (tab separated values).
I've also noticed that passing --separator "\t" to from-csv trips my uninspired check for a single character (it sees two characters, '' and 't').

I'd like to propose having from-tsv and from-csv --separator "\t" do the same thing, and I think we can deduplicate some code while we're at it. And I'm planning to make a pull request with these changes :)

  1. [from/to]_tsv can call the same function as [from/tp]_csv, this has already been started with from_structured_data. Only, I think the scope of this module would be more clear if we named it from_delimited_data. This will use csv::ReaderBuilder and csv::WriterBuilder with different delimiters.

  2. the parsing of the separator arg of from_csv and to_csv should be improved. I struggled to get a character out of nu from the command line and ended up checking a string.to_chars() has length 1. I can check if the string is "\t" first and return '\t' early for now but I worry that's symptomatic of a deeper issue? Are there plans for supporting characters from the command line? I'd be interested in the why/why not and how?

Also a side note: maybe --delimiter should be added as an alias for --separator?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions