raine / ramda-cli

:ram: A CLI tool for processing data with functional pipelines
ISC License
573 stars 12 forks source link

a couple thoughts #1

Closed kedashoe closed 9 years ago

kedashoe commented 9 years ago

I was thinking of a similar project but you beat me to it (by a mile :smile: ) Looks really great! A couple thoughts I had:

I was going to submit a PR but I've never used livescript and while it looks neat I don't have much free time at the moment.

raine commented 9 years ago

I like the idea of different input and output formats. Here's an example how formatting as CSV could work using a function and raw output together.

csv is to-csv. It takes a list of objects and the keys of the first object become the headers.

# outputs a string formatted as JSON
$ cat latest.json | R 'take 5' | R 'map pick <[ name category ]>' | R csv                                                                            
"name,category\n__,Function\r\nadd,Math\r\nadjust,List\r\nalways,Function\r\naperture,List\r\n"

# add -r for raw output. boom
$ cat latest.json | R 'take 5' | R 'map pick <[ name category ]>' | R csv -r                                                                           
name,category
__,Function
add,Math
adjust,List
always,Function
aperture,List

I like the idea that ramda-cli provides tools to use whatever output formatting function you want to use by allowing raw output, but on the other hand -o csv is an easier interface to approach so it's worth a try.

Pertaining to your third point, I was playing around with this idea:

~/.config/ramda-cli.{ls,js}:

var R = require('ramda')
exports.shout = R.compose(R.toUpper, R.add(R.__, '!'))

Functions exported in the configuration file would be available as such:

$ echo '"foo"' | R shout
"FOO!"

Also, something like this could be useful.

get-names.js:

var R = require('ramda');

module.exports = R.pluck('name');
cat latest.json | ramda -f get-names.js
[
  "__",
  "add",
  "adjust",
...
raine commented 9 years ago

--output-type is now implemented with possible values pretty, csv, tsv, raw

kedashoe commented 9 years ago

Very cool :) And feel free to close whenever you like, just thoughts rather than "issues"

raine commented 9 years ago

Sure. Thanks for the feedback, appreciate it a lot.