concinnity-dev 0.19.119

The Concinnity dev tooling library: world authoring, the in-engine editor, the debug server, docs and packaging
// The one file that joins argv to behavior: match the parsed command and call
// the matching entry point. Everything here is a call; any logic worth testing
// belongs on the other side of it, where `tests/cli.rs` and this crate's own
// tests can reach it.

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) => {
            // Every editor session hot-reloads, with or without a debug port.
            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(),
    }
}