跳到內容
Tauri

@tauri-apps/plugin-cli

解析來自命令列介面的參數。

介面

ArgMatch

2.0.0

屬性

屬性類型描述定義於
occurrencesnumber出現次數Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/cli/guest-js/index.ts#L26
valuenull | string | boolean | string[]string (若接受值) boolean (若為旗標) string[] 或 null (若接受多個值)Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/cli/guest-js/index.ts#L22

CliMatches

2.0.0

屬性

屬性類型定義於
argsRecord<string, ArgMatch>Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/cli/guest-js/index.ts#L41
subcommandnull | SubcommandMatchSource: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/cli/guest-js/index.ts#L42

SubcommandMatch

2.0.0

屬性

屬性類型定義於
matchesCliMatchesSource: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/cli/guest-js/index.ts#L34
namestringSource: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/cli/guest-js/index.ts#L33

函式

getMatches()

function getMatches(): Promise<CliMatches>

解析提供給當前程序的參數,並使用 tauri.cli 中定義的組態,取得符合的項目 (matches) tauri.conf.json

回傳

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

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


© 2025 Tauri 貢獻者。CC-BY / MIT