Skip to content

Commit

Permalink
feat(cli): Add duration timer to main runner
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed Mar 12, 2024
1 parent facc741 commit 004fcae
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion assets/en-US/cli.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ welcome =
Welcome to CaSILE { $version }!
outro =
CaSILE run complete
CaSILE run completed in { $duration }
make-header =
Building target(s) using ‘make’
Expand Down
2 changes: 1 addition & 1 deletion assets/tr-TR/cli.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ welcome =
CaSILE { $version } sürümüne hoş geldiniz!
outro =
CaSILE çalışması tamamlandı
CaSILE çalışması { $duration } içinde tamamlandı
run-header =
CaSILE ortamı içinde komut dosyası çalıştırılıyor
Expand Down
9 changes: 5 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ use crate::config::CONF;
use console::{style, StyledObject};
use git2::{Oid, Repository, Signature};
use i18n::LocalText;
use indicatif::{ProgressBar, ProgressStyle};
use indicatif::{HumanDuration, ProgressBar, ProgressStyle};
use regex::Regex;
use std::ffi::OsStr;
use std::{error, fmt, path, result, str};
use std::{error, fmt, path, result, str, time::Duration};

pub mod cli;
pub mod config;
Expand Down Expand Up @@ -109,8 +109,9 @@ pub fn show_welcome() {
}

/// Output welcome header at start of run before moving on to actual commands
pub fn show_outro() {
let outro = LocalText::new("outro").fmt();
pub fn show_outro(elapsed: Duration) {
let time = HumanDuration(elapsed);
let outro = LocalText::new("outro").arg("duration", time).fmt();
ProgressBar::new_spinner()
.with_style(ProgressStyle::with_template("{msg}").unwrap())
.finish_with_message(style(outro).cyan().to_string());
Expand Down
5 changes: 4 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ use casile::config::CONF;
use casile::{make, run, setup, status};
use casile::{Result, VERSION};

use std::time::Instant;

fn main() -> Result<()> {
let started = Instant::now();
CONF.defaults()?;
CONF.merge_env()?;
CONF.merge_files()?;
Expand All @@ -22,6 +25,6 @@ fn main() -> Result<()> {
Commands::Setup {} => setup::run(),
Commands::Status {} => status::run(),
};
casile::show_outro();
casile::show_outro(started.elapsed());
ret
}

0 comments on commit 004fcae

Please sign in to comment.