我正在研究开发一个piral cli扩展,并对CliPluginApi接口有几个问题:
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中的arguments和flags有什么区别?参数只需要位置参数吗?需要重新列出位置吗?
关于这个问题的最后一个问题--我想获得一个像数组一样的位置列表。它的语法是什么?我尝试过arguments: ['list[]'],,但它不起作用。
发布于 2020-06-20 20:16:50
Yes参数是位置参数,但是,它们也可能是可选的。
有关此区域的任何信息,请查看documentation of Yargs。这可能会有所帮助。
不过,您可以在argv中使用标志来描述这些位置词,例如:
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的单个类型。
希望这能有所帮助!
https://stackoverflow.com/questions/62479038
复制相似问题