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; use crate::config::Config;
#[derive(Default)]
pub struct Compiler { pub struct Compiler {
config: Config, config: Config,
path: String, path: String,

View File

@@ -1,18 +1,18 @@
use serde::Deserialize; use serde::Deserialize;
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize, Default)]
pub struct Config { pub struct Config {
pub general: General, pub general: General,
pub build: Build, pub build: Build,
} }
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize, Default)]
pub struct General { pub struct General {
pub target: String, pub target: String,
pub main: String, pub main: String,
} }
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize, Default)]
pub struct Build { pub struct Build {
pub build_dir: String, pub build_dir: String,
pub cc: 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 compiler;
pub mod config; pub mod config;
pub mod init;

View File

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