Compare commits
2 Commits
5fbae8abd6
...
experiment
| Author | SHA1 | Date | |
|---|---|---|---|
|
0ca86560bf
|
|||
|
50e4d5a879
|
21
Cargo.lock
generated
21
Cargo.lock
generated
@@ -62,10 +62,6 @@ version = "1.0.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "char"
|
|
||||||
version = "0.1.0"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "char_cli"
|
name = "char_cli"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
@@ -82,12 +78,27 @@ dependencies = [
|
|||||||
name = "char_plan"
|
name = "char_plan"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"char",
|
"char_sdk",
|
||||||
|
"char_sdk_derive",
|
||||||
|
"eyre",
|
||||||
|
"tokio",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "char_sdk"
|
name = "char_sdk"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"clap",
|
||||||
|
"eyre",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "char_sdk_derive"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap"
|
name = "clap"
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ members = [
|
|||||||
"examples/service/char_plan",
|
"examples/service/char_plan",
|
||||||
"crates/char_cli",
|
"crates/char_cli",
|
||||||
"crates/char_sdk",
|
"crates/char_sdk",
|
||||||
"crates/char",
|
"crates/char_sdk_derive",
|
||||||
]
|
]
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
|
|||||||
@@ -6,3 +6,5 @@ edition = "2021"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
eyre = { workspace = true }
|
||||||
|
clap = "4.1.6"
|
||||||
|
|||||||
@@ -1,14 +1,53 @@
|
|||||||
pub fn add(left: usize, right: usize) -> usize {
|
pub mod std;
|
||||||
left + right
|
|
||||||
|
pub enum ActionArg<'a> {
|
||||||
|
Required { name: &'a str, description: &'a str },
|
||||||
|
Optional { name: &'a str, description: &'a str },
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
pub struct InputArg<'a> {
|
||||||
mod tests {
|
name: &'a str,
|
||||||
use super::*;
|
value: &'a str,
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
pub struct ActionArgs<'a> {
|
||||||
fn it_works() {
|
pub name: &'a str,
|
||||||
let result = add(2, 2);
|
pub args: Vec<ActionArg<'a>>,
|
||||||
assert_eq!(result, 4);
|
}
|
||||||
|
|
||||||
|
pub trait Action {
|
||||||
|
fn action<'a>(&self) -> ActionArgs<'a>;
|
||||||
|
fn execute(&self, args: &[&InputArg]) -> eyre::Result<()>;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait Plugin {}
|
||||||
|
|
||||||
|
pub struct CharBuilder {
|
||||||
|
actions: Vec<Box<dyn Action>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CharBuilder {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
CharBuilder {
|
||||||
|
actions: Vec::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add_context<C>(mut self, context: C) -> Self {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add_action(mut self, action: impl Into<Box<dyn Action>>) -> Self {
|
||||||
|
self.actions.push(action.into());
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add_plugin(mut self, plugin: impl Plugin) -> Self {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn execute(mut self) -> eyre::Result<()> {
|
||||||
|
//clap::Command::new("").arg(a)
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
9
crates/char_sdk/src/std/dagger/mod.rs
Normal file
9
crates/char_sdk/src/std/dagger/mod.rs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
pub struct Plugin {}
|
||||||
|
|
||||||
|
impl crate::Plugin for Plugin {}
|
||||||
|
|
||||||
|
impl Default for Plugin {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {}
|
||||||
|
}
|
||||||
|
}
|
||||||
9
crates/char_sdk/src/std/k8s/mod.rs
Normal file
9
crates/char_sdk/src/std/k8s/mod.rs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
pub struct Plugin {}
|
||||||
|
|
||||||
|
impl crate::Plugin for Plugin {}
|
||||||
|
|
||||||
|
impl Default for Plugin {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {}
|
||||||
|
}
|
||||||
|
}
|
||||||
2
crates/char_sdk/src/std/mod.rs
Normal file
2
crates/char_sdk/src/std/mod.rs
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
pub mod dagger;
|
||||||
|
pub mod k8s;
|
||||||
@@ -1,8 +1,12 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "char"
|
name = "char_sdk_derive"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
syn = "1.0.107"
|
||||||
|
quote = "1.0.23"
|
||||||
|
[lib]
|
||||||
|
proc-macro = true
|
||||||
24
crates/char_sdk_derive/src/lib.rs
Normal file
24
crates/char_sdk_derive/src/lib.rs
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
extern crate proc_macro;
|
||||||
|
|
||||||
|
use proc_macro::TokenStream;
|
||||||
|
use quote::quote;
|
||||||
|
|
||||||
|
#[proc_macro_derive(CharAction)]
|
||||||
|
pub fn derive_char_action_into_box(input: TokenStream) -> TokenStream {
|
||||||
|
let ast = syn::parse(input).unwrap();
|
||||||
|
|
||||||
|
// Build the trait implementation
|
||||||
|
impl_hello_macro(&ast)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn impl_hello_macro(ast: &syn::DeriveInput) -> TokenStream {
|
||||||
|
let name = &ast.ident;
|
||||||
|
let gen = quote! {
|
||||||
|
impl Into<Box<dyn char_sdk::Action>> for #name {
|
||||||
|
fn into(self) -> Box<dyn char_sdk::Action> {
|
||||||
|
Box::new(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
gen.into()
|
||||||
|
}
|
||||||
@@ -6,4 +6,8 @@ edition = "2021"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
char = { path = "../../../crates/char" }
|
char_sdk = { path = "../../../crates/char_sdk" }
|
||||||
|
char_sdk_derive = { path = "../../../crates/char_sdk_derive" }
|
||||||
|
|
||||||
|
eyre = { workspace = true }
|
||||||
|
tokio = { workspace = true }
|
||||||
|
|||||||
@@ -1,14 +1,43 @@
|
|||||||
struct Run;
|
use char_sdk_derive::CharAction;
|
||||||
impl char::Action for Run {}
|
|
||||||
|
|
||||||
|
#[derive(CharAction)]
|
||||||
|
struct Run;
|
||||||
|
|
||||||
|
impl char_sdk::Action for Run {
|
||||||
|
fn action<'a>(&self) -> char_sdk::ActionArgs<'a> {
|
||||||
|
char_sdk::ActionArgs {
|
||||||
|
name: "run",
|
||||||
|
args: vec![char_sdk::ActionArg::Required {
|
||||||
|
name: "profile",
|
||||||
|
description: "which release profile to use, takes ['release', 'test']",
|
||||||
|
}],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn execute(&self, args: &[&char_sdk::InputArg]) -> eyre::Result<()> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(CharAction)]
|
||||||
struct Build;
|
struct Build;
|
||||||
impl char::Action for Build {}
|
|
||||||
|
impl char_sdk::Action for Build {
|
||||||
|
fn action<'a>(&self) -> char_sdk::ActionArgs<'a> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn execute(&self, args: &[&char_sdk::InputArg]) -> eyre::Result<()> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
char::new()
|
char_sdk::CharBuilder::new()
|
||||||
.add_context(char::dagger::Context::default())
|
|
||||||
.add_action(Run {})
|
.add_action(Run {})
|
||||||
.add_action(Build {})
|
.add_action(Build {})
|
||||||
.add_plugin(char::std::k8s::Context::default())
|
.add_plugin(char_sdk::std::dagger::Plugin::default())
|
||||||
.execute();
|
.add_plugin(char_sdk::std::k8s::Plugin::default())
|
||||||
|
.execute()
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user