fix(): Compgen reply
This commit is contained in:
parent
6679297c2f
commit
c069f1f232
23
this
23
this
|
@ -29,20 +29,24 @@ class This {
|
||||||
outputError: (str, write) => write(this._echoInRed(str)),
|
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
|
// add functions for shell completion
|
||||||
this.program
|
this.program
|
||||||
.command('compgen')
|
.command('compgen')
|
||||||
.option('-s, --shell <name>', 'You can select between [bash]', 'bash')
|
.option('-s, --shell <name>', 'You can select between [bash]', 'bash')
|
||||||
.action((arg) => {
|
.action((arg) => {
|
||||||
const words = this.listMethods();
|
console.log(cmds.join(os.EOL));
|
||||||
console.log(words.join(os.EOL));
|
|
||||||
return process.exit();
|
return process.exit();
|
||||||
});
|
});
|
||||||
|
|
||||||
// dynamically add all methods with appropriate docstring to commander
|
|
||||||
this.listMethods().forEach((method) => {
|
|
||||||
this._parseDocStringToCmd(this[method]);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getClassName() {
|
getClassName() {
|
||||||
|
@ -51,7 +55,7 @@ class This {
|
||||||
|
|
||||||
listMethods() {
|
listMethods() {
|
||||||
const methods = Object.getOwnPropertyNames(Object.getPrototypeOf(this)).filter(
|
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;
|
return methods;
|
||||||
}
|
}
|
||||||
|
@ -261,6 +265,9 @@ class This {
|
||||||
this.program.option(match.groups['flag'], match.groups['description'], match.groups['defaultValue']);
|
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
|
// Higher-order function to decorate other functions and provide logging
|
||||||
|
|
Loading…
Reference in New Issue
Block a user