Skip to content

Commit

Permalink
The initial idea
Browse files Browse the repository at this point in the history
  • Loading branch information
jhs committed Jan 30, 2013
1 parent 1801430 commit 7ec3ab0
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
76 changes: 76 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env node
//
// couchjs client
//
// Copyright 2011 Iris Couch
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

var fs = require('fs')
var util = require('util')
var optimist = require('optimist')
var child_process = require('child_process')

var client = require('./client')
var LineStream = require('couchjs/stream')


var opts = optimist.usage('$0 </path/to/couchjs> </path/to/main.js>')


function toSource() {
if(typeof this == 'function')
return '' + this

if(this instanceof Error)
return this.stack

return util.inspect(this)
}

function main() {
var couchjs_filename = opts.argv._[0]
, main_js = opts.argv._[1]

if(!main_js || !couchjs_filename)
return console.error(opts.help())

console.log('%j %j', couchjs_filename, main_js)

var child = child_process.spawn(couchjs_filename, [main_js], {'stdio':'pipe'})

child.on('exit', function(code) {
console.log('couchjs %s exit: %s', child.pid, code)
})

child.stderr.on('data', function(body) {
console.error('couchjs %s error: %s', child.pid, body)
})

// Break messages from the child into lines.
var child_stdout = new LineStream
child_stdout.on('data', child_line)
child.stdout.setEncoding('utf8')
child.stdout.pipe(child_stdout)

function child_line(line) {
console.log('couchjs %s: %s', child.pid, line)
}

setTimeout(function() {
child.stdin.write('[]\n')
}, 3000)
}

if(require.main === module)
main()
15 changes: 15 additions & 0 deletions client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2011 Iris Couch
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

module.exports = {}

0 comments on commit 7ec3ab0

Please sign in to comment.