Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolaRHristov committed Oct 9, 2024
1 parent 2f96aa5 commit 615a229
Show file tree
Hide file tree
Showing 9 changed files with 692 additions and 747 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ macos = { level = "full", notes = "" }
android = { level = "none", notes = "" }
ios = { level = "none", notes = "" }


[build-dependencies]
tauri-plugin = { workspace = true, features = ["build"] }

Expand Down
313 changes: 162 additions & 151 deletions Source/config.rs

Large diffs are not rendered by default.

15 changes: 7 additions & 8 deletions Source/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ use serde::{Serialize, Serializer};

#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("failed to parse arguments: {0}")]
ParseCli(#[from] clap::Error),
#[error("failed to parse arguments: {0}")]
ParseCli(#[from] clap::Error),
}

impl Serialize for Error {
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(self.to_string().as_ref())
}
fn serialize<S>(&self, serializer:S) -> std::result::Result<S::Ok, S::Error>
where
S: Serializer, {
serializer.serialize_str(self.to_string().as_ref())
}
}

pub type Result<T> = std::result::Result<T, Error>;
52 changes: 26 additions & 26 deletions Source/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,53 +9,53 @@
//! - Supported platforms: Windows, Linux and macOS.
#![doc(
html_logo_url = "https://github.com/tauri-apps/tauri/raw/dev/app-icon.png",
html_favicon_url = "https://github.com/tauri-apps/tauri/raw/dev/app-icon.png"
html_logo_url = "https://github.com/tauri-apps/tauri/raw/dev/app-icon.png",
html_favicon_url = "https://github.com/tauri-apps/tauri/raw/dev/app-icon.png"
)]

use tauri::{
plugin::{Builder, PluginApi, TauriPlugin},
AppHandle, Manager, Runtime, State,
plugin::{Builder, PluginApi, TauriPlugin},
AppHandle,
Manager,
Runtime,
State,
};

mod config;
mod error;
mod parser;

use config::{Arg, Config};

pub use error::{Error, Result};
pub use parser::{ArgData, Matches, SubcommandMatches};

pub struct Cli<R: Runtime>(PluginApi<R, Config>);
pub struct Cli<R:Runtime>(PluginApi<R, Config>);

impl<R: Runtime> Cli<R> {
pub fn matches(&self) -> Result<parser::Matches> {
parser::get_matches(self.0.config(), self.0.app().package_info())
}
impl<R:Runtime> Cli<R> {
pub fn matches(&self) -> Result<parser::Matches> {
parser::get_matches(self.0.config(), self.0.app().package_info())
}
}

pub trait CliExt<R: Runtime> {
fn cli(&self) -> &Cli<R>;
pub trait CliExt<R:Runtime> {
fn cli(&self) -> &Cli<R>;
}

impl<R: Runtime, T: Manager<R>> CliExt<R> for T {
fn cli(&self) -> &Cli<R> {
self.state::<Cli<R>>().inner()
}
impl<R:Runtime, T:Manager<R>> CliExt<R> for T {
fn cli(&self) -> &Cli<R> { self.state::<Cli<R>>().inner() }
}

#[tauri::command]
fn cli_matches<R: Runtime>(_app: AppHandle<R>, cli: State<'_, Cli<R>>) -> Result<parser::Matches> {
cli.matches()
fn cli_matches<R:Runtime>(_app:AppHandle<R>, cli:State<'_, Cli<R>>) -> Result<parser::Matches> {
cli.matches()
}

pub fn init<R: Runtime>() -> TauriPlugin<R, Config> {
Builder::new("cli")
.invoke_handler(tauri::generate_handler![cli_matches])
.setup(|app, api| {
app.manage(Cli(api));
Ok(())
})
.build()
pub fn init<R:Runtime>() -> TauriPlugin<R, Config> {
Builder::new("cli")
.invoke_handler(tauri::generate_handler![cli_matches])
.setup(|app, api| {
app.manage(Cli(api));
Ok(())
})
.build()
}
Loading

0 comments on commit 615a229

Please sign in to comment.