multiversx_sc_meta_lib/cli/
cli_args_contract.rs1use clap::{ArgAction, Args, Parser, Subcommand};
2
3use super::{BuildArgs, BuildDbgArgs, CliArgsToRaw, TwiggyArgs};
4
5#[derive(Default, PartialEq, Eq, Debug, Parser)]
7#[command(
8 version,
9 about,
10 after_help = "
11The MultiversX smart contract Meta crate can be used in two ways:
12 A. Import it into a contract's specific meta-crate.
13 There it will receive access to the contract ABI generator.
14 Based on that it is able to build the contract and apply various tools.
15 This part also contains the multi-contract config infrastructure.
16
17 B. Use it as a standalone tool.
18 It can be used to automatically upgrade contracts from one version to the next.
19
20You are currently using the contract tool (A).
21"
22)]
23#[command(propagate_version = true)]
24pub struct ContractCliArgs {
25 #[command(subcommand)]
26 pub command: ContractCliAction,
27
28 #[arg(
29 long = "no-abi-git-version",
30 help = "Skips loading the Git version into the ABI",
31 action = ArgAction::SetFalse
32 )]
33 #[clap(global = true)]
34 pub load_abi_git_version: bool,
35}
36
37#[derive(Default, Clone, PartialEq, Eq, Debug, Subcommand)]
38pub enum ContractCliAction {
39 #[default]
40 #[command(name = "abi", about = "Generates the contract ABI and nothing else.")]
41 Abi,
42
43 #[command(
44 name = "build",
45 about = "Builds contract(s) for deploy on the blockchain."
46 )]
47 Build(BuildArgs),
48
49 #[command(name = "build-dbg", about = "Builds contract(s) with symbols and WAT.")]
50 BuildDbg(BuildDbgArgs),
51
52 #[command(
53 name = "twiggy",
54 about = "Builds contract(s) and generate twiggy reports."
55 )]
56 Twiggy(TwiggyArgs),
57
58 #[command(about = "Clean the Rust project and the output folder.")]
59 Clean,
60
61 #[command(about = "Update the Cargo.lock files in all wasm crates.")]
62 Update,
63
64 #[command(
65 name = "snippets",
66 about = "Generates a snippets project, based on the contract ABI."
67 )]
68 GenerateSnippets(GenerateSnippetsArgs),
69
70 #[command(
71 name = "proxy",
72 about = "Generates a proxy, based on the contract ABI."
73 )]
74 GenerateProxies(GenerateProxyArgs),
75}
76
77impl CliArgsToRaw for ContractCliAction {
78 fn to_raw(&self) -> Vec<String> {
79 let mut raw = Vec::new();
80 match self {
81 ContractCliAction::Abi => {
82 raw.push("abi".to_string());
83 }
84 ContractCliAction::Build(args) => {
85 raw.push("build".to_string());
86 raw.append(&mut args.to_raw());
87 }
88 ContractCliAction::BuildDbg(args) => {
89 raw.push("build-dbg".to_string());
90 raw.append(&mut args.to_raw());
91 }
92 ContractCliAction::Twiggy(args) => {
93 raw.push("twiggy".to_string());
94 raw.append(&mut args.to_raw());
95 }
96 ContractCliAction::Clean => {
97 raw.push("clean".to_string());
98 }
99 ContractCliAction::Update => {
100 raw.push("update".to_string());
101 }
102 ContractCliAction::GenerateSnippets(args) => {
103 raw.push("snippets".to_string());
104 raw.append(&mut args.to_raw());
105 }
106 ContractCliAction::GenerateProxies(args) => {
107 raw.push("proxy".to_string());
108 raw.append(&mut args.to_raw());
109 }
110 }
111 raw
112 }
113}
114
115#[derive(Default, Clone, PartialEq, Eq, Debug, Args)]
116pub struct GenerateSnippetsArgs {
117 #[arg(long, verbatim_doc_comment)]
119 pub overwrite: bool,
120}
121
122impl CliArgsToRaw for GenerateSnippetsArgs {
123 fn to_raw(&self) -> Vec<String> {
124 let mut raw = Vec::new();
125 if self.overwrite {
126 raw.push("--overwrite".to_string());
127 }
128 raw
129 }
130}
131
132#[derive(Default, Clone, PartialEq, Eq, Debug, Args)]
133pub struct GenerateProxyArgs {
134 #[arg(long, verbatim_doc_comment)]
136 pub compare: bool,
137}
138
139impl CliArgsToRaw for GenerateProxyArgs {
140 fn to_raw(&self) -> Vec<String> {
141 let mut raw = Vec::new();
142 if self.compare {
143 raw.push("--compare".to_string());
144 }
145 raw
146 }
147}