Skip to content

Commit

Permalink
chore: add progress bar for cli
Browse files Browse the repository at this point in the history
  • Loading branch information
wtlin1228 committed Oct 11, 2024
1 parent 06cc895 commit f83c981
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 11 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ swc_core = { version = "0.104.2", features = ["common", "ecma_ast", "ecma
swc_ecma_parser = { version = "0.150.0", features = ["typescript"] }
clap = { version = "4.5", features = ["derive"] }
rusqlite = { version = "0.32.1", features = ["bundled"] }
indicatif = "0.17.8"
2 changes: 2 additions & 0 deletions crates/api_server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ struct Info {
exact_match: bool,
}

// Current implementation is mimick version of the trace with in-memory graph.
// We can refactor it after the database feature gets validated.
#[get("/search")]
async fn search(
data: web::Data<AppState>,
Expand Down
1 change: 1 addition & 0 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ version = "0.1.0"
anyhow = { workspace = true }
clap = { workspace = true }
serde_json = { workspace = true }
indicatif = { workspace = true }

dt_core = { version = "0.1.0", path = "../dt_core" }
14 changes: 12 additions & 2 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use dt_core::{
route::{collect_route_dependency, Route, SymbolToRoutes},
scheduler::ParserCandidateScheduler,
};
use indicatif::{ProgressBar, ProgressStyle};
use std::{
collections::{HashMap, HashSet},
fs::File,
Expand Down Expand Up @@ -156,6 +157,13 @@ fn parse_and_export_project_to_database(
.context("add translation to project")?;

let mut scheduler = ParserCandidateScheduler::new(&project_root);
let bar = ProgressBar::new(scheduler.get_total_remaining_candidate_count() as u64);
bar.set_style(
ProgressStyle::with_template(
"[{elapsed_precise}] {bar:40.cyan/blue} {pos:>7}/{len:7} {msg}",
)?
.progress_chars("##-"),
);
loop {
match scheduler.get_one_candidate() {
Some(c) => {
Expand Down Expand Up @@ -198,11 +206,12 @@ fn parse_and_export_project_to_database(
))?;

scheduler.mark_candidate_as_parsed(c);
bar.inc(1);
}
None => break,
}
}

bar.finish_with_message("all modules parsed 🌲");
Ok(())
}

Expand Down Expand Up @@ -562,7 +571,8 @@ impl Project {
))?;
}
Err(_) => {
println!("try to add translation for symbol {}, but translation {} doesn't exist", symbol_name, key);
// you can uncomment this to debug
// println!("try to add translation for symbol {}, but translation {} doesn't exist", symbol_name, key);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/demo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ version = "0.1.0"


[dependencies]
anyhow = { workspace = true }
clap = { workspace = true }
anyhow = { workspace = true }
clap = { workspace = true }
indicatif = { workspace = true }

umya-spreadsheet = "1.2.3"
dialoguer = { version = "0.11.0", features = ["history"] }
indicatif = "0.17.8"
console = "0.15.8"
rand = "0.8.5"

Expand Down
10 changes: 4 additions & 6 deletions crates/demo/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
use anyhow::Context;
use clap::Parser;
use console::style;
use dialoguer::{theme::ColorfulTheme, BasicHistory, Confirm, Input, Select};
use indicatif::{ProgressBar, ProgressStyle};
use rand::distributions::Alphanumeric;
use rand::{thread_rng, Rng};
use std::path::PathBuf;

use demo::spreadsheet::write_to_spreadsheet;
use dialoguer::{theme::ColorfulTheme, BasicHistory, Confirm, Input, Select};
use dt_core::{
graph::{depend_on_graph::DependOnGraph, used_by_graph::UsedByGraph},
parser::{collect_symbol_dependency, Input as ModuleInput},
path_resolver::{PathResolver, ToCanonicalString},
scheduler::ParserCandidateScheduler,
tracker::{DependencyTracker, TraceTarget},
};
use indicatif::{ProgressBar, ProgressStyle};
use rand::{distributions::Alphanumeric, thread_rng, Rng};
use std::path::PathBuf;

const SYMBOL_TYPE_SELECTIONS: [&str; 3] = ["Default Export", "Named Export", "Local Variable"];

Expand Down

0 comments on commit f83c981

Please sign in to comment.