started to make boat init

This commit is contained in:
Guilleag01
2025-02-20 22:01:01 +01:00
parent f1fc5d3c60
commit 1a2bd851fe
5 changed files with 33 additions and 12 deletions

View File

@@ -5,6 +5,7 @@ use std::{collections::HashSet, fs, path};
use crate::config::Config;
#[derive(Default)]
pub struct Compiler {
config: Config,
path: String,

View File

@@ -1,18 +1,18 @@
use serde::Deserialize;
#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Default)]
pub struct Config {
pub general: General,
pub build: Build,
}
#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Default)]
pub struct General {
pub target: String,
pub main: String,
}
#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Default)]
pub struct Build {
pub build_dir: String,
pub cc: String,

7
src/init.rs Normal file
View File

@@ -0,0 +1,7 @@
use std::{fs, path};
pub fn init(path: String) {
println!("Creating {}", path);
fs::create_dir(path.clone()).unwrap();
fs::create_dir(path::Path::new(&path).join("src")).unwrap();
}

View File

@@ -1,2 +1,3 @@
pub mod compiler;
pub mod config;
pub mod init;

View File

@@ -4,7 +4,7 @@ use std::{
path::{self, Path},
};
use boat::{compiler::Compiler, config::Config};
use boat::{compiler::Compiler, config::Config, init};
use clap::Parser;
#[derive(clap::ValueEnum, Clone, Debug)]
@@ -12,6 +12,7 @@ enum Modes {
Build,
Clean,
Run,
Init,
}
impl Display for Modes {
@@ -20,6 +21,7 @@ impl Display for Modes {
Modes::Build => f.write_str("build"), // "build".to_string(),
Modes::Clean => f.write_str("clean"),
Modes::Run => f.write_str("run"),
Modes::Init => f.write_str("init"),
}
}
}
@@ -52,6 +54,11 @@ pub struct Args {
fn main() {
let args = Args::parse();
let mut compiler = Compiler::default();
if let Modes::Init = args.mode {
} else {
let conf_path = path::Path::new(args.path.as_str()).join("c_config.toml");
let contents = fs::read_to_string(conf_path.clone())
@@ -61,11 +68,13 @@ fn main() {
// println!("{:?}", config);
let (src_files, header_files) = get_file_list(&args.path).expect("Error while readig files");
let (src_files, header_files) =
get_file_list(&args.path).expect("Error while readig files");
// println!("{:?}, {:?}", src_files, header_files);
let mut compiler = Compiler::new(config, args.path, src_files, header_files);
compiler = Compiler::new(config, args.path.clone(), src_files, header_files);
}
match args.mode {
Modes::Build => {
@@ -78,6 +87,9 @@ fn main() {
compiler.compile(args.verbose);
compiler.run();
}
Modes::Init => {
init::init(args.path);
}
}
}