use super::{Cli, Commands};
use crate::command;
use crate::export::ExportOptions;
use concinnity_engine::StateTree;
pub(super) fn dispatch(cli: &Cli, tree: &StateTree) -> std::io::Result<()> {
match cli.resolved_command() {
Commands::Init => command::init(),
Commands::New(args) => command::new(&args.path),
Commands::Build(args) => command::build(
args.world.file(),
if args.verbose {
command::Verbosity::Verbose
} else {
command::Verbosity::Normal
},
),
Commands::Run(args) => concinnity_engine::app::run(
tree,
concinnity_engine::app::run::RunOptions {
mode: if args.serial {
concinnity_engine::app::run::PipelineMode::Serial
} else {
concinnity_engine::app::run::PipelineMode::Pipelined
},
schedule: if args.serial_schedule {
concinnity_core::ecs::ScheduleMode::Serial
} else {
concinnity_core::ecs::ScheduleMode::Parallel
},
screenshot: args.screenshot.clone(),
max_frames: args.frames,
launch: args.render.launch(args.validation, false),
},
),
Commands::Debug(args) => {
let launch = args.render.launch(args.validation, true);
crate::run_debug(launch, args.world.file(), args.debug_port)
}
Commands::Editor(args) => {
let launch = args.render.launch(args.validation, true);
crate::run_editor(launch, args.file.as_deref(), args.debug_port)
}
Commands::Add(args) => {
command::add(args.id.as_deref(), &args.target, args.template.as_deref())
}
Commands::Rm(args) => command::rm(&args.id),
Commands::List(args) => command::list(args.world.file(), args.expanded, args.systems),
Commands::Explain(args) => command::explain(&args.id, args.world.file()),
Commands::Docs(args) => crate::docs::docs(args.root.as_deref()),
Commands::Test(args) => command::check(args.world.file()),
Commands::Export(args) => crate::export::export(&ExportOptions {
world: args.world.file().map(str::to_string),
name: args.name.clone(),
version: args.version.clone(),
platform: args.platform.clone(),
out: args.out.clone(),
format: args.format.into(),
dmg: args.dmg,
}),
Commands::Mcp(args) => crate::run_mcp(args.debug_port),
Commands::Version => command::version(),
}
}