Skip to content

Commit

Permalink
chore: test ci unit test automation (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
callicles authored Nov 4, 2023
1 parent eca9544 commit 62756ac
Show file tree
Hide file tree
Showing 33 changed files with 1,381 additions and 663 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/test-igloo-cli.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Test Igloo CLI
on:
push:
branches:
- "**"
- "!main"
paths:
- ".github/workflows/test-igloo-cli.yaml"
Expand Down Expand Up @@ -72,11 +73,11 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check --manifest-path ./apps/igloo-kit-cli/Cargo.toml
args: --manifest-path ./apps/igloo-kit-cli/Cargo.toml --all -- --check

- name: Run cargo clippy
uses: actions-rs/cargo@v1
continue-on-error: true # WARNING: only for this example, remove it!
with:
command: clippy
args: -- -D warnings --manifest-path ./apps/igloo-kit-cli/Cargo.toml
args: --manifest-path ./apps/igloo-kit-cli/Cargo.toml -- -D warnings
74 changes: 45 additions & 29 deletions apps/igloo-kit-cli/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
mod commands;
mod routines;
mod config;
mod watcher;
mod local_webserver;
mod display;
mod local_webserver;
mod routines;
mod watcher;

use std::sync::{RwLock, Arc};

use std::sync::{Arc, RwLock};

use self::{
commands::AddArgs,
display::{show_message, CommandTerminal, Message, MessageType},
routines::{
clean::CleanProject, initialize::InitializeProject, start::RunLocalInfratructure,
stop::StopLocalInfrastructure, validate::ValidateRedPandaCluster, RoutineController,
RunMode,
},
};
use crate::framework::{directories::get_igloo_directory, AddableObjects};
use clap::Parser;
use commands::Commands;
use config::{read_config, Config};
use clap::Parser;
use crate::framework::{AddableObjects, directories::get_igloo_directory};
use self::{commands::AddArgs, display::{MessageType, Message, show_message, CommandTerminal}, routines::{
initialize::InitializeProject, validate::ValidateRedPandaCluster, RoutineController, RunMode, start::RunLocalInfratructure, stop::StopLocalInfrastructure, clean::CleanProject}};

#[derive(Parser)]
#[command(author, version, about, long_about = None)]
Expand Down Expand Up @@ -59,18 +66,18 @@ fn add_handler(add_arg: &AddArgs) {
}
}




#[derive(PartialEq, Clone, Copy)]
pub enum DebugStatus {
Debug,
Silent,
}

