use std::path::{Path, PathBuf};
use serde::Deserialize;
use tracing::error;
use crate::{
bsc::{self, args::BscArgs},
util::path::maybe_canonicalize,
};
#[derive(Deserialize)]
pub struct Entry {
directory: PathBuf,
arguments: Option<Vec<String>>,
command: Option<String>,
file: Option<PathBuf>,
}
impl Entry {
pub fn parse(self, project_root: &Path) -> Option<BscArgs> {
let args = if let Some(arguments) = self.arguments {
arguments
} else if let Some(command) = self.command {
bsc::args::tokenize(&command)
} else {
error!("entry has no 'arguments' or 'command'");
return None;
};
let mut args = bsc::args::parse_compdb(
args.into_iter(),
maybe_canonicalize(&project_root.join(&self.directory)),
)?;
if args.file.is_none() {
args.file = self
.file
.map(|f| maybe_canonicalize(&self.directory.join(f)))
}
Some(args)
}
}