Skip to content

Commit

Permalink
Merge pull request #21 from ibm-watson-data-lab/issue20
Browse files Browse the repository at this point in the history
add new --nomonitor/-n option - fixes issue #20
  • Loading branch information
glynnbird committed Feb 21, 2018
2 parents f2d1c4a + e551b9b commit 982d0a4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ e.g.
- `--auth` / `-x` - also copy the `_security` document during replication
- `--live` / `-l` - set up continuous replications instead of the default "one-shot" replication
- `--quiet` / `-q` - suppress progress bars
- `--nomonitor` / `-n` - don't monitor the replications - just start the replication processed and exit. Only works with `--live`/`-l`
- `--help` / `-h` - show help message
- `--version` / `-v` - show version number

Expand Down
11 changes: 9 additions & 2 deletions bin/couchreplicate.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var argv = require('yargs')
.option('auth', { alias: 'x', describe: 'Also copy _security document', demandOption: false, default: false })
.option('quiet', { alias: 'q', describe: 'Supress progress bars', demandOption: false, default: false })
.option('live', { alias: 'l', describe: 'Setup live (continuous) replications instead', demandOption: false, default: false })
.option('nomonitor', { alias: 'n', describe: 'Don\'t monitor the replications after setup', demandOption: false, default: false })
.help('help')
.argv

Expand All @@ -20,13 +21,19 @@ var targetParsed = url.parse(argv.target)

// check source URL
if (!sourceParsed.protocol || !sourceParsed.hostname) {
console.error('invalid source URL')
console.error('Error: invalid source URL')
process.exit(1)
}

// check target URL
if (!targetParsed.protocol || !targetParsed.hostname) {
console.error('invalid target URL')
console.error('Error: invalid target URL')
process.exit(1)
}

// check for --nomonitor without live mode
if (argv.nomonitor && !argv.live) {
console.error('Error: --nomonitor/-n is only applicable with the --live/-l option')
process.exit(1)
}

Expand Down
19 changes: 13 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,19 @@ var migrateDB = function (opts) {
}).then((data) => {
ee.emit('status', status)

// optionally migrate the auth document
if (opts.auth) {
return migrateAuth(status.sourceURL, status.targetURL)
} else {

}
}).then((data) => {
// monitor the replication
return monitorReplication(status, ee)
if (opts.nomonitor && opts.live) {
resolve(status)
} else {
return monitorReplication(status, ee)
}
}).catch((e) => {
var msg = 'error'
if (e.error && e.error.reason) {
Expand Down Expand Up @@ -244,11 +255,7 @@ var migrateDB = function (opts) {
if (bar) {
bar.update(s.percent, { status: s.status })
}
if (opts.auth) {
migrateAuth(status.sourceURL, status.targetURL).then(() => { resolve(s) })
} else {
resolve(s)
}
resolve(s)
})
})
}
Expand Down

0 comments on commit 982d0a4

Please sign in to comment.