Skip to content

Commit 9b1c19c

Browse files
fix(databases): print a fork description once, and fix doc comment placement
The forked_from row in `fork` and `databases <id>` no longer repeats the description that the next line prints in full. Move the lineage_row doc comment back onto lineage_row.
1 parent 7b273a4 commit 9b1c19c

1 file changed

Lines changed: 26 additions & 12 deletions

File tree

‎src/commands/databases.rs‎

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,11 +1793,7 @@ pub fn get(workspace_id: &str, id_or_name: &str, format: &str) {
17931793
db.default_connection_id.clone().dark_cyan()
17941794
);
17951795
if let Some(f) = &db.forked_from {
1796-
println!(
1797-
"{}{}",
1798-
label("forked_from:"),
1799-
lineage_row(&LineageEntry::from(f.clone()), false)
1800-
);
1796+
println!("{}{}", label("forked_from:"), forked_from_row(f));
18011797
if let Some(d) = &f.description {
18021798
println!(
18031799
"{}{}",
@@ -2170,10 +2166,7 @@ pub fn fork(
21702166
// snapshot); the resolved source id is the fallback for servers
21712167
// that predate lineage.
21722168
match &result.forked_from {
2173-
Some(f) => println!(
2174-
"forked_from: {}",
2175-
lineage_row(&LineageEntry::from(f.clone()), false)
2176-
),
2169+
Some(f) => println!("forked_from: {}", forked_from_row(f)),
21772170
None => println!("forked_from: {}", db.id),
21782171
}
21792172
if let Some(d) = result
@@ -2321,9 +2314,6 @@ fn fetch_lineage(
23212314
.map(LineageResponse::from)
23222315
}
23232316

2324-
/// One `id (name) — root, forked <date>, snapshot <n>, deleted` line of the
2325-
/// lineage tree and the `forked_from:` rows. The id leads: it's the only field
2326-
/// guaranteed present, and the handle every other databases command accepts.
23272317
/// Longest description shown on a one-line lineage row; the full text is in
23282318
/// `-o json`/`yaml` and on `databases <id>`.
23292319
const DESCRIPTION_SUMMARY_CHARS: usize = 60;
@@ -2348,6 +2338,17 @@ fn indent_continuation(s: &str, width: usize) -> String {
23482338
.join(&format!("\n{}", " ".repeat(width)))
23492339
}
23502340

2341+
/// A `forked_from:` row. The description is left off because both views that
2342+
/// print this row give it a line of its own.
2343+
fn forked_from_row(f: &ForkedFrom) -> String {
2344+
let mut entry = LineageEntry::from(f.clone());
2345+
entry.description = None;
2346+
lineage_row(&entry, false)
2347+
}
2348+
2349+
/// One `id (name) — root, forked <date>, snapshot <n>, deleted` line of the
2350+
/// lineage tree and the `forked_from:` rows. The id leads: it's the only field
2351+
/// guaranteed present, and the handle every other databases command accepts.
23512352
fn lineage_row(e: &LineageEntry, root: bool) -> String {
23522353
use crossterm::style::Stylize;
23532354
let mut s = e.database_id.clone().dark_cyan().to_string();
@@ -4211,6 +4212,19 @@ mod tests {
42114212
);
42124213
}
42134214

4215+
#[test]
4216+
fn forked_from_row_leaves_the_description_to_its_own_line() {
4217+
let row = forked_from_row(&ForkedFrom {
4218+
database_id: "db_src".to_string(),
4219+
name: Some("sales".to_string()),
4220+
snapshot_id: Some(42),
4221+
forked_at: None,
4222+
description: Some("q3 what-if".to_string()),
4223+
});
4224+
assert!(row.contains("db_src"), "row: {row}");
4225+
assert!(!row.contains("q3 what-if"), "row: {row}");
4226+
}
4227+
42144228
#[test]
42154229
fn description_summary_keeps_one_short_line() {
42164230
assert_eq!(description_summary("q3 what-if"), "q3 what-if");

0 commit comments

Comments
 (0)