Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
FL03 committed Dec 27, 2022
1 parent b2aa07b commit 949d9da
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 14 deletions.
11 changes: 9 additions & 2 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ name = "acme-core"
repository = "https://github.com/FL03/acme"
version = "0.2.4"

[features]
default = [ "cli"]
full = [ "cli" ]

cli = [ "clap/cargo", "clap/derive", "clap/default", "clap/env"]

[lib]
crate-type = ["cdylib", "rlib"]
test = true
Expand All @@ -19,9 +25,10 @@ test = true
[dev-dependencies]

[dependencies]
async-trait = "0.1.59"
async-trait = "0.1.60"
axum = "0.6.1"
clap = { features = ["derive"], version = "4.0.29" }
axum-core = "0.3.0"
clap = { features = ["cargo", "derive", "env"], optional = true, version = "4.0.29" }
hyper = { features = ["full"], version = "0.14.23" }
http = "0.2.8"
http-body = "0.4.5"
Expand Down
4 changes: 0 additions & 4 deletions crates/core/src/specs/apps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,3 @@ pub trait AsyncApplicationSpawner: AsyncSpawable {
tracing::info!("Terminating the application and connected services...");
}
}

#[cfg(feature = "cli")]
#[cfg(not(feature = "wasm"))]
pub trait CommandLineInterface: clap::Parser {}
43 changes: 43 additions & 0 deletions crates/core/src/specs/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
Appellation: cli <specs>
Contrib: FL03 <jo3mccain@icloud.com>
Description: ... summary ...
*/
use super::{Handler, AsyncHandler};
use scsys::AsyncResult;

///
pub trait CLISpec: clap::Parser {
type Cmds: Handler + clap::Subcommand;

fn command(&self) -> Option<Self::Cmds>
where
Self: Sized;
fn handler(&self) -> scsys::Result<&Self>
where
Self: Sized,
{
if let Some(cmd) = self.command() {
cmd.handler()?;
}
Ok(self)
}
}
///
#[async_trait::async_trait]
pub trait AsyncCLISpec: clap::Parser {
type Cmds: AsyncHandler + clap::Subcommand;

fn command(&self) -> Option<Self::Cmds>
where
Self: Sized;
async fn handler(&self) -> AsyncResult<&Self>
where
Self: Sized,
{
if let Some(cmd) = self.command().clone() {
cmd.handler().await?;
}
Ok(self)
}
}
38 changes: 30 additions & 8 deletions crates/core/src/specs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,36 @@
Contrib: FL03 <jo3mccain@icloud.com>
Description: ... summary ...
*/
pub use self::apps::*;
pub use self::{apps::*, cli::*};

pub(crate) mod apps;
#[cfg(feature = "cli")]
pub(crate) mod cli;

use async_trait::async_trait;

///
#[async_trait]
pub trait AsyncHandler: Clone + Send + Sync {
type Error: std::error::Error + Send + Sync + 'static;

async fn handler(&self) -> Result<&Self, Self::Error>
where
Self: Sized;
}
///
#[async_trait]
pub trait AsyncSpawable {
async fn spawn(&mut self) -> scsys::AsyncResult<&Self>;
}
///
pub trait BaseApplication: BaseObject + Versionable {
fn application(&self) -> &Self {
self
}
fn namespace(&self) -> String;
}

///
pub trait BaseObject {
fn count(&self) -> usize;
fn name(&self) -> String;
Expand All @@ -22,16 +41,19 @@ pub trait BaseObject {
}
fn symbol(&self) -> String;
}
///
pub trait Handler: Clone {
type Error: std::error::Error + 'static;

fn handler(&self) -> Result<&Self, Self::Error>
where
Self: Sized;
}
///
pub trait Spawnable {
fn spawn(&mut self) -> scsys::Result<&Self>;
}

#[async_trait::async_trait]
pub trait AsyncSpawable {
async fn spawn(&mut self) -> scsys::AsyncResult<&Self>;
}

///
pub trait Versionable {
type Error;

Expand Down

0 comments on commit 949d9da

Please sign in to comment.