diff --git a/package.json b/package.json index 654238f..c4df53e 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,9 @@ "bin": "src/index.js", "main": "src/index.js", "scripts": { - "build": "pkg package.json" + "build": "pkg package.json", + "copy-local": "cp -f out/kr-linux ~/bin/kr", + "build-local": "npm run build && npm run copy-local" }, "pkg": { "scripts": "src/**/*.js", diff --git a/src/index.js b/src/index.js index f3fef06..048d14e 100644 --- a/src/index.js +++ b/src/index.js @@ -20,7 +20,6 @@ const yargs = Yargs(process.argv.splice(2)) description: 'Time in seconds we want to delay the restart with.', type: 'number' }) - .conflicts('_rpm', '_rph') const { _ = [], _rpm: rpm, _rph: rph, _delay: delay } = yargs.argv; const [command, ...args ] = _; @@ -36,7 +35,9 @@ let historyMax = 4; let seconds = SECONDS_IN_A_MINUTE; let restartName = 'minute'; -if (rpm) { +if (rpm && rph) { + return console.error('Currently, can not define both --rpm and --rph, please choose only one.'); +} else if (rpm) { historyMax = rpm } else if (rph) { historyMax = rph @@ -64,8 +65,15 @@ const checkHistory = () => Object.keys(history).length <= historyMax; const restart = () => setTimeout(() => runCommand(delay), delay * 1000); +const spawnCommand = () => { + const [ spawnCommand, ...cmdArgs ] = command.split(' '); + const spawnArgs = [...cmdArgs, ...args]; + + return spawn(spawnCommand, spawnArgs); +} + const runCommand = () => { - const runner = spawn(command, args); + const runner = spawnCommand(); const commandLogs = [];