Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

specify path to the spec files #118

Merged
merged 3 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ pub struct Extract {

impl Extract {
pub fn exec(&self) -> Result<(), Error> {
let contents = self.target.load()?;
let contents = self.target.load(None)?;
toidiu marked this conversation as resolved.
Show resolved Hide resolved
let spec = self.format.parse(&contents)?;
let sections = extract_sections(&spec);
let local_path = self.target.local();
let local_path = self.target.local(None);

if self.out.extension().is_some() {
// assume a path with an extension is a single file
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ fn main() {
}
}

#[allow(clippy::large_enum_variant)]
#[derive(Debug, StructOpt)]
enum Arguments {
Extract(extract::Extract),
Expand Down
8 changes: 8 additions & 0 deletions src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ pub struct Project {
/// Glob patterns for spec files
#[structopt(long = "spec-pattern")]
spec_patterns: Vec<String>,

/// Path to store the collection of spec files
///
/// The spec files are stored in a folder called `specs`. This folder is
/// stored at the root of the project by default. Use this argument to
/// specify a different location.
#[structopt(long = "spec-download-path", default_value = ".")]
pub spec_download_path: String,
toidiu marked this conversation as resolved.
Show resolved Hide resolved
}

impl Project {
Expand Down
7 changes: 2 additions & 5 deletions src/report/lcov.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ pub fn report(report: &ReportResult, dir: &Path) -> Result<(), Error> {
}

#[allow(clippy::cognitive_complexity)]
pub fn report_source<Output: Write>(
report: &TargetReport,
output: &mut Output,
) -> Result<(), Error> {
fn report_source<Output: Write>(report: &TargetReport, output: &mut Output) -> Result<(), Error> {
macro_rules! put {
($($arg:expr),* $(,)?) => {
writeln!(output $(, $arg)*)?;
Expand All @@ -73,7 +70,7 @@ pub fn report_source<Output: Write>(

put!("TN:Compliance");
let relative =
pathdiff::diff_paths(report.target.path.local(), std::env::current_dir()?).unwrap();
pathdiff::diff_paths(report.target.path.local(None), std::env::current_dir()?).unwrap();
put!("SF:{}", relative.display());

// record all sections
Expand Down
5 changes: 4 additions & 1 deletion src/report/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ impl Report {
let contents: HashMap<_, _> = targets
.par_iter()
.map(|target| {
let contents = target.path.load().unwrap();
let contents = target
.path
.load(Some(&self.project.spec_download_path))
.unwrap();
(target, contents)
})
.collect();
Expand Down
9 changes: 6 additions & 3 deletions src/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ impl TargetPath {
Ok(Self::Path(path))
}

pub fn load(&self) -> Result<String, Error> {
pub fn load(&self, spec_download_path: Option<&String>) -> Result<String, Error> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub fn load(&self, spec_download_path: Option<&String>) -> Result<String, Error> {
pub fn load(&self, spec_path: Option<&str>) -> Result<String, Error> {

let mut contents = match self {
Self::Url(url) => {
let path = self.local();
let path = self.local(spec_download_path);
if !path.exists() {
std::fs::create_dir_all(path.parent().unwrap())?;

Expand Down Expand Up @@ -103,10 +103,13 @@ impl TargetPath {
Ok(contents)
}

pub fn local(&self) -> PathBuf {
pub fn local(&self, spec_download_path: Option<&String>) -> PathBuf {
toidiu marked this conversation as resolved.
Show resolved Hide resolved
match self {
Self::Url(url) => {
let mut path = std::env::current_dir().unwrap();
if let Some(path_to_spec) = spec_download_path {
path.push(path_to_spec);
}
toidiu marked this conversation as resolved.
Show resolved Hide resolved
path.push("specs");
path.push(url.host_str().expect("url should have host"));
path.extend(url.path_segments().expect("url should have path"));
Expand Down
Loading