async fn top_command_handler(term: Arc<RwLock<CommandTerminal>>, config: Config, commands: &Option<Commands>, debug: DebugStatus) {


async fn top_command_handler(
term: Arc<RwLock<CommandTerminal>>,
config: Config,
commands: &Option<Commands>,
debug: DebugStatus,
) {
if !config.features.coming_soon_wall {
match commands {
Some(Commands::Init {}) => {
Expand All @@ -79,36 +86,42 @@ async fn top_command_handler(term: Arc<RwLock<CommandTerminal>>, config: Config,
controller.add_routine(Box::new(InitializeProject::new(run_mode.clone())));
controller.run_routines(run_mode);
}
Some(Commands::Dev{}) => {
Some(Commands::Dev {}) => {
let mut controller = RoutineController::new();
let run_mode = RunMode::Explicit { term };
controller.add_routine(Box::new(RunLocalInfratructure::new(debug, config.clickhouse.clone(), config.redpanda.clone())));
controller.add_routine(Box::new(RunLocalInfratructure::new(
debug,
config.clickhouse.clone(),
config.redpanda.clone(),
)));
controller.add_routine(Box::new(ValidateRedPandaCluster::new(debug)));
controller.run_routines(run_mode);
let _ = routines::start_development_mode(config.clickhouse.clone(), config.redpanda.clone()).await;

let _ = routines::start_development_mode(
config.clickhouse.clone(),
config.redpanda.clone(),
)
.await;
}
Some(Commands::Update{}) => {
Some(Commands::Update {}) => {
// This command may not be needed if we have incredible automation
todo!("Will update the project's underlying infrascructure based on any added objects")
}
Some(Commands::Stop{}) => {
Some(Commands::Stop {}) => {
let mut controller = RoutineController::new();
let run_mode = RunMode::Explicit { term };
controller.add_routine(Box::new(StopLocalInfrastructure::new(run_mode.clone())));
controller.run_routines(run_mode);
}
Some(Commands::Clean{}) => {
Some(Commands::Clean {}) => {
let run_mode = RunMode::Explicit { term };
let igloo_dir = get_igloo_directory().expect("Nothing to clean, no .igloo directory found");
let igloo_dir =
get_igloo_directory().expect("Nothing to clean, no .igloo directory found");
let mut controller = RoutineController::new();
controller.add_routine(Box::new(CleanProject::new(igloo_dir,run_mode.clone())));
controller.add_routine(Box::new(CleanProject::new(igloo_dir, run_mode.clone())));
controller.run_routines(run_mode);


}
Some(Commands::Add(add_args)) => {
add_handler(add_args);
add_handler(add_args);
}
None => {}
}
Expand All @@ -118,14 +131,17 @@ async fn top_command_handler(term: Arc<RwLock<CommandTerminal>>, config: Config,
details: "Join the IglooKit community to stay up to date on the latest features: https://join.slack.com/t/igloocommunity/shared_invite/zt-25gsnx2x2-9ttVTt4L9LYFrRcM6jimcg".to_string(),
});
}

}

pub async fn cli_run() {
let term = Arc::new(RwLock::new(CommandTerminal::new()));
let config = read_config(term.clone());
let cli = Cli::parse();
let debug_status = if cli.debug { DebugStatus::Debug } else { DebugStatus::Silent };
let debug_status = if cli.debug {
DebugStatus::Debug
} else {
DebugStatus::Silent
};

top_command_handler(term.clone(), config, &cli.command, debug_status).await
}
16 changes: 5 additions & 11 deletions apps/igloo-kit-cli/src/cli/commands.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,29 @@
//! # CLI Commands
//! A module for all the commands that can be run from the CLI
use clap::{Args, Subcommand};
use clap::{Args, Subcommand};

use crate::framework;


#[derive(Subcommand)]
pub enum Commands {
// Initializes the developer environment with all the necessary directories including temporary ones for data storage
Init {},
// Adds a new templated object to the project
Add(AddArgs),
// Spins up development infrastructure including a redpanda cluster and clickhouse database
Dev{},
Dev {},
// Updates the redpanda cluster and clickhouse database with the latest objects
Update{},
Update {},
// Stops development infrastructure
Stop{},
Stop {},
// Clears all temporary data and stops development infrastructure
Clean{},
Clean {},
}




#[derive(Debug, Args)]
#[command()]
pub struct AddArgs {
#[command(subcommand)]
pub command: Option<framework::AddableObjects>,
}


50 changes: 26 additions & 24 deletions apps/igloo-kit-cli/src/cli/config.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
use crate::infrastructure::olap::clickhouse::config::ClickhouseConfig;
use crate::infrastructure::stream::redpanda::RedpandaConfig;
use home::home_dir;
use serde::Deserialize;
use std::fs;
use std::path::PathBuf;
use std::sync::{RwLock, Arc};
use home::home_dir;
use crate::infrastructure::olap::clickhouse::config::ClickhouseConfig;
use crate::infrastructure::stream::redpanda::RedpandaConfig;
use std::sync::{Arc, RwLock};

use super::CommandTerminal;
use super::display::{show_message, MessageType, Message};
use super::display::{show_message, Message, MessageType};
use super::local_webserver::LocalWebserverConfig;
use super::CommandTerminal;

/// # Config
/// Module to handle reading the config file from the user's home directory and configuring the CLI
///
///
/// ## Suggested Improvements
/// - add clickhouse and redpanda config to the config file
/// - add a config file option to the CLI
/// - add a config file generator to the CLI
/// - add a config file validation and error handling
///
///
const CONFIG_FILE: &str = ".igloo-config.toml";

Expand All @@ -36,7 +35,7 @@ pub struct Config {

#[derive(Deserialize, Debug)]
pub struct Features {
pub coming_soon_wall: bool
pub coming_soon_wall: bool,
}

fn config_path() -> PathBuf {
Expand All @@ -46,29 +45,32 @@ fn config_path() -> PathBuf {
}

fn default_config() -> Config {
Config {
features: Features { coming_soon_wall: true } ,
clickhouse: ClickhouseConfig::default(),
redpanda: RedpandaConfig::default(),
local_webserver: LocalWebserverConfig::default()
Config {
features: Features {
coming_soon_wall: true,
},
clickhouse: ClickhouseConfig::default(),
redpanda: RedpandaConfig::default(),
local_webserver: LocalWebserverConfig::default(),
}
}

pub fn read_config(term: Arc<RwLock<CommandTerminal>>) -> Config {
let config_file_location: PathBuf = config_path();
match config_file_location.try_exists() {
Ok(true) => {
show_message(term, MessageType::Info, Message {
action: "Loading Config".to_string(),
details: "Reading configuration from ~/.igloo-config.toml".to_string(),
});
show_message(
term,
MessageType::Info,
Message {
action: "Loading Config".to_string(),
details: "Reading configuration from ~/.igloo-config.toml".to_string(),
},
);
let contents: String = fs::read_to_string(config_file_location)
.expect("Something went wrong reading the config file ");
toml::from_str(&contents)
.expect("Something went wrong parsing the config file ")
}
_ => {
default_config()
toml::from_str(&contents).expect("Something went wrong parsing the config file ")
}
_ => default_config(),
}
}
Loading

0 comments on commit 62756ac

Please sign in to comment.