1use std::path::Path;
6
7use clap::Parser;
8use iota_move_build::{IotaPackageHooks, set_iota_flavor};
9use move_cli::base::test::UnitTestResult;
10use move_package::BuildConfig;
11
12pub mod build;
13pub mod coverage;
14pub mod disassemble;
15pub mod manage_package;
16pub mod migrate;
17pub mod new;
18pub mod unit_test;
19
20#[derive(Parser)]
21pub enum Command {
22 Build(build::Build),
23 Coverage(coverage::Coverage),
24 Disassemble(disassemble::Disassemble),
25 ManagePackage(manage_package::ManagePackage),
26 Migrate(migrate::Migrate),
27 New(new::New),
28 Test(unit_test::Test),
29}
30#[derive(Parser)]
31pub struct Calib {
32 #[arg(name = "runs", short = 'r', long, default_value = "1")]
33 runs: usize,
34 #[arg(name = "summarize", short = 's', long)]
35 summarize: bool,
36}
37
38pub fn execute_move_command(
39 package_path: Option<&Path>,
40 mut build_config: BuildConfig,
41 command: Command,
42) -> anyhow::Result<()> {
43 if let Some(err_msg) = set_iota_flavor(&mut build_config) {
44 anyhow::bail!(err_msg);
45 }
46 move_package::package_hooks::register_package_hooks(Box::new(IotaPackageHooks));
47 match command {
48 Command::Build(c) => c.execute(package_path, build_config),
49 Command::Coverage(c) => c.execute(package_path, build_config),
50 Command::Disassemble(c) => c.execute(package_path, build_config),
51 Command::ManagePackage(c) => c.execute(package_path, build_config),
52 Command::Migrate(c) => c.execute(package_path, build_config),
53 Command::New(c) => c.execute(package_path),
54
55 Command::Test(c) => {
56 let result = c.execute(package_path, build_config)?;
57
58 if let UnitTestResult::Failure = result {
60 std::process::exit(1)
61 }
62
63 Ok(())
64 }
65 }
66}