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

drop sync-exec for security, upgrade sleep, normalize scope to main #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# http://editorconfig.org/

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
trim_trailing_whitespace = true

[*.js]
indent_size = 4
29 changes: 12 additions & 17 deletions package-lock.json

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

9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"description": "A command line utility to try executing a shell command and retry if it fails or repeat even if it succeeds.",
"main": "try.js",
"preferGlobal": true,
"bin" : {
"try" : "./try.js"
"bin": {
"try": "./try.js"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
Expand All @@ -31,8 +31,7 @@
},
"homepage": "https://github.com/preethamvishy/try#readme",
"dependencies": {
"commander": "^2.15.1",
"sleep": "^5.1.1",
"sync-exec": "^0.6.2"
"commander": "^2.20.3",
"sleep": "^6.1.0"
}
}
35 changes: 15 additions & 20 deletions try.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,33 @@
#!/usr/bin/env node
var commander = require('commander')
var exec = require('sync-exec');
var sleep = require('sleep');
var pack = require('./package.json');

var attempts,
timeout,
command,
attemptCount = 0
var commander = require('commander')
var execSync = require('child_process').execSync
var sleep = require('sleep')
var pack = require('./package.json')

commander
.version(pack.version)
.description(pack.description)
.option('-c, --command <cmd>', 'Command to try')
.option('-a, --attempts <number>', 'Maximum number of retry attempts. DEFAULT = 4')
.option('-t, --timeout <seconds>', 'Seconds between retries. DEFAULT = 4')
.option('-c, --command <cmd>', 'Command to try')
.option('-f, --force-repeat', 'Force repeated execution even if it succeeds')
.parse(process.argv)

function main() {
setArgs()
var command = commander.command || ''
var attemptCount = 0
var attempts = parseInt(commander.attempts || 4, 10)
var timeout = parseInt(commander.timeout || 4, 10)
var forceRepeat = commander.forceRepeat || false

while (attemptCount++ < attempts) {
var res = exec(command, { stdio: [0, 1, 2] })
if (res.status == 0 && !commander.forceRepeat)
var res = execSync(command, { stdio: [0, 1, 2] })
if (res.status == 0 && !forceRepeat)
break
sleep.sleep(parseInt(timeout))
sleep.sleep(timeout)
}
}

function setArgs() {
timeout = commander.timeout || 4
attempts = commander.attempts || 4
command = commander.command || ''
}

main()
process.on('SIGINT', process.exit());
process.on('SIGINT', process.exit())