Skip to content

Commit

Permalink
Sync shortcut (#58)
Browse files Browse the repository at this point in the history
* add sync shorthand

* add sync shorthand tests
  • Loading branch information
joehand authored Jan 3, 2017
1 parent 51bd27f commit bfc2054
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
15 changes: 12 additions & 3 deletions bin/cli.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env node

var subcommand = require('subcommand')
var usage = require('../lib/usage')

process.title = 'dat-next'

Expand All @@ -24,9 +25,9 @@ var config = {
abbr: 'v'
}
],
command: require('../lib/usage')
command: usage
},
none: require('../lib/usage'),
none: syncShorthand,
commands: [
require('../lib/commands/clone'),
require('../lib/commands/create'),
Expand All @@ -41,7 +42,7 @@ var config = {
require('../lib/commands/auth/login'),
{
name: 'help',
command: require('../lib/usage')
command: usage
}
],
aliases: {
Expand All @@ -58,3 +59,11 @@ function alias (argv) {
argv[0] = config.aliases[cmd]
return argv
}

function syncShorthand (opts) {
if (!opts._.length) return usage(opts)
opts.dir = opts._[0]
var sync = require('../lib/commands/sync')
opts.import = opts.import || true // TODO: use default opts in sync
sync.command(opts)
}
17 changes: 17 additions & 0 deletions tests/sync-owner.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,23 @@ test('sync-owner - port and utp options', function (t) {
}
})

test('sync-owner - shorthand', function (t) {
var cmd = dat + ' .'
var st = spawn(t, cmd, {cwd: fixtures})

st.stdout.match(function (output) {
var sharing = output.indexOf('Sharing latest') > -1
if (!sharing) return false

t.ok(help.matchLink(output), 'prints link')

st.kill()
return true
})
st.stderr.empty()
st.end()
})

test.onFinish(function () {
rimraf.sync(path.join(fixtures, '.dat'))
})
21 changes: 18 additions & 3 deletions tests/sync-remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ var help = require('./helpers')
var dat = path.resolve(path.join(__dirname, '..', 'bin', 'cli.js'))
var baseTestDir = help.testFolder()
var shareDat
var syncDir

test('sync-remote - default opts', function (t) {
// cmd: dat sync
var key
var datDir

help.shareFixtures({import: false}, function (_, fixturesDat) {
shareDat = fixturesDat
key = shareDat.key.toString('hex')
datDir = path.join(baseTestDir, key)
syncDir = path.join(baseTestDir, key)

makeClone(function () {
shareDat.importFiles(function () {
var cmd = dat + ' sync'
var st = spawn(t, cmd, {cwd: datDir})
var st = spawn(t, cmd, {cwd: syncDir})
st.stdout.match(function (output) {
var updated = output.indexOf('Files updated') > -1
if (!updated) return false
Expand Down Expand Up @@ -60,6 +60,21 @@ test('sync-remote - default opts', function (t) {
}
})

test('sync-remote - shorthand sync', function (t) {
// cmd: dat sync
var cmd = dat + ' .'
var st = spawn(t, cmd, {cwd: syncDir})
st.stdout.match(function (output) {
var syncing = output.indexOf('Syncing Dat Archive') > -1
if (!syncing) return false
t.ok(help.matchLink(output), 'prints link')
st.kill()
return true
})
st.stderr.empty()
st.end()
})

test('close sharer', function (t) {
shareDat.close(function () {
rimraf.sync(path.join(shareDat.path, '.dat'))
Expand Down

0 comments on commit bfc2054

Please sign in to comment.