Skip to content

Commit

Permalink
Adds filename option to external commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin J Dolan authored and Kevin J Dolan committed May 17, 2021
1 parent a0c0e0b commit c158142
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ command could be configured to utilize the hardware GPIO pins to interact with t
station alerting systems.
- `command`: The full command to run. The following values can be used to add arguments. `[timestamp]`, `[detectorName]`,
`[description]`, `[tones]`, `[matchAverages]`, `[recordingRelPath]` amd `[custom]`. Example:
`[description]`, `[tones]`, `[matchAverages]`, `[filename]` `[recordingRelPath]` amd `[custom]`. Example:
node ./rel/path/main.js [timestamp] \"[detectorName]\" \"[description]\" [tones] [matchAverages] [recordingRelPath] [custom]
- `description`: A description that will be used while logging
Expand Down
2 changes: 1 addition & 1 deletion config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
],
"externalCommands": [
{
"command": "node ./rel/path/main.js [timestamp] \"[detectorName]\" \"[description]\" [tones] [matchAverages] [recordingRelPath] [custom]",
"command": "node ./rel/path/main.js [timestamp] \"[detectorName]\" \"[filename]\" \"[description]\" [tones] [matchAverages] [recordingRelPath] [custom]",
"description": "fancy description for the logs",
"custom": {
"anyObject": true,
Expand Down
5 changes: 3 additions & 2 deletions notifiers/external.command.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ const chalk = require('chalk');
const log = require('../util/logger');

async function runExternalCommand({command, description="[Write a description for the command in the config file to display here]",
timestamp, tones, matchAverages, recordingRelPath=null, detectorName, custom}){
command = _formatCommand({command, description, timestamp, tones, matchAverages, recordingRelPath, detectorName, custom});
timestamp, tones, matchAverages, filename, recordingRelPath=null, detectorName, custom}){
command = _formatCommand({command, description, timestamp, tones, matchAverages, filename, recordingRelPath, detectorName, custom});
const commandArray = command.match(/(".*?"|[^"\s]+)+(?=\s*|\s*$)/g);
const args = commandArray.slice(1);
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -53,6 +53,7 @@ function _formatCommand(options){
options.command = options.command.replace("[tones]", _removeQuites(options.tones));
options.command = options.command.replace("[matchAverages]", _removeQuites(options.matchAverages));
options.command = options.command.replace("[recordingRelPath]", _removeQuites(options.recordingRelPath));
options.command = options.command.replace("[filename]", _removeQuites(options.filename));
options.command = options.command.replace("[detectorName]", _removeQuites(options.detectorName));
options.command = options.command.replace("[custom]", JSON.stringify(options.custom));
return options.command;
Expand Down
9 changes: 5 additions & 4 deletions test/notifiers/external.command.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ describe("External Command", function() {
it(`should be able to run external command`, async function () {
const timestamp = new Date().getTime();
const results = await runExternalCommand({
command: `node ${path.resolve("test/notifiers/bin/test.external.js")} [timestamp] "[detectorName]" "[description]" [tones] [matchAverages] [recordingRelPath] [custom]`,
command: `node ${path.resolve("test/notifiers/bin/test.external.js")} [timestamp] "[detectorName]" "[filename]" "[description]" [tones] [matchAverages] [recordingRelPath] [custom]`,
commandName: "Some External Task",
timestamp,
tones: [1000, 2000],
matchAverages: [1001, 2001],
filename: null,
filename: "testFileName.wav",
detectorName: "Test FD",
description: "Tone Detected",
custom: {obj: true}
Expand All @@ -21,6 +21,7 @@ describe("External Command", function() {
"myArgs: [",
` '${timestamp}',`,
" '\"Test FD\"',",
" '\"testFileName.wav\"',",
" '\"Tone Detected\"',",
" '1000,2000',",
" '1001,2001',",
Expand All @@ -45,12 +46,12 @@ describe("External Command", function() {
it(`should be able to run external bat command`, async function () {
const timestamp = new Date().getTime();
const results = await runExternalCommand({
command: `${path.resolve("test/notifiers/bin/test.bat")} [timestamp] "[detectorName]" "[description]" [tones] [matchAverages] [recordingRelPath] [custom]`,
command: `${path.resolve("test/notifiers/bin/test.bat")} [timestamp] "[detectorName]" "[filename]" "[description]" [tones] [matchAverages] [recordingRelPath] [custom]`,
commandName: "Some External Task",
timestamp,
tones: [1000, 2000],
matchAverages: [1001, 2001],
filename: null,
filename: "testFileName.wav",
detectorName: "Test FD",
description: "Tone Detected",
custom: {obj: true}
Expand Down

0 comments on commit c158142

Please sign in to comment.