Skip to content

Commit

Permalink
Replace node-getopt with commander for args
Browse files Browse the repository at this point in the history
node-getopt isn't maintained and nodejs has started complaining about
deprecated features in it.
  • Loading branch information
CendioOssman committed Dec 17, 2024
1 parent 52392ec commit 3e2e04b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
"karma-safari-launcher": "latest",
"karma-script-launcher": "latest",
"mocha": "latest",
"node-getopt": "latest",
"po2json": "latest",
"sinon": "latest",
"sinon-chai": "latest"
Expand Down
18 changes: 7 additions & 11 deletions po/po2js
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

const getopt = require('node-getopt');
const { program } = require('commander');
const fs = require('fs');
const po2json = require("po2json");

const opt = getopt.create([
['h', 'help', 'display this help'],
]).bindHelp().parseSystem();
program
.argument('<input>')
.argument('<output>')
.parse(process.argv);

if (opt.argv.length != 2) {
console.error("Incorrect number of arguments given");
process.exit(1);
}

const data = po2json.parseFileSync(opt.argv[0]);
const data = po2json.parseFileSync(program.args[0]);

const bodyPart = Object.keys(data)
.filter(msgid => msgid !== "")
Expand All @@ -42,4 +38,4 @@ const bodyPart = Object.keys(data)

const output = "{\n" + bodyPart + "\n}";

fs.writeFileSync(opt.argv[1], output);
fs.writeFileSync(program.args[1], output);
16 changes: 8 additions & 8 deletions po/xgettext-html
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
* Licensed under MPL 2.0 (see LICENSE.txt)
*/

const getopt = require('node-getopt');
const { program } = require('commander');
const jsdom = require("jsdom");
const fs = require("fs");

const opt = getopt.create([
['o', 'output=FILE', 'write output to specified file'],
['h', 'help', 'display this help'],
]).bindHelp().parseSystem();
program
.argument('<INPUT...>')
.requiredOption('-o, --output <FILE>', 'write output to specified file')
.parse(process.argv);

const strings = {};

Expand Down Expand Up @@ -87,8 +87,8 @@ function process(elem, locator, enabled) {
}
}

for (let i = 0; i < opt.argv.length; i++) {
const fn = opt.argv[i];
for (let i = 0; i < program.args.length; i++) {
const fn = program.args[i];
const file = fs.readFileSync(fn, "utf8");
const dom = new jsdom.JSDOM(file, { includeNodeLocations: true });
const body = dom.window.document.body;
Expand Down Expand Up @@ -116,4 +116,4 @@ for (let str in strings) {
output += "\n";
}

fs.writeFileSync(opt.options.output, output);
fs.writeFileSync(program.opts().output, output);

0 comments on commit 3e2e04b

Please sign in to comment.