Command Line Interface (CLI)
Ce contenu n’est pas encore disponible dans votre langue.
Tauri enables your app to have a CLI through clap, a robust command line argument parser. With a simple CLI definition in your tauri.conf.json
file, you can define your interface and read its argument matches map on JavaScript and/or Rust.
Supported Platforms
This plugin requires a Rust version of at least 1.77.2
Platform | Level | Notes |
---|---|---|
windows | ||
linux | ||
macos | ||
android | | |
ios | |
- Windows
- Due to an OS limitation, production apps are not be able to write text back to the calling console by default. Please check out tauri#8305 for a workaround.
Setup
Install the CLI plugin to get started.
Base Configuration
Under tauri.conf.json
, you have the following structure to configure the interface:
Adding Arguments
The args
array represents the list of arguments accepted by its command or subcommand.
Positional Arguments
A positional argument is identified by its position in the list of arguments. With the following configuration:
Users can run your app as ./app tauri.txt dest.txt
and the arg matches map will define source
as "tauri.txt"
and destination
as "dest.txt"
.
Named Arguments
A named argument is a (key, value) pair where the key identifies the value. With the following configuration:
Users can run your app as ./app --type foo bar
, ./app -t foo -t bar
or ./app --type=foo,bar
and the arg matches map will define type
as ["foo", "bar"]
.
Flag Arguments
A flag argument is a standalone key whose presence or absence provides information to your application. With the following configuration:
Users can run your app as ./app -v -v -v
, ./app --verbose --verbose --verbose
or ./app -vvv
and the arg matches map will define verbose
as true
, with occurrences = 3
.
Subcommands
Some CLI applications have additional interfaces as subcommands. For instance, the git
CLI has git branch
, git commit
and git push
. You can define additional nested interfaces with the subcommands
array:
Its configuration is the same as the root application configuration, with the description
, longDescription
, args
, etc.
Usage
The CLI plugin is available in both JavaScript and Rust.
Permissions
By default all potentially dangerous plugin commands and scopes are blocked and cannot be accessed. You must modify the permissions in your capabilities
configuration to enable these.
See the Capabilities Overview for more information and the step by step guide to use plugin permissions.
Default Permission
Allows reading the CLI matches
allow-cli-matches
Permission Table
Identifier | Description |
---|---|
|
Enables the cli_matches command without any pre-configured scope. |
|
Denies the cli_matches command without any pre-configured scope. |
© 2024 Tauri Contributors. CC-BY / MIT