Skip to main content

b2c2_flag/
lib.rs

1// b2c2-flag crate
2// author: Leonardone @ NEETSDKASU
3
4use b2c2_compiler as compiler;
5use std::fs;
6use std::io;
7use std::path::{Path, PathBuf};
8
9#[derive(Clone, Default)]
10pub struct Flags {
11    pub src_file: Option<String>,
12    pub compiler: compiler::Flag,
13    pub statistics: bool,
14    pub dst_dir: Option<String>,
15    pub run_debugger: Option<DebugTarget>,
16}
17
18#[derive(Clone, Copy)]
19pub enum DebugTarget {
20    Casl2,
21    Basic,
22    NonStep,
23}
24
25impl Flags {
26    // 出力先ディレクトリの生成
27    pub fn create_dst_dir(&self) -> io::Result<PathBuf> {
28        if let Some(dir) = self.dst_dir.as_ref() {
29            let path = Path::new(dir);
30            if !path.exists() || !path.is_dir() {
31                fs::create_dir_all(dir)?;
32            }
33            Ok(path.to_path_buf())
34        } else {
35            Ok(PathBuf::new())
36        }
37    }
38}