命令行(cli)
从命令行接口解析参数。
当 tauri.conf.json
中的 build.withGlobalTauri
设置为 true
时,此包也可以通过 window.__TAURI__.cli
访问。
Interface
ArgMatch
Since: 1.0.0
属性
-
occurrences:
number
出现的次数
定义在: cli.ts:27
-
value:
null
|string
|boolean
|string[]
如果是单个值则为 string
,如果是flag则为 boolean
,如果是多个值则为 string[]
或 null
。
定义在: cli.ts:23
Functions
getMatches
-
getMatches(): Promise<
CliMatches
>
解析提供给当前进程的参数,并使用在 tauri.conf.json
中定义的 tauri.cli
配置获取匹配项。
示例
import { getMatches } from '@tauri-apps/api/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
}
Since: 1.0.0
返回: Promise<CliMatches
>