首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Piral扩展参数格式

Piral扩展参数格式
EN

Stack Overflow用户
提问于 2020-06-20 05:53:23
回答 1查看 18关注 0票数 1

我正在研究开发一个piral cli扩展,并对CliPluginApi接口有几个问题:

代码语言:javascript
复制
module.exports = function (cliApi) {
  cliApi.withCommand({
    name: 'dependencies-pilet',
    alias: ['deps-pilet'],
    description: 'Lists the dependencies of the current pilet.',
    arguments: [],
    flags(argv) {
      return argv
        .boolean('only-shared')
        .describe('only-shared', 'Only outputs the declared shared dependencies.')
        .default('only-shared', false)
        .string('base')
        .default('base', process.cwd())
        .describe('base', 'Sets the base directory. By default the current directory is used.');
    },
    run(args) {
      // your code here, where args.onlyShared refers to our custom argument
    },
  });
};

ToolCommand中的argumentsflags有什么区别?参数只需要位置参数吗?需要重新列出位置吗?

关于这个问题的最后一个问题--我想获得一个像数组一样的位置列表。它的语法是什么?我尝试过arguments: ['list[]'],,但它不起作用。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-06-20 20:16:50

Yes参数是位置参数,但是,它们也可能是可选的。

有关此区域的任何信息,请查看documentation of Yargs。这可能会有所帮助。

不过,您可以在argv中使用标志来描述这些位置词,例如:

代码语言:javascript
复制
return argv
    .positional('source', {
        type: 'string',
        describe: 'Sets the source root directory or index.html file for collecting all the information.',
        default: apps.debugPiralDefaults.entry,
    })
    // ...

关于您对数组的问题:要允许多个,您可以使用..后缀作为位置名称。

在您的情况下,这将意味着:arguments: ['[list..]'],

在Yargs中,[]不是指数组,而是可选的。这与<>相反,后者意味着需要。对于位置描述仍然使用,例如,Yargs ->您在这里仅描述了一个元素,但由于您指定了..,因此传输的数据类型将始终是Array<T>,其中T是您给Yargs的单个类型。

希望这能有所帮助!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62479038

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档