shenwei356 / csvtk

A cross-platform, efficient and practical CSV/TSV toolkit in Golang
http://bioinf.shenwei.me/csvtk
MIT License
1k stars 84 forks source link

Chaining sub-commands with one csvtk command #160

Closed tseemann closed 3 years ago

tseemann commented 3 years ago

Long term enhancement:

Tools like mlr allow chaining of sun-commands within the one command. Could csvtk ever do this?

cat in.csv | csvtk cut -f A,C // gather -g C -f A // sort -k C // pretty

instead of piping?

The // is just an example sub-command digraph, could use anything.

shenwei356 commented 3 years ago

Unless rewrite the whole architecture of csvtk, it's huge of work.

tseemann commented 3 years ago

That's a shame.

I think it could be done using a wrapper that parsed the // and used temp files.

But it would not have the efficiency.

shenwei356 commented 3 years ago

No need to use temp files. Just passing data between functions in memory, it could reduce steps of parsing data.

All commands can be methods of a CSV object,

struct CSV {
}
func (csv CSV) Read(file, options)  
func (csv CSV) Write(file, options) 
func (csv CSV) A(options)  // replace old data inplace
func (csv CSV) B(options)  // replace old data inplace

The pipe would be

csv.Read(file, options).A(options).B(options).Write(file, options)