Set up initial structure for the nix builder.
This commit is contained in:
3
src/command/build/mod.rs
Normal file
3
src/command/build/mod.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
mod runner;
|
||||
|
||||
pub(crate) use runner::run_build;
|
||||
29
src/command/build/runner.rs
Normal file
29
src/command/build/runner.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
use crate::cli::parameters::BuildArgs;
|
||||
use crate::config::Config;
|
||||
use crate::config::TargetConfig;
|
||||
use crate::error::CustomError;
|
||||
|
||||
pub(crate) async fn run_build(args: BuildArgs) -> Result<(), CustomError> {
|
||||
println!("{:?}", args);
|
||||
let config = Config::load_from_file(args.config).await?;
|
||||
println!("{:?}", config);
|
||||
|
||||
for target_name in args.target {
|
||||
let target_config = {
|
||||
let target_config = config.get_target_config(&target_name)?;
|
||||
if let Some(conf) = target_config {
|
||||
conf
|
||||
} else {
|
||||
return Err(format!("Could not find target {}", target_name).into());
|
||||
}
|
||||
};
|
||||
|
||||
prepare_flake_repo(target_config).await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn prepare_flake_repo(target_config: &TargetConfig) -> Result<(), CustomError> {
|
||||
todo!()
|
||||
}
|
||||
3
src/command/daemon/mod.rs
Normal file
3
src/command/daemon/mod.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
mod runner;
|
||||
|
||||
pub(crate) use runner::start_daemon;
|
||||
23
src/command/daemon/runner.rs
Normal file
23
src/command/daemon/runner.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
use crate::cli::parameters::DaemonArgs;
|
||||
use crate::config::Config;
|
||||
use crate::error::CustomError;
|
||||
|
||||
pub(crate) async fn start_daemon(args: DaemonArgs) -> Result<(), CustomError> {
|
||||
if args.path.exists() && !args.path.is_dir() {
|
||||
return Err("The supplied path exists but is not a directory. Aborting.".into());
|
||||
}
|
||||
|
||||
if !args.path.exists() {
|
||||
tokio::fs::create_dir_all(&args.path).await?;
|
||||
}
|
||||
|
||||
let mut existing_entries = tokio::fs::read_dir(&args.path).await?;
|
||||
let first_entry = existing_entries.next_entry().await?;
|
||||
if first_entry.is_some() {
|
||||
return Err("The directory is not empty. Aborting.".into());
|
||||
}
|
||||
|
||||
let new_config = Config::new(args.path)?;
|
||||
new_config.write_to_disk().await?;
|
||||
Ok(())
|
||||
}
|
||||
2
src/command/mod.rs
Normal file
2
src/command/mod.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
pub(crate) mod build;
|
||||
pub(crate) mod daemon;
|
||||
Reference in New Issue
Block a user