fix(): Compgen reply

This commit is contained in:
Chris Daßler 2024-07-02 23:37:20 +02:00
parent 6679297c2f
commit c069f1f232

23
this
View File

@ -29,20 +29,24 @@ class This {
outputError: (str, write) => write(this._echoInRed(str)),
});
// dynamically add all methods with appropriate docstring to commander
let cmds = [];
this.listMethods().forEach((method) => {
let cmd = this._parseDocStringToCmd(this[method]);
// exclude start function as commandline cmd, because its the scripts main entry point
if (cmd && cmd != 'start') {
cmds.push(cmd);
}
});
// add functions for shell completion
this.program
.command('compgen')
.option('-s, --shell <name>', 'You can select between [bash]', 'bash')
.action((arg) => {
const words = this.listMethods();
console.log(words.join(os.EOL));
console.log(cmds.join(os.EOL));
return process.exit();
});
// dynamically add all methods with appropriate docstring to commander
this.listMethods().forEach((method) => {
this._parseDocStringToCmd(this[method]);
});
}
getClassName() {
@ -51,7 +55,7 @@ class This {
listMethods() {
const methods = Object.getOwnPropertyNames(Object.getPrototypeOf(this)).filter(
(prop) => typeof this[prop] === 'function' && prop !== 'constructor' && prop !== 'start' && !prop.startsWith('_')
(prop) => typeof this[prop] === 'function' && prop !== 'constructor' && !prop.startsWith('_')
);
return methods;
}
@ -261,6 +265,9 @@ class This {
this.program.option(match.groups['flag'], match.groups['description'], match.groups['defaultValue']);
}
}
// return name of function, if docstring could be parsed successfully
return fn.name;
}
// Higher-order function to decorate other functions and provide logging