some things that need explaining first
uri: default scheme is file://
pin: pipe in
pout: pipe out
json selector: from here http://jsonselect.org
received from the server to list supported commands.
{
command: 'ls',
arguments: [
// accepts many uri arguments ( maybe need a different type for patterns )
{'type': 'uri', name_hint: 'path', repeats: true}
]
}
{
command: 'cp',
arguments: [
// copy all args to the last argument
// ( the regular cp can also do `cp src1 dest1 src2 dest2` but
// im not sure how to handle that )
{type: 'uri', name_hint: 'source', repeats: true},
{type: 'uri', name_hint: 'dest'}
},
options: {
'recursive': { type: 'bool', default: 'false', help='...'}
}
}
{
command: 'grep',
arguments: [
// first argument is the regexp
{type: 'regexp', name_hint: 'pattern'},
// many uri
{type: 'uri', repeats: 'true'}
],
options: {
'invert': {type: 'bool', default: 'false', help='...'}
}
}
this is what would be sent to the server. the server would send the json back from the last command. using the schema attribute of the returned json the client can format the results however it wants.
// list a directory
{
command: 'ls',
arguments: [
{'uri': '/home/dunk/*.json'}
]
}
// list a directory and grep the returned files for foo
{
command: 'ls',
arguments: [
{'uri': '/home/dunk/*.json'}
],
pout: {
command: 'grep',
arguments: [
{'regexp': 'foo'},
// using a json selector to get filename from input json
{'pin': '.filename'}
]
}
}
// list a directory and cp all files to the same name + '.bak'
{
command: 'ls',
arguments: [
{'uri': '/home/dunk/*.json'},
],
pout: {
command: 'cp',
arguments: [
// using a json selector to get filename from input json
{'pin': '.filename'},
// some sort of expression implementation
{'pin': {'jsexpr': '.filename+".bak"'}}
]
}
}
full example of grep example:
ls output:
{
schema: 'filestats',
filestats: [
{filename: 'a.txt', size: 1024, mode: 0777},
{filename: 'b.txt', size: 1024, mode: 0777},
{filename: 'c.txt', size: 1024, mode: 0777},
]
}
piped to grep and greps output:
{
schema: 'grep',
grep: [
{filename: 'b.txt', matches: [
{line: 10, text: "something about foo.com", start: 16, end: 19}
]}
]
}