fix(): Downgrade commander and override default exit behaviour

This commit is contained in:
Chris Daßler 2024-06-30 19:49:12 +02:00
parent e29f085961
commit d6336f4836
6 changed files with 27 additions and 23 deletions

View File

@ -24,3 +24,5 @@ The iSH-App on iOS has the following latest versions available
- npm v7.17.0
These versions are deprecated, but if we want to use these scripts on iSH, we have to make sure they run on that outdated versions.
- only commander v11 supports nodejs v16

14
log
View File

@ -60,16 +60,20 @@ class Log extends This {
/**
* @program()
*/
this.program.parse();
this.program.exitOverride();
try {
this.program.parse();
} catch (err) {
// custom processing...
}
if (Object.keys(this.program.opts()).length || this.program.args.length) {
//// Debugging commander options and arguments
const opts = util.inspect(this.program.opts(), { depth: null, colors: true, showHidden: true });
const args = util.inspect(this.program.args, { depth: null, colors: true, showHidden: true });
//this.echo(`Options: ${opts}`);
//this.echo(`Remaining arguments: ${args}`);
} else {
this.program.outputHelp();
this.echo(`Options: ${opts}`);
this.echo(`Remaining arguments: ${args}`);
}
}
}

10
package-lock.json generated
View File

@ -5,7 +5,7 @@
"packages": {
"": {
"dependencies": {
"commander": "^12.1.0",
"commander": "^11.1.0",
"shelljs": "^0.8.5"
},
"devDependencies": {
@ -27,11 +27,11 @@
}
},
"node_modules/commander": {
"version": "12.1.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-12.1.0.tgz",
"integrity": "sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA==",
"version": "11.1.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-11.1.0.tgz",
"integrity": "sha512-yPVavfyCcRhmorC7rWlkHn15b4wDVgVmBA7kV4QVBsF7kv/9TKJAbAXVTxvTnwP8HHKjRCJDClKbciiYS7p0DQ==",
"engines": {
"node": ">=18"
"node": ">=16"
}
},
"node_modules/concat-map": {

View File

@ -3,7 +3,7 @@
"format": "prettier --ignore-path .gitignore --write \"./*\""
},
"dependencies": {
"commander": "^12.1.0",
"commander": "^11.1.0",
"shelljs": "^0.8.5"
},
"devDependencies": {

View File

@ -1,23 +1,17 @@
#!/usr/bin/env node
const This = require('./this');
const { Command } = require('commander');
const program = new Command();
class PmSearch extends This {
constructor() {
super();
this.version = '0.0.1';
this.description = 'Search packages of fake package manager';
super.init(); // initialize commander with overridden version and description
}
start() {
// Usage
const pmSearch = new PmSearch();
// Output: Methods of ExampleClass: [ 'methodOne', 'methodTwo' ]
// Properties of ExampleClass: [ 'propertyOne', 'propertyTwo', 'version' ] and Version: 1.1.0
// pmSearch.discovery();
program.name(this.scriptName).version('0.0.1').description('Search packages of fake package manager').outputHelp();
super.start();
}
}

10
this
View File

@ -64,7 +64,13 @@ class This {
/**
* @program()
*/
this.program.parse();
this.program.exitOverride();
try {
this.program.parse();
} catch (err) {
// custom processing...
}
if (Object.keys(this.program.opts()).length || this.program.args.length) {
// Debugging commander options and arguments
@ -72,8 +78,6 @@ class This {
const args = util.inspect(this.program.args, { depth: null, colors: true, showHidden: true });
this.execCmd(`${this.workingDir}/log echo 'Options: ${opts}'`);
this.execCmd(`${this.workingDir}/log echo 'Remaining arguments: ${args}'`);
} else {
this.program.outputHelp();
}
}