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 clap::{Parser, Subcommand};
#[derive(Parser)]
#[command(name = "ncheap", version, about = "Namecheap registrar API CLI")]
pub struct Cli {
/// Emit machine-readable JSON on stdout
#[arg(long, global = true)]
pub json: bool,
/// Config profile to use (overrides NCHEAP_PROFILE and default_profile)
#[arg(long, global = true)]
pub profile: Option<String>,
#[command(subcommand)]
pub command: Command,
}
#[derive(Subcommand)]
pub enum Command {
/// Domain operations
Domains {
#[command(subcommand)]
command: DomainsCommand,
},
/// Account operations
Account {
#[command(subcommand)]
command: AccountCommand,
},
/// DNS operations
Dns {
#[command(subcommand)]
command: DnsCommand,
},
/// Domain privacy operations
Privacy {
#[command(subcommand)]
command: PrivacyCommand,
},
/// Call an allowlisted read-only API method directly, emitting raw XML
Raw {
/// API command, e.g. domains.getTldList ("namecheap." prefix optional)
command: String,
/// Method parameter, repeatable: --param Key=Value
#[arg(long = "param", value_name = "KEY=VALUE")]
params: Vec<String>,
},
}
impl Command {
/// The command name used in the JSON envelope; the single source of
/// truth so main's error path and success path cannot drift apart.
pub fn name(&self) -> &'static str {
match self {
Command::Domains { command } => match command {
DomainsCommand::List => "domains.list",
DomainsCommand::Check { .. } => "domains.check",
DomainsCommand::Lock { .. } => "domains.lock",
DomainsCommand::Info { .. } => "domains.info",
DomainsCommand::Contacts { .. } => "domains.contacts",
},
Command::Account { command } => match command {
AccountCommand::Balances { .. } => "account.balances",
AccountCommand::Pricing { .. } => "account.pricing",
},
Command::Dns {
command: DnsCommand::Get { .. },
} => "dns.get",
Command::Privacy {
command: PrivacyCommand::List,
} => "privacy.list",
Command::Raw { .. } => "raw",
}
}
}
#[derive(Subcommand)]
pub enum PrivacyCommand {
/// List all domain privacy subscriptions (auto-paginated)
List,
}
#[derive(Subcommand)]
pub enum DnsCommand {
/// Show nameserver mode and host records for a domain
Get { domain: String },
}
#[derive(Subcommand)]
pub enum DomainsCommand {
/// List all domains in the account (auto-paginated)
List,
/// Check availability of one or more domains
Check {
/// Domains to check (the API caps one call at 50)
#[arg(required = true)]
domains: Vec<String>,
},
/// Show the registrar lock status of a domain
Lock { domain: String },
/// Show registration, privacy, and DNS details for a domain
Info { domain: String },
/// Show domain contacts (PII redacted unless --full)
Contacts {
domain: String,
/// Show the actual contact fields
#[arg(long)]
full: bool,
},
}
#[derive(Subcommand)]
pub enum AccountCommand {
/// Show account balance summary (amounts redacted unless --full)
Balances {
/// Show exact balance amounts
#[arg(long)]
full: bool,
},
/// Show product pricing (response cached locally for 24h)
Pricing {
/// Product type (DOMAIN, SSLCERTIFICATE)
#[arg(long = "type", default_value = "DOMAIN")]
product_type: String,
/// Product category filter (e.g. DOMAINS)
#[arg(long)]
category: Option<String>,
/// Action filter (e.g. REGISTER, RENEW, TRANSFER)
#[arg(long)]
action: Option<String>,
/// Product name filter (e.g. com)
#[arg(long)]
product: Option<String>,
},
}