Skip to content

Commit

Permalink
feat: add file size for cloc
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Mar 4, 2021
1 parent 4584524 commit 6eaa473
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/app/analysis/cloc_analysis.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::domain::cloc::{ClocDetail, ClocLanguage};
use crate::infrastructure::cloc;
use std::path::PathBuf;
use std::error::Error;
use std::path::{Path, PathBuf};

pub fn analysis(path: PathBuf) -> Vec<ClocLanguage> {
let mut languages = vec![];
Expand All @@ -21,6 +22,7 @@ pub fn analysis(path: PathBuf) -> Vec<ClocLanguage> {
comments: report.stats.comments,
file_name,
path: strip_path.to_str().unwrap().to_string(),
bytes: file_size(strip_path).unwrap(),
});
}

Expand All @@ -36,6 +38,10 @@ pub fn analysis(path: PathBuf) -> Vec<ClocLanguage> {
return languages;
}

fn file_size(filename: &Path) -> Result<u64, Error> {
Ok(filename.metadata()?.len())
}

#[cfg(test)]
mod test {
use super::*;
Expand Down
8 changes: 8 additions & 0 deletions src/domain/cloc/cloc_language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,18 @@ impl Default for ClocLanguage {

#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
pub struct ClocDetail {
/// Total blank lines
pub blanks: usize,
/// Total number of lines within the file.
pub code: usize,
/// Number of comments within the file.
pub comments: usize,
/// File name
pub file_name: String,
/// really path
pub path: String,
/// File size in bytes
pub bytes: u64,
}

impl Default for ClocDetail {
Expand All @@ -38,6 +45,7 @@ impl Default for ClocDetail {
comments: 0,
file_name: "".to_string(),
path: "".to_string(),
bytes: 0,
}
}
}

0 comments on commit 6eaa473

Please sign in to comment.