Skip to content

jpospychala/rcli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RCLI: Ramda for Command Line

Build Status

JSON manipulation tools for command line inspired by Ramda.js, a practical functional JavaScript library inspired by Clojure.

$ echo '{"status":"RUNNING"}' | R path status
RUNNING

$ echo '{"age":60,"color":"blue", "score": 3}' | R pick age score
{"age": 60, "score": 3}

$ echo '[1, 2, 3, 4]' | R head
1

$ echo '[1, 2, 3, 4]' | R tail
[2, 3, 4]

$ echo '{"age":60}' | R eq '{"age":60}'
true

$ echo '{"age":60}' | R not eq '{"name":"joe"}'
true

Installing

Version: 0.2

Download binary for your platform:

Building

RCLI is written in Go and requires go command to build.

git clone https://github.com/jpospychala/rcli.git
cd rcli
make
sudo make install

Usage

Usage: R <func> [arguments...]

Functions can be stacked, so that result of one function is passed as input to next function, for example:

$ echo '[1]' | R append 2 each
1
2

Input can contain single JSON object or sequence of objects, in which case each object is processed by function chain, for example:

$ echo -e '{"name":"Jack","sex":"male"}{"name":"Wendy","sex":"female"}' | R path name
Jack
Wendy

Functions

append

append appends object to list

Example:

 $ echo '[1]' | R append 2
 [1,2]

concat

concat [list] concatenates two lists

Example:

 $ echo '[1,2]' | R concat '[3,4]'
 [1,2,3,4]

contains

contains true if input contains object

Example:

 $ echo '[1, 2]' | R contains 1
 true

each

each prints each list element in new line

Example:

 $ echo '[1,2,3]' | R each
 1
 2
 3

eq

eq compares stdin with first argument for equality

Example:

 $ echo '{"a":{"b":1}}' | R eq '{"a":{"b":1}}'

filter

filter returns list of objects matching predicate

Example:

 $ echo '[{"a":1, "b":2}]' | R filter where '{"a":1}'
 [{"a":1,"b":2}]

find

find first object from list matching predicate

Example:

 $ echo '[{"a":1, "b":2}]' | R find where '{"a":1}'
 {"a":1,"b":2}
 $ echo '[{"a":1, "b":2}]' | R find where '{"a":2}'
 $

head

head first element of a list

Example:

 $ echo '[1,2,3,4]' | R head
 1

help

help prints usage details

keys

keys returns object property names

Example:

 $ echo '{"a":1,"b":2}' | R keys
 ["a","b"]

length

length [list] number of elements in list

Example:

 $ echo '[1,2,3,4]' | R length
 4

map

map maps list elements using func

Example:

 $ echo '[{"a":1},{"a":2}]' | R map path a
 [1,2]

mixin

mixin adds obj properties into input object

Example:

 $ echo '{"a":1, "b":2}' | R mixin '{"b": 5,"c":3}'
 {"a":1,"b":5,"c":3}

not

not inverts boolean result of following function

Example:

 $ echo '0' | R not eq '1'

omit

omit [list] returns object without specified properties

Example:

 $ echo '{"a":1,"b":2}' | R omit a
 {"b":2}

path

path returns object at period-delimited path

Example:

 $ echo '{"a":{"b":true}}' | R path a.b
 true

pick

pick [list] returns object with only specified properties

Example:

 $ echo '{"a":1,"b":2}' | R pick a
 {"a":1}

tail

tail all but first elements of a list

Example:

 $ echo '[1,2,3,4]' | R tail
 [2,3,4]

values

values returns list of object values

Example:

 $ echo '{"a":1,"b":2}' | R values
 [1,2]

version

version prints R version

where

where checks if object matches spec obj

Example:

 $ echo '{"a":1, "b":2}' | R where '{"a": 1}'
 {"a":1, "b":2}
 $ echo '{"a":1, "b":2}' | R where '{"a": b}'
 $

About

RCLI: Ramda for Command Line

Resources

License

Stars

Watchers

Forks

Packages

No packages published