Skip to content

Commit f83c981

Browse files
committed
chore: add progress bar for cli
1 parent 06cc895 commit f83c981

File tree

7 files changed

+24
-11
lines changed

7 files changed

+24
-11
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ swc_core = { version = "0.104.2", features = ["common", "ecma_ast", "ecma
2525
swc_ecma_parser = { version = "0.150.0", features = ["typescript"] }
2626
clap = { version = "4.5", features = ["derive"] }
2727
rusqlite = { version = "0.32.1", features = ["bundled"] }
28+
indicatif = "0.17.8"

crates/api_server/src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ struct Info {
2626
exact_match: bool,
2727
}
2828

29+
// Current implementation is mimick version of the trace with in-memory graph.
30+
// We can refactor it after the database feature gets validated.
2931
#[get("/search")]
3032
async fn search(
3133
data: web::Data<AppState>,

crates/cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ version = "0.1.0"
1010
anyhow = { workspace = true }
1111
clap = { workspace = true }
1212
serde_json = { workspace = true }
13+
indicatif = { workspace = true }
1314

1415
dt_core = { version = "0.1.0", path = "../dt_core" }

crates/cli/src/main.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use dt_core::{
1515
route::{collect_route_dependency, Route, SymbolToRoutes},
1616
scheduler::ParserCandidateScheduler,
1717
};
18+
use indicatif::{ProgressBar, ProgressStyle};
1819
use std::{
1920
collections::{HashMap, HashSet},
2021
fs::File,
@@ -156,6 +157,13 @@ fn parse_and_export_project_to_database(
156157
.context("add translation to project")?;
157158

158159
let mut scheduler = ParserCandidateScheduler::new(&project_root);
160+
let bar = ProgressBar::new(scheduler.get_total_remaining_candidate_count() as u64);
161+
bar.set_style(
162+
ProgressStyle::with_template(
163+
"[{elapsed_precise}] {bar:40.cyan/blue} {pos:>7}/{len:7} {msg}",
164+
)?
165+
.progress_chars("##-"),
166+
);
159167
loop {
160168
match scheduler.get_one_candidate() {
161169
Some(c) => {
@@ -198,11 +206,12 @@ fn parse_and_export_project_to_database(
198206
))?;
199207

200208
scheduler.mark_candidate_as_parsed(c);
209+
bar.inc(1);
201210
}
202211
None => break,
203212
}
204213
}
205-
214+
bar.finish_with_message("all modules parsed 🌲");
206215
Ok(())
207216
}
208217

@@ -562,7 +571,8 @@ impl Project {
562571
))?;
563572
}
564573
Err(_) => {
565-
println!("try to add translation for symbol {}, but translation {} doesn't exist", symbol_name, key);
574+
// you can uncomment this to debug
575+
// println!("try to add translation for symbol {}, but translation {} doesn't exist", symbol_name, key);
566576
}
567577
}
568578
}

crates/demo/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ version = "0.1.0"
77

88

99
[dependencies]
10-
anyhow = { workspace = true }
11-
clap = { workspace = true }
10+
anyhow = { workspace = true }
11+
clap = { workspace = true }
12+
indicatif = { workspace = true }
1213

1314
umya-spreadsheet = "1.2.3"
1415
dialoguer = { version = "0.11.0", features = ["history"] }
15-
indicatif = "0.17.8"
1616
console = "0.15.8"
1717
rand = "0.8.5"
1818

crates/demo/src/main.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
use anyhow::Context;
22
use clap::Parser;
33
use console::style;
4-
use dialoguer::{theme::ColorfulTheme, BasicHistory, Confirm, Input, Select};
5-
use indicatif::{ProgressBar, ProgressStyle};
6-
use rand::distributions::Alphanumeric;
7-
use rand::{thread_rng, Rng};
8-
use std::path::PathBuf;
9-
104
use demo::spreadsheet::write_to_spreadsheet;
5+
use dialoguer::{theme::ColorfulTheme, BasicHistory, Confirm, Input, Select};
116
use dt_core::{
127
graph::{depend_on_graph::DependOnGraph, used_by_graph::UsedByGraph},
138
parser::{collect_symbol_dependency, Input as ModuleInput},
149
path_resolver::{PathResolver, ToCanonicalString},
1510
scheduler::ParserCandidateScheduler,
1611
tracker::{DependencyTracker, TraceTarget},
1712
};
13+
use indicatif::{ProgressBar, ProgressStyle};
14+
use rand::{distributions::Alphanumeric, thread_rng, Rng};
15+
use std::path::PathBuf;
1816

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

0 commit comments

Comments
 (0)