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
use move_package::BuildConfig;
pub mod base;
pub mod experimental;
pub mod package;
pub mod sandbox;
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, gas_schedule::CostTable,
identifier::Identifier,
};
use move_vm_runtime::native_functions::NativeFunction;
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),
default_value = "."
)]
package_path: PathBuf,
#[clap(short = 'v', global = true)]
verbose: bool,
#[clap(flatten)]
build_config: BuildConfig,
}
#[derive(Parser)]
pub struct MoveCLI {
#[clap(flatten)]
move_args: Move,
#[clap(subcommand)]
cmd: Command,
}
#[derive(Parser)]
pub enum Command {
#[clap(name = "package")]
Package {
#[clap(subcommand)]
cmd: package::cli::PackageCommand,
},
#[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,
},
}
pub fn run_cli(
natives: Vec<NativeFunctionRecord>,
cost_table: &CostTable,
error_descriptions: &ErrorMapping,
move_args: &Move,
cmd: &Command,
) -> Result<()> {
match cmd {
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::Package { cmd } => package::cli::handle_package_commands(
&move_args.package_path,
move_args.build_config.clone(),
cmd,
natives,
),
}
}
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,
)
}