diff --git a/Cargo.toml b/Cargo.toml index b48b69e..715dc56 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,3 @@ [workspace] -members = [ "src/api","src/vmm"] +members = [ "src/api","src/vmm", "src/cli"] resolver = "2" diff --git a/src/cli/Cargo.toml b/src/cli/Cargo.toml new file mode 100644 index 0000000..b42f5c8 --- /dev/null +++ b/src/cli/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "cli" +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.5.3", features = ["derive"] } +toml = "0.8.12" +tokio = { version = "1.36.0", features = ["full"] } +serde = { version = "1.0.197", features = ["derive"] } +serde_yaml = "0.9.34" +schemars = "0.8.16" +serde_json = "1.0.115" diff --git a/src/cli/config/config.template.yaml b/src/cli/config/config.template.yaml new file mode 100644 index 0000000..bdadbb4 --- /dev/null +++ b/src/cli/config/config.template.yaml @@ -0,0 +1,4 @@ +language: rust +env_path: .env +code_path: src +log_level: debug diff --git a/src/cli/src/main.rs b/src/cli/src/main.rs new file mode 100644 index 0000000..3e4ada0 --- /dev/null +++ b/src/cli/src/main.rs @@ -0,0 +1,71 @@ +use clap::Parser; +mod types; +mod utils; +use std::io::{self}; +use types::{Config, Language, LogLevel}; +use utils::load_config; + +#[derive(Parser, Debug)] +#[command(version, about, long_about = None)] +struct Args { + #[command(subcommand)] + command: Commands, +} + +#[derive(Parser, Debug)] +enum Commands { + Configure { + #[arg(short, long)] + config_path: String, + }, + Status {}, + Apply {}, + Kill {}, +} + +#[tokio::main] + +async fn main() -> io::Result<()> { + let args = Args::parse(); + + match args.command { + Commands::Configure { config_path } => { + let config: Config = load_config(&config_path).unwrap(); + + println!("Configuration from YAML file:"); + println!( + "Language: {}", + match config.language { + Language::Rust => "Rust", + Language::Python => "Python", + Language::Node => "Node", + } + ); + println!("Env Path: {}", config.env_path); + println!("Code Path: {}", config.code_path); + println!( + "Log Level: {}", + match config.log_level { + LogLevel::Debug => "Debug", + LogLevel::Info => "Info", + LogLevel::Warn => "Warn", + LogLevel::Error => "Error", + } + ); + } + + Commands::Status {} => { + println!("Getting status"); + } + + Commands::Apply {} => { + println!("Applying configuration"); + } + + Commands::Kill {} => { + println!("Killing configuration"); + } + } + + Ok(()) +} diff --git a/src/cli/src/types.rs b/src/cli/src/types.rs new file mode 100644 index 0000000..02f9e02 --- /dev/null +++ b/src/cli/src/types.rs @@ -0,0 +1,27 @@ +use clap::ValueEnum; +use serde::Deserialize; + +#[derive(Clone, Debug, ValueEnum, Deserialize)] +#[serde(rename_all = "lowercase")] +pub enum Language { + Rust, + Python, + Node, +} + +#[derive(Clone, Debug, ValueEnum, Deserialize)] +#[serde(rename_all = "lowercase")] +pub enum LogLevel { + Debug, + Info, + Warn, + Error, +} + +#[derive(Deserialize, Debug)] +pub struct Config { + pub language: Language, + pub env_path: String, + pub code_path: String, + pub log_level: LogLevel, +} diff --git a/src/cli/src/utils.rs b/src/cli/src/utils.rs new file mode 100644 index 0000000..e970e6f --- /dev/null +++ b/src/cli/src/utils.rs @@ -0,0 +1,11 @@ +use crate::types::Config; +use std::fs::File; +use std::io::{self, Read}; + +pub fn load_config(config_path: &str) -> io::Result { + let mut file = File::open(config_path)?; + let mut contents = String::new(); + file.read_to_string(&mut contents)?; + let config: Config = serde_yaml::from_str(&contents).unwrap(); + Ok(config) +}