Skip to content

Commit

Permalink
Merge branch 'main' into snyk-upgrade-13dcf5266fb34892a7f4540ef4baaf68
Browse files Browse the repository at this point in the history
  • Loading branch information
so5 authored Jun 16, 2024
2 parents 97efa74 + 123af57 commit df87856
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 22 deletions.
2 changes: 1 addition & 1 deletion lib/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const sbs = new SBS({
.map((e) => { return e.argument; })
.reduce((a, c) => { return `${a}${watcher.delimiter || " "}${c}`; });

const cmd = `${watcher.cmd} ${argumentString}`.trim();
const cmd = `${watcher.cmd} ${watcher.withoutArgument ? "" : argumentString}`.trim();
let outputString = "";
let rt = 0;
if (watcher.onLocalhost) {
Expand Down
26 changes: 22 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const { requestSchema } = require("./schema.js");
* @param {string} request.delimiter - delimiter between each arguments default " "
* @param {number} request.interval - interval time between commands executed on the same host
* @param {string} request.argment - argument of command
* @param {Boolean} request.withoutArgument- if true, command will be issued without arguments
* @param {string} request.re - end determination regexp string
* @param {boolean} request.until - flag it flip re.test result
* @param {boolean} request.allowEmptyOutput - keep watching if cmd returns empty ouput
Expand Down Expand Up @@ -97,18 +98,34 @@ function addRequest (request) {
return watcher.addRequest(request);
}

/**
* replace command
* @param {string} id - id string which returnd by addRequest
* @param {string} cmd - new cmd for entire watcher
*
* please note this function affects all request for same watcher
*/
function replaceCmd (id, cmd) {
const watcher = getWatcherByRequestID(id);
if (!watcher) {
return false;
}
watcher.cmd = cmd;
return true;
}

/**
* delete watch request and stop watching
* @param {string} id - id string which returnd by addRequest
* @return {Boolean} - successufully removed or not
*/
function delRequest (id) {
const watcher = getWatcherByRequestID(id);
if (watcher) {
watcher.deleteRequest(id);
return true;
if (!watcher) {
return false;
}
return false;
watcher.deleteRequest(id);
return true;
}

/**
Expand All @@ -133,5 +150,6 @@ module.exports = {
addRequest,
delRequest,
getRequest,
replaceCmd,
clearAll
};
1 change: 1 addition & 0 deletions lib/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const requestSchema = {
cmd: { type: "string", pattern: "\\S+", transform: ["trim"] },
delimiter: { type: "string", pattern: "\\S+", transform: ["trim"] },
argument: { type: "string", pattern: "\\S+", transform: ["trim"] },
withoutArgument: { type: "boolean" },
re: { type: "string", pattern: "\\S+", transform: ["trim"] },
interval: { type: "number", minimum: 0 },
until: { type: "boolean" },
Expand Down
1 change: 1 addition & 0 deletions lib/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class Watcher {
this.cmd = arg.cmd;
this.delimiter = arg.delimiter;
this.interval = arg.interval;
this.withoutArgument = arg.withoutArgument;

if (onLocalhost(arg.hostInfo)) {
this.onLocalhost = true;
Expand Down
26 changes: 13 additions & 13 deletions package-lock.json

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

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rwatchd",
"version": "0.5.0",
"version": "0.6.0",
"description": "Remote WATCH Daemon",
"main": "lib/index.js",
"engines": {
Expand Down Expand Up @@ -46,11 +46,11 @@
"sinon-chai": "^3.7.0"
},
"dependencies": {
"ajv": "^8.12.0",
"ajv": "^8.13.0",
"ajv-keywords": "^5.1.0",
"debug": "^4.3.4",
"shlex": "^2.1.2",
"simple-batch-system": "^1.19.0",
"ssh-client-wrapper": "^2.4.1"
"ssh-client-wrapper": "^2.4.1",
"simple-batch-system": "^1.20.0"
}
}

0 comments on commit df87856

Please sign in to comment.