跳转到内容
Tauri

@tauri-apps/plugin-cli

从您的命令行界面解析参数。

接口

ArgMatch

2.0.0

属性

属性类型描述定义在
occurrencesnumber发生次数来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/cli/guest-js/index.ts#L26
valuenull | string | boolean | string[]如果带值则为字符串,如果是标志则为布尔类型,如果为字符串数组或多个值则为 null来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/cli/guest-js/index.ts#L22

CliMatches

2.0.0

属性

属性类型定义在
argsRecord<string, ArgMatch>来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/cli/guest-js/index.ts#L41
subcommandnull | SubcommandMatch来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/cli/guest-js/index.ts#L42

SubcommandMatch

2.0.0

属性

属性类型定义在
matchesCliMatches来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/cli/guest-js/index.ts#L34
namestring来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/cli/guest-js/index.ts#L33

函数

getMatches()

function getMatches(): Promise<CliMatches>

解析传递给当前进程的参数,并使用在 tauri.conf.json 中定义的配置 tauri.cli 获取匹配项

返回

Promise<CliMatches>

示例

import { getMatches } from '@tauri-apps/plugin-cli';
const matches = await getMatches();
if (matches.subcommand?.name === 'run') {
// `./your-app run $ARGS` was executed
const args = matches.subcommand?.matches.args
if ('debug' in args) {
// `./your-app run --debug` was executed
}
} else {
const args = matches.args
// `./your-app $ARGS` was executed
}

2.0.0

来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/cli/guest-js/index.ts#L66


© 2025 Tauri 贡献者. CC-BY / MIT