Closed kedashoe closed 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",
...
--output-type
is now implemented with possible values pretty, csv, tsv, raw
Very cool :) And feel free to close whenever you like, just thoughts rather than "issues"
Sure. Thanks for the feedback, appreciate it a lot.
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, --inspect
to-p, --pretty-print
and use-i, --input-type
and support at least csv/tsv out of the box. Also would be cool to support "white-space columns" input type (not sure what the accepted name is for that), eg the output ofls -l
,top -n 1
,ps aux
etc. This may be a little more work than csv as I couldn't find any packages that already do this but I also am not sure exactly what terms to search for. Others?-r, --raw-output
, maybe get rid of that and add-o, --output-type
to be a companion to-i
(and handle-o raw
) and support all the same input typescat friends.json |\ ramda --save-as ~/bin/first-names.ramda 'first-word=(head . split " "); prop(\friends) >> map(first-word . prop(\fullName)) >> sortBy length'
which would write the associated snippet to the file, and then in the future I can just runcat friends.json | first-names.ramda
and I'm good to go :smile: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.