Skip to content

Commit

Permalink
chore(Utilities): Update commander usage
Browse files Browse the repository at this point in the history
  • Loading branch information
floryst committed Sep 21, 2021
1 parent fec5edc commit a5c51d5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
18 changes: 10 additions & 8 deletions Utilities/DataGenerator/convert-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ program.version('1.0.0')
.option('--sample-data [path]', 'Convert sample data from ParaViewData\n')
.parse(process.argv);

const options = program.opts();

// ----------------------------------------------------------------------------
// Need argument otherwise print help/usage
// ----------------------------------------------------------------------------
Expand All @@ -31,7 +33,7 @@ const pvPossibleBasePath = [];

if(!paraview) {
paraview = [];
[program.paraview].concat(pvPossibleBasePath).forEach(function(directory){
[options.paraview].concat(pvPossibleBasePath).forEach(function(directory){
try {
if(fs.statSync(directory).isDirectory()) {
paraview.push(directory);
Expand All @@ -42,7 +44,7 @@ if(!paraview) {
});
}

if (!process.argv.slice(2).length || !program.help || paraview.length === 0) {
if (!process.argv.slice(2).length || !options.help || paraview.length === 0) {
program.outputHelp();
process.exit(0);
}
Expand All @@ -51,12 +53,12 @@ var pvPythonExecs = shell.find(paraview).filter(function(file) { return file.mat
if(pvPythonExecs.length < 1) {
console.log('Could not find pvpython in your ParaView HOME directory ($PARAVIEW_HOME)');
program.outputHelp();
} else if (program.sampleData) {
} else if (options.sampleData) {
console.log('Extract sample datasets');
const cmdLineSample = [
pvPythonExecs[0], '-dr',
path.normalize(path.join(__dirname, 'vtk-data-converter.py')),
'--sample-data', program.sampleData,
'--sample-data', options.sampleData,
'--output', path.normalize(path.join(__dirname, '../../Data')),,
];
console.log('\n===============================================================================');
Expand All @@ -68,15 +70,15 @@ if(pvPythonExecs.length < 1) {
const cmdLine = [
pvPythonExecs[0], '-dr',
path.normalize(path.join(__dirname, 'vtk-data-converter.py')),
'--input', program.input,
'--output', program.output,
'--input', options.input,
'--output', options.output,
];

if (program.extractSurface) {
if (options.extractSurface) {
cmdLine.push('--extract-surface');
}

if (program.merge) {
if (options.merge) {
cmdLine.push('--merge');
}

Expand Down
3 changes: 2 additions & 1 deletion Utilities/ExampleRunner/example-runner-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ program
.option('--no-browser', 'Do not open the browser')
.parse(process.argv);

var configFilePath = path.join(process.cwd(), program.config.replace(/\//g, path.sep));
const options = program.opts();
var configFilePath = path.join(process.cwd(), options.config.replace(/\//g, path.sep));
var configuration = require(configFilePath);

function getSplitedPath(filePath) {
Expand Down
9 changes: 5 additions & 4 deletions Utilities/XMLConverter/xml2json-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ program.version('1.0.0')
.option('-o, --output [file.json]', 'Destination file\n')
.option('-p, --process [chemistry]', 'Name of post-processor to apply')
.parse(process.argv);
const options = program.opts();

var parser = new xml2js.Parser();
fs.readFile(program.input, function (err, data) {
fs.readFile(options.input, function (err, data) {
parser.parseString(data, function (err, result) {
var dataToWrite = result;
if (program.process) {
var postProcessor = require('./' + program.process + '/post-process.js');
if (options.process) {
var postProcessor = require('./' + options.process + '/post-process.js');
dataToWrite = postProcessor(result);
}
fs.writeFile(program.output, JSON.stringify(dataToWrite, null, 2), function(err) {
fs.writeFile(options.output, JSON.stringify(dataToWrite, null, 2), function(err) {
if(err) {
return console.log(err);
}
Expand Down

0 comments on commit a5c51d5

Please sign in to comment.