1#![doc(
10 html_logo_url = "https://github.com/tauri-apps/tauri/raw/dev/app-icon.png",
11 html_favicon_url = "https://github.com/tauri-apps/tauri/raw/dev/app-icon.png"
12)]
13
14use tauri::{
15 plugin::{Builder, PluginApi, TauriPlugin},
16 AppHandle, Manager, Runtime, State,
17};
18
19mod config;
20mod error;
21mod parser;
22
23use config::{Arg, Config};
24
25pub use error::{Error, Result};
26pub use parser::{ArgData, Matches, SubcommandMatches};
27
28pub struct Cli<R: Runtime>(PluginApi<R, Config>);
29
30impl<R: Runtime> Cli<R> {
31 pub fn matches(&self) -> Result<parser::Matches> {
32 parser::get_matches(self.0.config(), self.0.app().package_info())
33 }
34}
35
36pub trait CliExt<R: Runtime> {
37 fn cli(&self) -> &Cli<R>;
38}
39
40impl<R: Runtime, T: Manager<R>> CliExt<R> for T {
41 fn cli(&self) -> &Cli<R> {
42 self.state::<Cli<R>>().inner()
43 }
44}
45
46#[tauri::command]
47fn cli_matches<R: Runtime>(_app: AppHandle<R>, cli: State<'_, Cli<R>>) -> Result<parser::Matches> {
48 cli.matches()
49}
50
51pub fn init<R: Runtime>() -> TauriPlugin<R, Config> {
52 Builder::new("cli")
53 .invoke_handler(tauri::generate_handler![cli_matches])
54 .setup(|app, api| {
55 app.manage(Cli(api));
56 Ok(())
57 })
58 .build()
59}