pub mod clean;
#[doc(hidden)]
pub mod cli;
pub mod common;
pub mod config;
pub mod graph;
pub mod hash;
pub mod init;
pub mod plan;
pub mod release;
pub mod run;
pub mod split;
pub mod sync;
pub mod unify;
pub use clean::run_clean;
#[doc(hidden)]
pub use cli::{CargoCli, Commands, RailCli, ReleaseCommand, SplitCommand, generate_completions};
pub use common::OutputFormat;
pub use config::{
StrictnessMode, run_config_locate, run_config_print, run_config_sync, run_config_validate_standalone,
};
pub use graph::run_graph;
pub use hash::{run_diff_hash, run_hash};
pub use init::{run_init, run_init_standalone};
pub use plan::{PlanOptions, run_plan};
pub use release::{run_release_check, run_release_init, run_release_plan, run_release_publish};
pub use run::run_run;
pub use split::{run_split, run_split_init};
pub use sync::run_sync;
pub use unify::{run_unify_analyze, run_unify_apply, run_unify_undo};
use crate::error::RailResult;
use crate::workspace::WorkspaceContext;
use std::path::Path;
#[doc(hidden)]
pub enum PreContextDispatch {
Handled,
NeedsContext(Commands),
}
#[doc(hidden)]
pub fn try_dispatch_pre_context(
cmd: Commands,
workspace_root: &Path,
config_override: Option<&Path>,
json: bool,
) -> RailResult<PreContextDispatch> {
match cmd {
Commands::Init { output, force, check } => {
init::run_init_standalone(workspace_root, &output, force, check, json)?;
Ok(PreContextDispatch::Handled)
}
Commands::Unify {
command: Some(cli::UnifyCommand::Undo { list, backup_id }),
..
} => {
unify::run_unify_undo(workspace_root, list, backup_id)?;
Ok(PreContextDispatch::Handled)
}
Commands::Config {
command: cli::ConfigCommand::Sync { check, format },
} => {
config::run_config_sync(workspace_root, config_override, check, format)?;
Ok(PreContextDispatch::Handled)
}
Commands::Config {
command: cli::ConfigCommand::Validate {
format,
strict,
no_strict,
},
} => {
let strictness = if strict {
StrictnessMode::Strict
} else if no_strict {
StrictnessMode::NoStrict
} else {
StrictnessMode::Auto
};
config::run_config_validate_standalone(workspace_root, config_override, format, strictness)?;
Ok(PreContextDispatch::Handled)
}
Commands::Config {
command: cli::ConfigCommand::Locate { format },
} => {
config::run_config_locate(workspace_root, config_override, format)?;
Ok(PreContextDispatch::Handled)
}
Commands::Config {
command: cli::ConfigCommand::Print { format },
} => {
config::run_config_print(workspace_root, config_override, format)?;
Ok(PreContextDispatch::Handled)
}
Commands::Completions { shell } => {
cli::generate_completions(shell);
Ok(PreContextDispatch::Handled)
}
other => Ok(PreContextDispatch::NeedsContext(other)),
}
}
pub fn dispatch(cmd: Commands, ctx: &WorkspaceContext) -> RailResult<()> {
match cmd {
Commands::Run {
since,
merge_base,
all,
surfaces,
profile,
workflow,
dry_run,
print_cmd,
explain,
ignore_bin_crates,
skip_nextest,
run_args,
} => run_run(
ctx,
run::RunOptions {
since,
merge_base,
all,
surfaces,
profile,
workflow,
dry_run,
print_cmd,
explain,
ignore_bin_crates,
skip_nextest,
run_args,
},
),
Commands::Plan {
since,
from,
to,
merge_base,
format,
output,
explain,
confidence_profile,
} => run_plan(
ctx,
PlanOptions {
since,
from,
to,
merge_base,
format,
output,
explain,
confidence_profile,
},
),
Commands::Init { .. } => unreachable!("Init command should be handled before dispatch"),
Commands::Unify {
command,
check,
plan,
format,
backup,
skip_report,
report_path,
output,
show_diff,
explain,
} => {
if command.is_some() {
unreachable!("Undo subcommand should be handled before dispatch")
} else if check {
run_unify_analyze(ctx, show_diff, explain, format, output.as_ref())
} else {
run_unify_apply(ctx, backup, skip_report, report_path, plan)
}
}
Commands::Split { command } => match command {
cli::SplitCommand::Init { crate_names, check } => {
let crates = if crate_names.is_empty() {
None
} else {
Some(crate_names)
};
run_split_init(ctx, crates, check)
}
cli::SplitCommand::Run {
crate_name,
all,
remote,
check,
plan,
allow_dirty,
yes,
format,
} => run_split(
ctx,
split::SplitRunArgs {
crate_name,
all,
remote,
check,
plan_path: plan,
allow_dirty,
yes,
format,
},
),
},
Commands::Sync {
crate_name,
all,
remote,
from_remote,
to_remote,
strategy,
check,
plan,
allow_dirty,
yes,
format,
} => run_sync(
ctx,
sync::SyncArgs {
crate_name,
all,
remote,
from_remote,
to_remote,
strategy,
check,
plan_path: plan,
allow_dirty,
yes,
format,
},
),
Commands::Release { command } => match command {
cli::ReleaseCommand::Init { crate_names, check } => {
let crates = if crate_names.is_empty() {
None
} else {
Some(crate_names)
};
run_release_init(ctx, crates, check)
}
cli::ReleaseCommand::Run {
crate_names,
all,
bump,
check,
plan,
skip_publish,
skip_tag,
include_dependents,
yes,
format,
} => {
let names = if all || crate_names.is_empty() {
None
} else {
Some(crate_names)
};
if check {
run_release_plan(ctx, names, bump, skip_publish, skip_tag, include_dependents, format)
} else {
run_release_publish(
ctx,
release::ReleasePublishArgs {
crate_names: names,
all,
bump,
skip_publish,
skip_tag,
include_dependents,
yes,
plan_path: plan,
},
)
}
}
cli::ReleaseCommand::Check {
crate_names,
all,
extended,
include_dependents,
format,
} => {
let names = if all || crate_names.is_empty() {
None
} else {
Some(crate_names)
};
run_release_check(ctx, names, all, extended, include_dependents, format)
}
},
Commands::Clean {
cache,
backups,
reports,
check,
format,
} => run_clean(ctx, cache, backups, reports, check, format),
Commands::Config { command } => match command {
cli::ConfigCommand::Locate { .. } => unreachable!("Config locate should be handled before dispatch"),
cli::ConfigCommand::Print { .. } => unreachable!("Config print should be handled before dispatch"),
cli::ConfigCommand::Validate { .. } => unreachable!("Config validate should be handled before dispatch"),
cli::ConfigCommand::Sync { .. } => unreachable!("Config sync should be handled before dispatch"),
},
Commands::Hash {
since,
from,
to,
merge_base,
confidence_profile,
format,
} => run_hash(
ctx,
hash::HashOptions {
since,
from,
to,
merge_base,
confidence_profile,
format,
},
),
Commands::DiffHash { a, b, format } => run_diff_hash(a, b, format),
Commands::Graph {
since,
from,
to,
merge_base,
confidence_profile,
dot,
output,
} => run_graph(
ctx,
graph::GraphOptions {
since,
from,
to,
merge_base,
confidence_profile,
dot,
output,
},
),
Commands::Completions { .. } => unreachable!("Completions should be handled before dispatch"),
}
}