Skip to content

Commit c9cfb9b

Browse files
committed
Add smart execution mode and fix interactive detection
- Auto-detect SerenDB targets for remote execution - Respect --local flag (was previously ignored with `local: _`) - Skip interactive mode when CLI filter flags are provided - Add --sync flag as explicit enable (alias for default behavior) Behavior changes: - init --target db.serendb.com → auto remote execution - init --include-databases X → skip interactive prompts - init --local forces local execution even for SerenDB targets Closes #6
1 parent c636384 commit c9cfb9b

1 file changed

Lines changed: 33 additions & 8 deletions

File tree

src/main.rs

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ enum Commands {
8989
/// Drop existing databases on target before copying
9090
#[arg(long)]
9191
drop_existing: bool,
92-
/// Disable automatic continuous replication setup after snapshot (default: false, meaning sync IS enabled)
92+
/// Enable continuous replication after snapshot (default)
93+
#[arg(long)]
94+
sync: bool,
95+
/// Disable automatic continuous replication setup after snapshot
9396
#[arg(long)]
9497
no_sync: bool,
9598
/// Ignore any previous checkpoint and start a fresh run
@@ -228,22 +231,31 @@ async fn main() -> anyhow::Result<()> {
228231
no_interactive,
229232
table_rules,
230233
drop_existing,
234+
sync: _, // sync is the default behavior, no_sync overrides it
231235
no_sync,
232236
no_resume,
233237
seren,
234-
local: _, // local is implicit when --seren is not specified
238+
local,
235239
seren_api,
236240
job_timeout,
237241
} => {
238-
// Interactive mode is default unless --no-interactive or --yes is specified
239-
// (--yes implies automation, so it disables interactive mode)
242+
// Check if CLI filter flags were provided (skip interactive if so)
243+
let has_cli_filters = include_databases.is_some()
244+
|| exclude_databases.is_some()
245+
|| include_tables.is_some()
246+
|| exclude_tables.is_some();
247+
248+
// Interactive mode is default unless:
249+
// - --no-interactive flag is set
250+
// - --yes flag is set (implies automation)
251+
// - CLI filter flags are provided
240252
// Run this BEFORE remote execution check so interactive mode works for both local and remote
241253
let (
242254
final_include_databases,
243255
final_exclude_databases,
244256
final_include_tables,
245257
final_exclude_tables,
246-
) = if !no_interactive && !yes {
258+
) = if !no_interactive && !yes && !has_cli_filters {
247259
// Interactive mode (default) - prompt user to select databases and tables
248260
let (filter, _rules) =
249261
database_replicator::interactive::select_databases_and_tables(&source).await?;
@@ -265,8 +277,21 @@ async fn main() -> anyhow::Result<()> {
265277
)
266278
};
267279

268-
// SerenAI cloud execution path (when --seren flag is used)
269-
if seren {
280+
// Determine execution mode:
281+
// 1. --seren flag → remote execution
282+
// 2. --local flag → local execution
283+
// 3. Neither → auto-detect based on target URL (SerenDB = remote)
284+
let use_remote = if seren {
285+
true
286+
} else if local {
287+
false
288+
} else {
289+
// Auto-detect: SerenDB targets default to remote execution
290+
database_replicator::utils::is_serendb_target(&target)
291+
};
292+
293+
if use_remote {
294+
tracing::info!("Using SerenAI cloud execution");
270295
return init_remote(
271296
source,
272297
target,
@@ -283,7 +308,7 @@ async fn main() -> anyhow::Result<()> {
283308
.await;
284309
}
285310

286-
// Local execution path (existing code continues below)
311+
// Local execution path
287312
let filter = database_replicator::filters::ReplicationFilter::new(
288313
final_include_databases,
289314
final_exclude_databases,

0 commit comments

Comments
 (0)