1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use clap::Parser;
#[cfg(feature = "unit_test")]
use move_cli::base::test::UnitTestResult;
use move_package::BuildConfig;
use std::path::PathBuf;
use sui_move_build::set_sui_flavor;

#[cfg(feature = "build")]
pub mod build;
#[cfg(feature = "coverage")]
pub mod coverage;
#[cfg(feature = "disassemble")]
pub mod disassemble;
pub mod manage_package;
pub mod migrate;
pub mod new;
#[cfg(feature = "unit_test")]
pub mod unit_test;

#[derive(Parser)]
pub enum Command {
    #[cfg(feature = "build")]
    Build(build::Build),
    #[cfg(feature = "coverage")]
    Coverage(coverage::Coverage),
    #[cfg(feature = "disassemble")]
    Disassemble(disassemble::Disassemble),
    ManagePackage(manage_package::ManagePackage),
    Migrate(migrate::Migrate),
    New(new::New),
    #[cfg(feature = "unit_test")]
    Test(unit_test::Test),
}
#[derive(Parser)]
pub struct Calib {
    #[clap(name = "runs", short = 'r', long = "runs", default_value = "1")]
    runs: usize,
    #[clap(name = "summarize", short = 's', long = "summarize")]
    summarize: bool,
}

pub fn execute_move_command(
    package_path: Option<PathBuf>,
    mut build_config: BuildConfig,
    command: Command,
) -> anyhow::Result<()> {
    if let Some(err_msg) = set_sui_flavor(&mut build_config) {
        anyhow::bail!(err_msg);
    }
    match command {
        #[cfg(feature = "build")]
        Command::Build(c) => c.execute(package_path, build_config),
        #[cfg(feature = "coverage")]
        Command::Coverage(c) => c.execute(package_path, build_config),
        #[cfg(feature = "disassemble")]
        Command::Disassemble(c) => c.execute(package_path, build_config),
        Command::ManagePackage(c) => c.execute(package_path, build_config),
        Command::Migrate(c) => c.execute(package_path, build_config),
        Command::New(c) => c.execute(package_path),

        #[cfg(feature = "unit_test")]
        Command::Test(c) => {
            let result = c.execute(package_path, build_config)?;

            // Return a non-zero exit code if any test failed
            if let UnitTestResult::Failure = result {
                std::process::exit(1)
            }

            Ok(())
        }
    }
}