Permalink
Browse files

start hacking on dat

  • Loading branch information...
maxogden committed Aug 17, 2013
1 parent 72ae059 commit e5eda57b53f60b05c0c3d97da90c10cd17dcbe19
Showing with 79 additions and 1 deletion.
  1. +1 −0 .gitignore
  2. +39 −0 cli.js
  3. +29 −0 index.js
  4. +10 −1 package.json
View
@@ -0,0 +1 @@
node_modules
View
39 cli.js
@@ -0,0 +1,39 @@
#!/usr/bin/env node
var dat = require('./')(process.cwd())
var opts = require('optimist')
.usage("Usage: $0 <command> [<args>]\n\nEnter 'dat help' for help")
parse(dat, opts)
function parse(dat, opts) {
var args = opts.argv._
var error = validate(dat, args)
if (error) return process.stdout.write(error)
var cmd = commands(opts)
dat[cmd.command].call(dat, cmd.options, function(err) {
if (err) return console.error('fatal', err.message)
})
}
function validate(dat, args) {
var args = opts.argv._
if (args.length === 0) return opts.help()
if (!dat[args[0]]) {
return ['Invalid command: ' + args[0], opts.help()].join('\n')
}
}
function commands(opts) {
var args = opts.argv._
var cmd = args.shift()
var options = {}
args.map(function(arg) { options[arg] = true })
var skip = ['$0', '_']
Object.keys(opts.argv).map(function(arg) {
if (skip.indexOf(arg) > -1) return
options[arg] = opts.argv[arg]
})
return {command: cmd, options: options}
}
View
@@ -0,0 +1,29 @@
var level = require('level')
var mkdirp = require('mkdirp')
var fs = require('fs')
var path = require('path')
module.exports = Dat
function Dat(dir, opts) {
// if 'new' was not used
if (!(this instanceof Dat)) return new Dat(dir, opts)
this.dir = dir
this.opts = opts
}
Dat.prototype.exists = function(dir, cb) {
var datPath = path.join(dir, '.dat')
fs.exists(datPath, function(exists) {
if (!exists) return cb(false, false)
})
}
Dat.prototype.init = function(dir) {
process.stdout.write('TODO\n')
}
Dat.prototype.help = function() {
process.stdout.write('TODO\n')
}
View
@@ -3,8 +3,17 @@
"version": "0.0.0",
"description": "collaborative data tool",
"main": "index.js",
"bin": {
"dat": "cli.js"
},
"scripts": {},
"repository": "",
"author": "",
"license": "BSD"
"license": "BSD",
"dependencies": {
"optimist": "~0.6.0",
"level": "~0.13.0",
"mkdirp": "~0.3.5",
"abbrev": "~1.0.4"
}
}

0 comments on commit e5eda57

Please sign in to comment.