Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modify --exit for dat pull command, so that it exits after specified … #1098

Merged
merged 1 commit into from
Apr 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/).

## [Unreleased]
*Note: unreleased changes are added here.*
* `dat pull --exit=NN` exits after `NN` number of seconds, when there are no updates to sync.

## 13.9.0 - 2017-10-11

Expand Down
12 changes: 11 additions & 1 deletion src/commands/pull.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ module.exports = {
'Usage: dat pull'
].join('\n'),
options: [
{
name: 'exit',
boolean: false,
help: 'exit after specified number of seconds (gives the dat network time to find updates). defaults to 12 seconds.'
},

{
name: 'upload',
boolean: true,
Expand Down Expand Up @@ -58,7 +64,11 @@ function pull (opts) {

// Force these options for pull command
opts.createIfMissing = false
opts.exit = true

// If --exit is specified without a number of seconds, default to 12
if (opts.exit === true) {
opts.exit = 12
}

var neat = neatLog(archiveUI, { logspeed: opts.logspeed, quiet: opts.quiet, debug: opts.debug })
neat.use(trackArchive)
Expand Down
11 changes: 9 additions & 2 deletions src/lib/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,15 @@ function trackDownload (state, bus) {
archive.on('sync', function () {
debug('archive sync', state.stats.get())
state.download.nsync = true
var shouldExit = (state.download.modified && state.opts.exit)
if (shouldExit) return exit()
// if we are supposed to exit, do so if we've pulled changes or have given the network the desired wait time
if (state.opts.exit) {
if (state.download.modified) {
return exit()
} else {
var delayInMilliseconds = 1000 * state.opts.exit
setTimeout(exit, delayInMilliseconds)
}
}
if (state.dat.archive.version === 0) {
// TODO: deal with this.
// Sync sometimes fires early when it should wait for update.
Expand Down
4 changes: 4 additions & 0 deletions src/ui/components/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ function networkUI (state) {
}
}

if (state.opts.exit) {
title = `dat synced, exiting in ${state.opts.exit} seconds.`
}

if (!stats.downloaded || !stats.length) {
return '' // no metadata yet
}
Expand Down