[cli] Allow plugins to extend CLI
brillout opened this issue · 5 comments
This would require changes in https://github.com/brillout/reframe/blob/master/core/utils/processReframeConfig.js
This would be super cool though.
@tdfranklin up for it?
Happy to take a stab at it! Might need you to point me in the right direction of what you're looking for, if you don't mind?
A plugin can currently do something like that:
function myPlugin() {
return {
webpackBrowserConfig: ({config}) => {
// change webpack config
return config;
},
};
}
We could extend a plugin to be able to do
function myPlugin() {
return {
commands: [
{
name: 'my-new-command',
description: 'This is an awesome command',
handler: function (cliArgs) {
console.log('something cool happened');
},
},
],
};
}
For that
1.
processReframeConfig
needs to be changed.
See comments in the https://github.com/brillout/reframe/blob/master/core/utils/processReframeConfig.js file
2.
The reframe config needs to be loaded and processReframeConfig
needs to be called before the whole commander thingy: https://github.com/brillout/reframe/blob/c75f2a5de272b18523186e50d94848c62e88aee4/core/cli/cli.js#L15-L39
Currently the reframe config is loaded here: https://github.com/brillout/reframe/blob/c75f2a5de272b18523186e50d94848c62e88aee4/core/cli/cli.js#L53-L55.
We would move that before the commander stuff.
What could also help is to look at current plugins such as https://github.com/brillout/reframe/blob/master/plugins/postcss/index.js
You're right, after
const {pagesDirPath, reframeConfigPath, appDirPath} = find_files(cwd);
const reframeConfig = reframeConfigPath && require(reframeConfigPath);
we need to process the reframe config:
const {processReframeConfig} = require('@reframe/utils/processReframeConfig');
processReframeConfig(reframeConfig);
// we now have access to the processed stuff
console.log(reframeConfig._processed);
// We could change `processReframeConfig` to add something like
// `reframeConfig._processed.cli_commands`
At that point, everything we do in processReframeConfig
will be availble to cli.js
Done
Good job @tdfranklin