Skip to content

Commit

Permalink
First commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyfa committed Feb 10, 2012
0 parents commit 962dd7c
Show file tree
Hide file tree
Showing 13 changed files with 420 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
node_modules/
.DS_Store
42 changes: 42 additions & 0 deletions Cakefile
@@ -0,0 +1,42 @@

fs = require 'fs'
findit = require 'findit'
exec = require('child_process').exec
coffee = require 'coffee-script'
path = require 'path'

escapeShell = (arg) -> "'" + arg.replace(/[^\\]'/g, (m, i, s) -> m.slice(0, 1) + "\\'") + "'"
src = __dirname + '/src'
bin = __dirname + '/bin'

task 'build', 'build project', (options) ->

# Remove bin contents
exec "rm -rf #{escapeShell bin}", (err, stdout, stderr) ->
if err? then throw err

# Copy src content into bin
exec "cp -R #{escapeShell src} #{escapeShell bin}", (err, stdout, stderr) ->
if err? then throw err

# Compile coffee files
for filename in findit.sync bin
if filename.substring(filename.length-7) is '.coffee'
# Get script from coffee file
script = fs.readFileSync filename, 'utf8'
# Compile into js code
js = coffee.compile script
# Write js file with compiled code
file = fs.openSync filename.substring(0, filename.length-7)+'.js', 'w+'
fs.writeSync file, js
fs.closeSync file
# Delete coffee file
fs.unlinkSync filename

# Ensure redis-dump is executable
exec "chmod +x #{escapeShell bin+'/cli/redis-dump'}", (err, stdout, stderr) ->
if err? then throw err

# Finish
console.log 'built redis-dump.'

30 changes: 30 additions & 0 deletions bin/cli.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions bin/cli/redis-dump
@@ -0,0 +1,3 @@
#!/usr/bin/env node

require('../cli');
158 changes: 158 additions & 0 deletions bin/dump.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions bin/index.js
@@ -0,0 +1,5 @@
(function() {

module.exports = require('./dump');

}).call(this);
13 changes: 13 additions & 0 deletions bin/test.js
@@ -0,0 +1,13 @@
(function() {
var dump;

dump = require('./dump');

dump({
filter: '*'
}, function(err, result) {
if (err != null) return process.stderr.write("" + err + "\n");
return console.log(result);
});

}).call(this);
24 changes: 24 additions & 0 deletions package.json
@@ -0,0 +1,24 @@
{
"name": "redis-dump",
"version": "0.1.0",
"description": "Redis dump library",
"author": "Jeremy Faivre <contact@jeremyfa.com>",
"main": "./bin/index.js",
"scripts": {
"test": "node ./bin/test.js"
},
"bin": {
"redis-dump": "./bin/cli/redis-dump"
},
"dependencies": {
"async": ">=0.1.15",
"optimist": ">=0.3.1"
},
"devDependencies": {
"coffee-script": ">=1.2.0"
},
"repository": {
"type": "git",
"url": "git://github.com/jeremyfa/redis-dump.git"
}
}
38 changes: 38 additions & 0 deletions src/cli.coffee
@@ -0,0 +1,38 @@

fs = require 'fs'
path = require 'path'
argv = require('optimist').argv
dump = require './dump'
package = JSON.parse fs.readFileSync path.normalize(__dirname+'/../package.json'), 'utf8'

if argv.help
console.log """
#{package.name} #{package.version}
Usage: #{package.name} [OPTIONS]
-h <hostname> Server hostname (default: 127.0.0.1)
-p <port> Server port (default: 6379)
-f <filter> Query filter (default: *)
--help Output this help and exit
Examples:
redis-dump
redis-dump -p 6500
redis-dump -f 'mydb:*' > mydb.dump.txt
The output is a valid list of redis commands.
That means the following will work:
redis-dump > dump.txt # Dump redis database
cat dump.txt | redis-cli # Import redis database from generated file
"""
else
params =
filter: argv.f ? '*'
port: argv.p ? 6379
host: argv.h ? '127.0.0.1'

dump params, (err, result) ->
if err? then return process.stderr.write "#{err}\n"
if result? and "#{result}".replace(/^\s+/, '').replace(/\s+$/, '') isnt ''
console.log result
3 changes: 3 additions & 0 deletions src/cli/redis-dump
@@ -0,0 +1,3 @@
#!/usr/bin/env node

require('../cli');

0 comments on commit 962dd7c

Please sign in to comment.