首页 > 解决方案 > jhipster 将选项传递给蓝图

问题描述

我正在尝试创建一个 jhipster 蓝图来覆盖弹簧控制器的功能。我想访问从命令行运行的选项:

jhipster -d --blueprint generator-jhipster-baris-blueprint spring-controller policyEffectiveStatus --path 附录

这个命令使我的蓝图运行。我可以通过以下方式从代码中的参数访问名称“policyEffectiveStatus”:

this.argument('name', { type: String, required: true });
this.name = this.options.name;

但我无法访问选项路径。如何将选项传递给我的蓝图?

这是我的 index.js :

module.exports = class extends BaseGenerator {
constructor(args, opts) {
super(args, Object.assign({ fromBlueprint: true }, opts)); // fromBlueprint 
variable is important
this.argument('name', { type: String, required: true });

   // This adds support for a `--path` flag
    this.option('path', {
        desc: 'Indicates the path for class request mapping',
        type: String
    });

    this.path = this.options['path'];
    this.log(`this.path is ${this.path}`);
    this.path = this.options.path;
    this.log(`this.path is ${this.path}`);

    this.name = this.options.name;

    const jhContext = this.jhipsterContext = this.options.jhipsterContext;
    this.configOptions = jhContext.configOptions || {};

    if (!jhContext) {
        this.error(`This is a JHipster blueprint and should be used only like ${chalk.yellow('jhipster --blueprint generator-jhipster-sample-blueprint')}`);
    }
}

我正在运行的命令是:

命令

标签: jhipsteroptionsblueprint

解决方案


刚刚发现它们存在于 jhipster 上下文下的选项中,这意味着:

this.options.jhipsterContext.options

而不是这个

this.options

推荐阅读