From d6336f483691cc660d5968f7a80a853ec31c129d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20Da=C3=9Fler?= Date: Sun, 30 Jun 2024 19:49:12 +0200 Subject: [PATCH] fix(): Downgrade commander and override default exit behaviour --- README.md | 2 ++ log | 14 +++++++++----- package-lock.json | 10 +++++----- package.json | 2 +- pm-search | 12 +++--------- this | 10 +++++++--- 6 files changed, 27 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 72c68ed..a671a84 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/log b/log index 7c648dd..207c7fb 100755 --- a/log +++ b/log @@ -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}`); } } } diff --git a/package-lock.json b/package-lock.json index 89be523..7a143f7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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": { diff --git a/package.json b/package.json index 8700838..548c75d 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "format": "prettier --ignore-path .gitignore --write \"./*\"" }, "dependencies": { - "commander": "^12.1.0", + "commander": "^11.1.0", "shelljs": "^0.8.5" }, "devDependencies": { diff --git a/pm-search b/pm-search index f2fea7e..2a3a7d8 100755 --- a/pm-search +++ b/pm-search @@ -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(); } } diff --git a/this b/this index 53959ad..0105ed9 100644 --- a/this +++ b/this @@ -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(); } }