Skip to content

Commit

Permalink
Merge pull request #61 from bojan88/project_creation_date
Browse files Browse the repository at this point in the history
Project creation date
  • Loading branch information
o2sh authored Oct 10, 2019
2 parents 6a73ae1 + 8f22ff5 commit 7b31ed5
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ fn count_newlines(s: &str) -> usize {
/// escape characters for color display.
///
/// Colors are specified with {0}, {1}... where the number represents
/// the nth element in the colors Vec provided to the function.
/// the nth element in the colors Vec provided to the function.
/// If there are more colors in the ascii than in the Vec it
/// defaults to white.
/// defaults to white.
/// The usize in the tuple refers to the extra padding needed
/// which comes from the added escape characters.
fn colorize_str(line: &str, colors: Vec<Color>) -> (String, usize) {
Expand Down Expand Up @@ -363,9 +363,13 @@ fn main() -> Result<()> {
let commits = get_commits(&dir)?;
let repo_size = get_packed_size(&dir)?;
let last_change = get_last_change(&dir)?;
let project_name = match get_creation_time() {
Some(creation_time) => format!("{}, {}", config.repository_name, creation_time),
None => config.repository_name
};

let info = Info {
project_name: config.repository_name,
project_name,
current_commit: current_commit_info,
version,
dominant_language,
Expand Down Expand Up @@ -521,7 +525,7 @@ fn get_packed_size(dir: &str) -> Result<String> {
None => "??",
Some(size_str) => &(size_str[11..])
};

let output = Command::new("git")
.arg("-C")
.arg(dir)
Expand All @@ -547,7 +551,7 @@ fn get_packed_size(dir: &str) -> Result<String> {
else{
let res =repo_size;
Ok(res.into())
}
}
}

fn is_git_installed() -> bool {
Expand Down Expand Up @@ -674,6 +678,23 @@ fn get_total_loc(languages: &tokei::Languages) -> usize {
.fold(0, |sum, val| sum + val.code)
}

fn get_creation_time() -> Option<String> {
let output = Command::new("git")
.arg("log")
.arg("--reverse")
.arg("--pretty=oneline")
.arg("--format=\"%ar\"")
.output()
.expect("Failed to execute git.");

let output = String::from_utf8_lossy(&output.stdout);

match output.lines().next() {
Some(val) => Some(val.to_string().replace('"', "")),
None => None
}
}

/// Convert from tokei LanguageType to known Language type .
impl From<tokei::LanguageType> for Language {
fn from(language: tokei::LanguageType) -> Self {
Expand Down

0 comments on commit 7b31ed5

Please sign in to comment.