Skip to content

Commit

Permalink
make sure relative input dirs get normalized
Browse files Browse the repository at this point in the history
  • Loading branch information
HJfod committed Jan 27, 2023
1 parent 617d3e0 commit fc17b63
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "flash"
version = "0.1.2"
version = "0.1.3"
edition = "2021"
authors = ["HJfod"]
description = "Documentation generator for C++"
Expand Down
2 changes: 1 addition & 1 deletion src/cmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,5 @@ pub fn cmake_compile_args_for(config: Arc<Config>) -> Result<Vec<String>, String
return Ok(cmd.get_command_list(config));
}
}
Err(format!("Unable to find compile args for '{}'", from.to_string_lossy()))
Err(format!("Unable to find compile args for '{}'", config.input_dir.join(from).to_string_lossy()))
}
6 changes: 3 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use glob::glob;
use serde::{Deserialize, Deserializer};
use std::{fs, path::PathBuf, sync::Arc};

use crate::url::UrlPath;
use crate::{url::UrlPath, normalize::Normalize};

fn parse_template<'de, D>(deserializer: D) -> Result<Arc<String>, D::Error>
where
Expand Down Expand Up @@ -161,8 +161,8 @@ impl Config {
)
.map_err(|e| format!("Unable to parse config: {e}"))?;

config.input_dir = input_dir;
config.output_dir = output_dir;
config.input_dir = input_dir.normalize();
config.output_dir = output_dir.normalize();
config.output_url = output_url;
Ok(Arc::from(config))
}
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ mod cmake;
mod config;
mod html;
mod url;
mod normalize;

#[derive(Parser, Debug)]
struct Args {
Expand Down
21 changes: 21 additions & 0 deletions src/normalize.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

use std::path::{PathBuf, Component};

pub trait Normalize {
fn normalize(&self) -> Self;
}

impl Normalize for PathBuf {
fn normalize(&self) -> Self {
let mut res = Self::new();
for comp in self.components() {
if comp == Component::ParentDir {
res.pop();
}
else {
res.push(comp);
}
}
res
}
}
1 change: 0 additions & 1 deletion src/url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ impl TryFrom<&str> for UrlPath {

impl TryFrom<String> for UrlPath {
type Error = String;

fn try_from(value: String) -> Result<Self, Self::Error> {
UrlPath::parse(&value)
}
Expand Down

0 comments on commit fc17b63

Please sign in to comment.