Skip to content

Commit 100faa4

Browse files
committed
editoast: import railjson can return only id with --quiet
Signed-off-by: Tristram Gräbener <tristram+git@tristramg.eu>
1 parent bb65884 commit 100faa4

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

editoast/src/client/infra_commands.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ pub struct ImportRailjsonArgs {
6666
/// Whether the import should refresh generated data
6767
#[arg(short = 'g', long)]
6868
generate: bool,
69+
/// Only print the generated infra id (useful when scripting)
70+
#[arg(short = 'q', long)]
71+
quiet: bool,
6972
}
7073

7174
pub async fn clone_infra(
@@ -120,32 +123,42 @@ pub async fn import_railjson(
120123
.last_railjson_version();
121124
let railjson: RailJson = serde_json::from_reader(BufReader::new(railjson_file))?;
122125

123-
println!("🍞 Importing infra {infra_name}");
126+
if !args.quiet {
127+
println!("🍞 Importing infra {infra_name}");
128+
}
124129
let mut infra = infra.persist(railjson, &mut db_pool.get().await?).await?;
125130

126131
infra
127132
.bump_version(&mut db_pool.get().await?)
128133
.await
129134
.map_err(|_| InfraApiError::NotFound { infra_id: infra.id })?;
130135

131-
println!("✅ Infra {infra_name}[{}] saved!", infra.id);
136+
if !args.quiet {
137+
println!("✅ Infra {infra_name}[{}] saved!", infra.id);
138+
}
139+
132140
// Generate only if the flag was set
133141
if args.generate {
134142
let infra_cache = InfraCache::load(&mut db_pool.get().await?, &infra).await?;
135143
infra.refresh(db_pool.clone(), true, &infra_cache).await?;
136-
println!(
137-
"✅ Infra {infra_name}[{}] generated data refreshed!",
138-
infra.id
139-
);
144+
if !args.quiet {
145+
println!(
146+
"✅ Infra {infra_name}[{}] generated data refreshed!",
147+
infra.id
148+
);
149+
}
140150

141151
let error_counts = infra.get_error_summary(&mut db_pool.get().await?).await?;
142-
if !error_counts.is_empty() {
152+
if !error_counts.is_empty() && !args.quiet {
143153
println!("🚨 Infra {infra_name}[{}] has errors:", infra.id);
144154
for ((error_type, object_type), count) in error_counts {
145155
println!(" - {:<15} {} {}", object_type.bold(), count, error_type);
146156
}
147157
}
148158
};
159+
if args.quiet {
160+
println!("{}", infra.id);
161+
}
149162
Ok(())
150163
}
151164

@@ -285,6 +298,7 @@ mod tests {
285298
infra_name: "test".into(),
286299
railjson_path: railjson_path.into(),
287300
generate: false,
301+
quiet: false,
288302
};
289303

290304
// WHEN
@@ -318,6 +332,7 @@ mod tests {
318332
infra_name: infra_name.clone(),
319333
railjson_path: file.path().into(),
320334
generate: false,
335+
quiet: false,
321336
};
322337

323338
// WHEN

0 commit comments

Comments
 (0)