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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
use base::{
build::Build, coverage::Coverage, disassemble::Disassemble, docgen::Docgen, errmap::Errmap,
info::Info, movey_login::MoveyLogin, movey_upload::MoveyUpload, new::New, prove::Prove,
test::Test,
};
use move_package::BuildConfig;
pub mod base;
pub mod experimental;
pub mod sandbox;
pub mod utils;
pub const DEFAULT_STORAGE_DIR: &str = "storage";
pub const DEFAULT_BUILD_DIR: &str = ".";
const BCS_EXTENSION: &str = "bcs";
use anyhow::Result;
use clap::Parser;
use move_core_types::{
account_address::AccountAddress, errmap::ErrorMapping, identifier::Identifier,
};
use move_vm_runtime::native_functions::NativeFunction;
use move_vm_test_utils::gas_schedule::CostTable;
use std::path::PathBuf;
type NativeFunctionRecord = (AccountAddress, Identifier, Identifier, NativeFunction);
#[derive(Parser)]
#[clap(author, version, about)]
pub struct Move {
#[clap(long = "path", short = 'p', global = true, parse(from_os_str))]
pub package_path: Option<PathBuf>,
#[clap(short = 'v', global = true)]
pub verbose: bool,
#[clap(flatten)]
pub build_config: BuildConfig,
}
#[derive(Parser)]
pub struct MoveCLI {
#[clap(flatten)]
pub move_args: Move,
#[clap(subcommand)]
pub cmd: Command,
}
#[derive(Parser)]
pub enum Command {
Build(Build),
Coverage(Coverage),
Disassemble(Disassemble),
Docgen(Docgen),
Errmap(Errmap),
Info(Info),
MoveyUpload(MoveyUpload),
New(New),
Prove(Prove),
Test(Test),
#[clap(name = "sandbox")]
Sandbox {
#[clap(long, default_value = DEFAULT_STORAGE_DIR, parse(from_os_str))]
storage_dir: PathBuf,
#[clap(subcommand)]
cmd: sandbox::cli::SandboxCommand,
},
#[clap(name = "experimental")]
Experimental {
#[clap(long, default_value = DEFAULT_STORAGE_DIR, parse(from_os_str))]
storage_dir: PathBuf,
#[clap(subcommand)]
cmd: experimental::cli::ExperimentalCommand,
},
#[clap(name = "movey-login")]
MoveyLogin(MoveyLogin),
}
pub fn run_cli(
natives: Vec<NativeFunctionRecord>,
cost_table: &CostTable,
error_descriptions: &ErrorMapping,
move_args: Move,
cmd: Command,
) -> Result<()> {
match cmd {
Command::Build(c) => c.execute(move_args.package_path, move_args.build_config),
Command::Coverage(c) => c.execute(move_args.package_path, move_args.build_config),
Command::Disassemble(c) => c.execute(move_args.package_path, move_args.build_config),
Command::Docgen(c) => c.execute(move_args.package_path, move_args.build_config),
Command::Errmap(c) => c.execute(move_args.package_path, move_args.build_config),
Command::Info(c) => c.execute(move_args.package_path, move_args.build_config),
Command::MoveyUpload(c) => c.execute(move_args.package_path),
Command::New(c) => c.execute_with_defaults(move_args.package_path),
Command::Prove(c) => c.execute(move_args.package_path, move_args.build_config),
Command::Test(c) => c.execute(move_args.package_path, move_args.build_config, natives),
Command::Sandbox { storage_dir, cmd } => cmd.handle_command(
natives,
cost_table,
error_descriptions,
&move_args,
&storage_dir,
),
Command::Experimental { storage_dir, cmd } => cmd.handle_command(&move_args, &storage_dir),
Command::MoveyLogin(c) => c.execute(),
}
}
pub fn move_cli(
natives: Vec<NativeFunctionRecord>,
cost_table: &CostTable,
error_descriptions: &ErrorMapping,
) -> Result<()> {
let args = MoveCLI::parse();
run_cli(
natives,
cost_table,
error_descriptions,
args.move_args,
args.cmd,
)
}