forked from Txio-labs/txio-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.rs
More file actions
248 lines (215 loc) · 6.26 KB
/
Copy pathparser.rs
File metadata and controls
248 lines (215 loc) · 6.26 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
use clap::{Parser, Subcommand, ValueEnum};
use std::fmt;
#[derive(Clone, Debug, ValueEnum, Default, PartialEq, Eq)]
pub enum Network {
#[default]
Mainnet,
Testnet,
Devnet,
Localnet,
}
impl Network {
/// Parse a persisted network name back into a `Network`, accepting the
/// same spellings the CLI flag does. Anything unrecognized is `None` so
/// callers fall back to the default instead of guessing.
pub fn from_config_str(value: &str) -> Option<Network> {
match value.trim().to_ascii_lowercase().as_str() {
"mainnet" => Some(Network::Mainnet),
"testnet" => Some(Network::Testnet),
"devnet" => Some(Network::Devnet),
"localnet" => Some(Network::Localnet),
_ => None,
}
}
}
impl fmt::Display for Network {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let s = match self {
Network::Mainnet => "mainnet",
Network::Testnet => "testnet",
Network::Devnet => "devnet",
Network::Localnet => "localnet",
};
f.write_str(s)
}
}
impl std::str::FromStr for Network {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"mainnet" => Ok(Network::Mainnet),
"testnet" => Ok(Network::Testnet),
"devnet" => Ok(Network::Devnet),
"localnet" => Ok(Network::Localnet),
_ => Err(format!("Unknown network: {}", s)),
}
}
}
#[derive(Parser)]
#[command(name = "txio")]
#[command(version = env!("CARGO_PKG_VERSION"))]
#[command(about = "txio: The Universal Multi-Chain Blockchain Terminal", long_about = None)]
pub struct Cli {
#[command(subcommand)]
pub command: Commands,
/// Enable verbose output
#[arg(short, long, global = true)]
pub verbose: bool,
/// Pretty print JSON output
#[arg(short, long, global = true)]
pub pretty: bool,
/// Override the default RPC URL
#[arg(long, global = true)]
pub rpc_url: Option<String>,
/// Select the network to use (overrides the persisted default). When
/// omitted, the last network chosen via `switch --network` is used;
/// with no persisted choice this defaults to Mainnet.
#[arg(short, long, global = true, value_enum)]
pub network: Option<Network>,
/// Load environment overrides from an explicit file (opt-in; no upward search).
/// Without this flag, a `./.env` in the current directory is NOT loaded.
#[arg(long, global = true, value_name = "PATH")]
pub env_file: Option<std::path::PathBuf>,
}
#[derive(Subcommand)]
pub enum Commands {
/// List all supported chains
Chains,
/// Switch the default chain and/or the persisted default network
Switch {
/// Target blockchain to switch to
chain: Option<String>,
/// Target network to switch to (e.g. mainnet, testnet, devnet, localnet)
#[arg(long, value_enum)]
network: Option<Network>,
},
/// Login to your txio account
Login,
/// Logout from your txio account
Logout,
/// Show current CLI status (chain, network, login state, RPC health)
Status,
/// Manage CLI configuration key-value settings
Config {
#[command(subcommand)]
action: ConfigAction,
},
/// Manage user profiles
Profile {
#[command(subcommand)]
action: ProfileAction,
},
/// Manage wallets
Wallet {
#[command(subcommand)]
action: WalletAction,
},
/// Generate shell completion scripts
Completion { shell: clap_complete::Shell },
/// Launch interactive console
Console,
/// Sui blockchain commands
Sui {
#[command(subcommand)]
command: ChainCommand,
},
/// Ethereum blockchain commands
#[command(alias = "eth")]
Ethereum {
#[command(subcommand)]
command: ChainCommand,
},
/// Solana blockchain commands
#[command(alias = "sol")]
Solana {
#[command(subcommand)]
command: ChainCommand,
},
/// Aptos blockchain commands
Aptos {
#[command(subcommand)]
command: ChainCommand,
},
/// Soroban/Stellar blockchain commands
#[command(alias = "stellar")]
Soroban {
#[command(subcommand)]
command: ChainCommand,
},
/// Database and Admin commands
Db {
#[command(subcommand)]
action: DbAction,
},
}
#[derive(Subcommand)]
pub enum ChainCommand {
/// Call a raw RPC method
Call {
#[arg(short, long)]
method: String,
#[arg(short, long)]
params: Option<String>,
},
/// Check balance for an address
Balance { address: String },
/// Fetch a transaction by hash or digest
#[command(alias = "hash")]
Tx { hash: String },
/// Inspect an object or account by ID
#[command(alias = "account")]
Object { id: String },
/// Get recent transaction history for an address
History {
address: String,
/// Maximum number of transactions to return
#[arg(short, long, default_value_t = 10)]
limit: u32,
},
/// Get the current gas price / reference fee
Gas,
/// Get the latest block, checkpoint, or ledger (or by number)
Block {
/// Block number / checkpoint sequence / slot to fetch
#[arg(short, long)]
number: Option<u64>,
},
}
#[derive(Subcommand)]
pub enum ConfigAction {
/// List all configuration settings
List,
/// Get a specific configuration value
Get { key: String },
/// Set a configuration value
Set { key: String, value: String },
/// Remove a configuration key
Unset { key: String },
}
#[derive(Subcommand)]
pub enum ProfileAction {
Add,
List,
Remove { name: String },
}
#[derive(Subcommand)]
pub enum WalletAction {
Import,
List,
New,
}
#[derive(Subcommand)]
pub enum DbAction {
/// List all registered users
ListUsers,
/// Delete a user by email (admin only)
DeleteUser { email: String },
/// Show database statistics (users, RPC call count)
Stats,
/// List recent RPC call logs
ListLogs {
/// Maximum number of log entries to show
#[arg(short, long, default_value_t = 20)]
limit: u64,
},
}