feat: beginning of omnia

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2023-12-11 20:25:06 +01:00
parent f009887772
commit 32c2703ef2
6 changed files with 849 additions and 1 deletions

1
crates/omnia/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/target

15
crates/omnia/Cargo.toml Normal file
View File

@@ -0,0 +1,15 @@
[package]
name = "omnia"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
clap = { version = "4.4.11", features = ["string"] }
color-eyre = "0.6.2"
eyre = "0.6.10"
tokio = { version = "1.35.0", features = ["full"] }
tracing = { version = "0.1.40", features = ["log"] }
tracing-subscriber = { version = "0.3.18", features = ["tracing"] }
uuid = { version = "1.6.1", features = ["v4"] }

94
crates/omnia/src/main.rs Normal file
View File

@@ -0,0 +1,94 @@
use cli::CliCommand;
use inbox::services::Inbox;
#[tokio::main]
async fn main() -> eyre::Result<()> {
tracing_subscriber::fmt().init();
if let Err(e) = color_eyre::install() {
tracing::error!("failed to install color_eyre: {}", e);
}
let cmd = clap::Command::new("omnia");
let inbox = Inbox::new();
let cmd = cmd.subcommand(inbox.get_command());
let matches = cmd.get_matches();
match matches.subcommand() {
Some((name, args)) => {
tracing::debug!("executing: {}", name);
if inbox.matches_command(name) {
inbox.execute_command(args).await?;
}
}
None => {
tracing::info!("executing raw command")
}
}
Ok(())
}
pub mod cli {
use clap::{ArgMatches, Command};
pub trait CliCommand {
fn get_name(&self) -> String;
fn get_command(&self) -> Command {
Command::new(self.get_name())
}
fn matches_command(&self, name: &str) -> bool {
name == self.get_name()
}
async fn execute_command(&self, args: &ArgMatches) -> eyre::Result<()>;
}
}
pub mod inbox {
pub mod cli {}
pub mod domain {
#[derive(Debug, Clone)]
pub struct InboxItem {
pub title: String,
pub description: Option<String>,
pub project: Option<String>,
}
}
pub mod services {
use crate::cli::CliCommand;
use super::domain::*;
pub struct Inbox {}
impl Inbox {
pub fn new() -> Self {
Self {}
}
pub async fn add_item(&self, inbox_item: InboxItem) -> eyre::Result<uuid::Uuid> {
Ok(uuid::Uuid::new_v4())
}
}
impl CliCommand for Inbox {
fn get_name(&self) -> String {
"inbox".to_string()
}
async fn execute_command(&self, args: &clap::ArgMatches) -> eyre::Result<()> {
self.add_item(InboxItem {
title: "something".into(),
description: Some("description".into()),
project: Some("project".into()),
})
.await?;
Ok(())
}
}
}
}