Skip to content

Commit

Permalink
refine shell func
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcook1186 committed Aug 30, 2023
1 parent fa7a616 commit d57db06
Showing 1 changed file with 25 additions and 40 deletions.
65 changes: 25 additions & 40 deletions src/lib/shell_imp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,32 @@ const fs = require('fs');
const yaml = require('js-yaml');

Check failure on line 2 in src/lib/shell_imp.ts

View workflow job for this annotation

GitHub Actions / build

"js-yaml" is extraneous
const cp = require('child_process');


function shellCommand(impl, execPath, omplName) {
/*
description:
spawns a child process to run an external IMP
expects execPath to be a path to an executable with a CLI exposing two methods: --calculate and --impl
The shell command then calls the --command method passing var impl as the path to the desired impl file
params:
- impl: (string) path to impl file
- execPath: (string) path to executable
- omplName: (string) savename for ompl file
returns:
- ompl data to stdout
- ompl data to disk as omplName.yaml
*/

// create a child process to run the CLI
const exe = execPath; // assign the path to an executable
try {
const child = cp.spawn(exe, ['--calculate', '--impl=' + impl]); // pass the CLI argument in the array

// handle the return data
child.stdout.on('data', function (data) {
// print to stdout
var o = '' + data
const yamlStr = yaml.safeDump(o, { lineWidth: -1 });
console.log(yamlStr)
fs.writeFileSync(omplName, yamlStr, 'utf8');
});
// close the process
child.stdin.end();
}
catch (e) {
// report error to stderr
console.error("Error calling external IMP: please check input arguments");
}
/*

Check failure on line 5 in src/lib/shell_imp.ts

View workflow job for this annotation

GitHub Actions / build

Trailing spaces not allowed
description:
spawns a child process to run an external IMP
expects execPath to be a path to an executable with a CLI exposing two methods: --calculate and --impl
The shell command then calls the --command method passing var impl as the path to the desired impl file
params:
- impl: (string) path to impl file
- execPath: (string) path to executable
- omplName: (string) savename for ompl file
returns:
- ompl data to stdout
- ompl data to disk as omplName.yaml
*/
function runModelInShell(impl, execPath, omplName) {
var out = ''

Check failure on line 21 in src/lib/shell_imp.ts

View workflow job for this annotation

GitHub Actions / build

Replace `··var·out·=·''` with `var·out·=·'';`

Check failure on line 21 in src/lib/shell_imp.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected var, use let or const instead
const child = cp.spawn(execPath, ['--calculate', '--impl=' + impl]);

Check failure on line 22 in src/lib/shell_imp.ts

View workflow job for this annotation

GitHub Actions / build

Delete `··`
child.stdout.on('data', function (data) {

Check failure on line 23 in src/lib/shell_imp.ts

View workflow job for this annotation

GitHub Actions / build

Delete `··`

Check failure on line 23 in src/lib/shell_imp.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected function expression
out = yaml.load(data)

Check failure on line 24 in src/lib/shell_imp.ts

View workflow job for this annotation

GitHub Actions / build

Replace `········out·=·yaml.load(data)` with `····out·=·yaml.load(data);`
fs.writeFileSync(omplName, yaml.dump(out), 'utf8');

Check failure on line 25 in src/lib/shell_imp.ts

View workflow job for this annotation

GitHub Actions / build

Delete `····`
});

Check failure on line 26 in src/lib/shell_imp.ts

View workflow job for this annotation

GitHub Actions / build

Replace `····` with `··`
child.stdin.end();
return out
}

//example invocation
// calling prototype python model available in ief-sandbox repo

//shellCommand('intel.yaml', '/bin/pimpl.py', 'ompl.yaml')
let out = runModelInShell('dow_msft.yaml', '/home/joe/Code/ief-sandbox/dist/cli/cli', 'ompl2.yaml')

Check warning on line 33 in src/lib/shell_imp.ts

View workflow job for this annotation

GitHub Actions / build

'out' is assigned a value but never used

0 comments on commit d57db06

Please sign in to comment.