jbenet / transformer

transformer - multiformat data conversion
transform.datadex.io
130 stars 7 forks source link

cli separator #12

Closed jbenet closed 10 years ago

jbenet commented 10 years ago

I want all of these to work:

> cat input
94309
92009
12567
> transform us-zipcode us-city < input
Palo Alto, CA
Carlsbad, CA
Pine Plains, NY

and

> cat input
foo,bar,baz
1,2,3
4,5,6
7,8,9
> transform csv-string json
[ {"foo": 1, "bar": 2, "baz": 3}, {"foo": 4, "bar": 5, "baz": 6}, {"foo": 7, "bar": 8, "baz": 9} ]

and

> cat input
foo,bar,baz
1,2,3
4,5,6
7,8,9
> transform csv-string json ndjson
{"foo": 1, "bar": 2, "baz": 3}
{"foo": 4, "bar": 5, "baz": 6}
{"foo": 7, "bar": 8, "baz": 9}

This all depends on how the transform cli consumes input. Some possibilities:

Differentiate with a type:

transform string             // reads stdin as one large string
transform nd-strings         // reads stdin as many newline-delimited strings
transform json               // reads stdin as one large json doc
transform ndjson             // reads stdin as many newline-delimited json docs

Differentiate with a flag:

transform string             // reads stdin as one large string
transform -d="\n" string     // reads stdin as many newline-delimited strings
transform json               // reads stdin as one large json doc
transform -d="\n" json       // reads stdin as many newline-delimited json docs
jbenet commented 10 years ago

This is solved by differentiating with the type. Makes the most sense.