-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathargs.rs
102 lines (87 loc) · 3.07 KB
/
args.rs
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
//! Cainome CLI arguments.
//!
use cainome_rs::ExecutionVersion;
use camino::Utf8PathBuf;
use clap::{Args, Parser};
use starknet::core::types::Felt;
use url::Url;
use crate::plugins::builtins::BuiltinPlugins;
use crate::plugins::PluginManager;
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
#[command(propagate_version = true)]
pub struct CainomeArgs {
#[arg(long)]
#[arg(value_name = "OUTPUT_DIR")]
#[arg(help = "Directory where bindings files must be written.")]
pub output_dir: Utf8PathBuf,
#[arg(long)]
#[arg(value_name = "PATH")]
#[arg(conflicts_with = "contract_address")]
#[arg(
help = "Path where artifacts are located. Cainome will parse all the files that are a valid Sierra artifact."
)]
pub artifacts_path: Option<Utf8PathBuf>,
#[arg(long)]
#[arg(value_name = "PATH")]
#[arg(help = "Path of a JSON file defining Cainome parsing configuration.")]
pub parser_config: Option<Utf8PathBuf>,
#[arg(long)]
#[arg(value_name = "ADDRESS")]
#[arg(conflicts_with = "artifacts_path")]
#[arg(requires = "rpc_url")]
#[arg(requires = "contract_name")]
#[arg(help = "Address of the contract to fetch the ABI from.")]
pub contract_address: Option<Felt>,
#[arg(long)]
#[arg(value_name = "NAME")]
#[arg(requires = "contract_address")]
#[arg(requires = "rpc_url")]
#[arg(help = "Name of the contract.")]
pub contract_name: Option<String>,
#[arg(long)]
#[arg(value_name = "URL")]
#[arg(requires = "contract_address")]
#[arg(requires = "contract_name")]
#[arg(conflicts_with = "artifacts_path")]
#[arg(help = "The Starknet RPC provider to fetch the ABI from.")]
pub rpc_url: Option<Url>,
#[command(flatten)]
#[command(next_help_heading = "Plugins options")]
pub plugins: PluginOptions,
#[arg(long)]
#[arg(value_name = "EXECUTION_VERSION")]
#[arg(help = "The execution version to use. Supported values are 'v1', 'V1', 'v3', or 'V3'.")]
pub execution_version: ExecutionVersion,
#[arg(long)]
#[arg(value_name = "DERIVES")]
#[arg(help = "Derives to be added to the generated types.")]
pub derives: Option<Vec<String>>,
#[arg(long)]
#[arg(value_name = "CONTRACT_DERIVES")]
#[arg(help = "Derives to be added to the generated contract.")]
pub contract_derives: Option<Vec<String>>,
}
#[derive(Debug, Args, Clone)]
pub struct PluginOptions {
#[arg(long)]
#[arg(help = "Generate bindings for rust (built-in).")]
pub rust: bool,
// TODO: For custom plugin, we can add a vector of strings,
// where the user provides the name of the plugin.
// Then cainome like protobuf will attempt to execute cainome_plugin_<NAME>.
}
impl From<PluginOptions> for PluginManager {
fn from(options: PluginOptions) -> Self {
let mut builtin_plugins = vec![];
// Ignored for now.
let plugins = vec![];
if options.rust {
builtin_plugins.push(BuiltinPlugins::Rust);
}
Self {
builtin_plugins,
plugins,
}
}
}