WIP: Merge 'dev' into 'main' #1
32
log
32
log
|
@ -60,20 +60,28 @@ class Log extends This {
|
||||||
/**
|
/**
|
||||||
* @program()
|
* @program()
|
||||||
*/
|
*/
|
||||||
this.program.exitOverride();
|
if (this.debugLevel > 2) {
|
||||||
|
this.program.exitOverride();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
this.program.parse();
|
||||||
|
} catch (err) {
|
||||||
|
// this.echo('\n');
|
||||||
|
// this.error(err);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
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('\n');
|
||||||
|
this.echo(`Options: ${opts}`);
|
||||||
|
this.echo(`Remaining arguments: ${args}`);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// don't debug log if level is < 3 or the output will be hard to read
|
||||||
this.program.parse();
|
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}`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ class MyUpdateSubCommand extends This {
|
||||||
const myUpdateSubCommand = new MyUpdateSubCommand();
|
const myUpdateSubCommand = new MyUpdateSubCommand();
|
||||||
// Output: Methods of ExampleClass: [ 'methodOne', 'methodTwo' ]
|
// Output: Methods of ExampleClass: [ 'methodOne', 'methodTwo' ]
|
||||||
// Properties of ExampleClass: [ 'propertyOne', 'propertyTwo', 'version' ] and Version: 1.1.0
|
// Properties of ExampleClass: [ 'propertyOne', 'propertyTwo', 'version' ] and Version: 1.1.0
|
||||||
// myUpdateSubCommand.discovery();
|
// myUpdateSubCommand.discover();
|
||||||
|
|
||||||
if (!shell.which('git')) {
|
if (!shell.which('git')) {
|
||||||
shell.echo('Sorry, this script requires git');
|
shell.echo('Sorry, this script requires git');
|
||||||
|
|
12
pm
12
pm
|
@ -51,8 +51,8 @@ class Pm extends This {
|
||||||
// Calls stand-alone excutable `pm-list` because of @command(<description>) in docstring
|
// Calls stand-alone excutable `pm-list` because of @command(<description>) in docstring
|
||||||
}
|
}
|
||||||
|
|
||||||
// override This.discovery()
|
// override This.discover()
|
||||||
discovery() {
|
discover() {
|
||||||
const methods = this.listMethods();
|
const methods = this.listMethods();
|
||||||
return methods;
|
return methods;
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ class Pm extends This {
|
||||||
pmMethods.includes('search') &&
|
pmMethods.includes('search') &&
|
||||||
pmMethods.includes('update') &&
|
pmMethods.includes('update') &&
|
||||||
pmMethods.includes('list') &&
|
pmMethods.includes('list') &&
|
||||||
pmMethods.includes('discovery') &&
|
pmMethods.includes('discover') &&
|
||||||
pmMethods.includes('start');
|
pmMethods.includes('start');
|
||||||
const testInternalMethods = !pmMethods.includes('_testListMethod');
|
const testInternalMethods = !pmMethods.includes('_testListMethod');
|
||||||
|
|
||||||
|
@ -127,9 +127,9 @@ class Pm extends This {
|
||||||
|
|
||||||
// main
|
// main
|
||||||
const pm = new Pm();
|
const pm = new Pm();
|
||||||
// // applies logDecorator to this.discovery() and binds it to the instance to maintain the correct context
|
// // applies logDecorator to this.discover() and binds it to the instance to maintain the correct context
|
||||||
// const logDecoratedDiscovery = pm._logDecorator(pm.discovery).bind(pm);
|
// const logDecoratedDiscover = pm._logDecorator(pm.discover).bind(pm);
|
||||||
// logDecoratedDiscovery();
|
// logDecoratedDiscover();
|
||||||
|
|
||||||
pm.start();
|
pm.start();
|
||||||
//pm.selfTest();
|
//pm.selfTest();
|
||||||
|
|
52
this
52
this
|
@ -11,6 +11,7 @@ class This {
|
||||||
this.description = 'This is the parent class all other scripts should extend.';
|
this.description = 'This is the parent class all other scripts should extend.';
|
||||||
this.scriptName = path.parse(process.argv[1]).base;
|
this.scriptName = path.parse(process.argv[1]).base;
|
||||||
this.workingDir = path.parse(process.argv[1]).dir;
|
this.workingDir = path.parse(process.argv[1]).dir;
|
||||||
|
this.debugLevel = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
|
@ -49,10 +50,14 @@ class This {
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
discovery() {
|
discover() {
|
||||||
console.log(`My name is '${this.getClassName()}' and I have the version: ${this.version}`);
|
const methods = util.inspect(this.listMethods(), { depth: null, colors: true, showHidden: true });
|
||||||
console.log(`My methods are:`, this.listMethods());
|
const properties = util.inspect(this.listProperties(), { depth: null, colors: true, showHidden: true });
|
||||||
console.log(`My properties are:`, this.listProperties());
|
this.execCmd(
|
||||||
|
`${this.workingDir}/log echo 'My name is "${this.getClassName()}" and I have the version: ${this.version}'`
|
||||||
|
);
|
||||||
|
this.execCmd(`${this.workingDir}/log echo 'My methods are: ${methods}'`);
|
||||||
|
this.execCmd(`${this.workingDir}/log echo 'My properties are: ${properties}'`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Method to create a context manager for this instance
|
// Method to create a context manager for this instance
|
||||||
|
@ -64,20 +69,37 @@ class This {
|
||||||
/**
|
/**
|
||||||
* @program()
|
* @program()
|
||||||
*/
|
*/
|
||||||
this.program.exitOverride();
|
if (this.debugLevel > 0) {
|
||||||
|
this.program.exitOverride();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
this.program.parse();
|
||||||
|
|
||||||
|
// show help even if there are no commands registered
|
||||||
|
if (this.program.commands.length == 0) {
|
||||||
|
this.program.outputHelp();
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
// this.execCmd(`${this.workingDir}/log echo '\n'`);
|
||||||
|
// this.execCmd(`${this.workingDir}/log error '${err}'`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
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.execCmd(`${this.workingDir}/log echo '\n'`);
|
||||||
|
this.execCmd(`${this.workingDir}/log echo 'Options: ${opts}'`);
|
||||||
|
this.execCmd(`${this.workingDir}/log echo 'Remaining arguments: ${args}'`);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
this.program.parse();
|
this.program.parse();
|
||||||
} catch (err) {
|
|
||||||
// custom processing...
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Object.keys(this.program.opts()).length || this.program.args.length) {
|
// show help even if there are no commands registered
|
||||||
// Debugging commander options and arguments
|
if (this.program.commands.length == 0) {
|
||||||
const opts = util.inspect(this.program.opts(), { depth: null, colors: true, showHidden: true });
|
this.program.outputHelp();
|
||||||
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}'`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user