started to make boat init
This commit is contained in:
@@ -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,
|
||||||
|
|||||||
@@ -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
7
src/init.rs
Normal 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();
|
||||||
|
}
|
||||||
@@ -1,2 +1,3 @@
|
|||||||
pub mod compiler;
|
pub mod compiler;
|
||||||
pub mod config;
|
pub mod config;
|
||||||
|
pub mod init;
|
||||||
|
|||||||
18
src/main.rs
18
src/main.rs
@@ -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,6 +54,11 @@ pub struct Args {
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = Args::parse();
|
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 conf_path = path::Path::new(args.path.as_str()).join("c_config.toml");
|
||||||
|
|
||||||
let contents = fs::read_to_string(conf_path.clone())
|
let contents = fs::read_to_string(conf_path.clone())
|
||||||
@@ -61,11 +68,13 @@ fn main() {
|
|||||||
|
|
||||||
// println!("{:?}", config);
|
// 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);
|
// 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 {
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user