Skip to content

Commit

Permalink
[esrlabs#1966] Basic skeleton with Componets and Commands
Browse files Browse the repository at this point in the history
  • Loading branch information
sergio-bobillier committed Jan 12, 2024
1 parent 28fb012 commit 43aca49
Show file tree
Hide file tree
Showing 9 changed files with 455 additions and 1 deletion.
286 changes: 286 additions & 0 deletions build-cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions build-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ 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 = ["derive"] }
termion = "2.0.3"
23 changes: 23 additions & 0 deletions build-cli/src/commands/clean/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use crate::components::cleanable;
use crate::errors::BuildError;
use cleanable::Cleanable;

use super::Command;

pub struct Clean {
component: Cleanable
}

impl Clean {
pub fn new(component_name: String) -> Result<Self, BuildError> {
let component = cleanable::Cleanable::new(component_name)?;
Ok(Self { component })
}
}

impl Command for Clean {
fn run(&self) {
// Clean the component
self.component.clean();
}
}
7 changes: 7 additions & 0 deletions build-cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
mod clean;

pub use clean::Clean;

pub trait Command {
fn run(&self);
}
21 changes: 21 additions & 0 deletions build-cli/src/components/bindings.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use super::Component;

const COMPONENT_NAME:&str = "Bindings";

pub struct Bindings {}

impl Bindings {
pub fn clean(&self) {
// Bindings knows how to clear itself
}
}

impl Component for Bindings {
fn new() -> Self {
Self {}
}

fn name(&self) -> &str {
COMPONENT_NAME
}
}
29 changes: 29 additions & 0 deletions build-cli/src/components/cleanable.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use crate::errors::{BuildError, BuildErrorTypes};

use super::Component;
use super::bindings::Bindings;

pub enum Cleanable {
Bindings(Bindings)
}

impl Cleanable {
pub fn new(component_name: String) -> Result<Cleanable, BuildError> {
match component_name.as_str() {
"bindings" => Ok(Cleanable::Bindings(Bindings::new())),
_ => Err(BuildError::new(BuildErrorTypes::UnknownComponent(component_name)))
}
}

pub fn name(&self) -> &str {
match self {
Cleanable::Bindings(bindings) => { bindings.name() }
}
}

pub fn clean(&self) {
match self {
Cleanable::Bindings(bindings) => { bindings.clean() }
}
}
}
8 changes: 8 additions & 0 deletions build-cli/src/components/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
mod bindings;

pub mod cleanable;

trait Component {
fn new() -> Self;
fn name(&self) -> &str;
}
Loading

0 comments on commit 43aca49

Please sign in to comment.