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
use clap::Subcommand;
use serde_json::json;
use crate::socket::{client::DaemonSocketClient, types::DaemonCommandKind};
#[derive(Subcommand, Debug)]
pub(crate) enum CreateCommand {
/// Create a zone
Zone {
/// Zone name
#[arg(long)]
name: String,
/// Primary nameserver
#[arg(long)]
primary_ns: String,
/// Admin email
#[arg(long)]
admin_email: String,
/// TTL
#[arg(long)]
ttl: i32,
/// Serial number (optional, auto-generated if not provided)
#[arg(long)]
serial: Option<i32>,
},
/// Create a record
Record {
/// Record name
#[arg(long)]
name: String,
/// Record type (A, AAAA, CNAME, MX, etc.)
#[arg(long = "type", alias = "record-type")]
record_type: String,
/// Record value
#[arg(long)]
value: String,
/// Zone name
#[arg(long,
aliases = ["zone"]
)]
zone_name: String,
/// TTL (optional)
#[arg(long)]
ttl: Option<i32>,
/// Priority (for MX records)
#[arg(long)]
priority: Option<i32>,
},
}
pub(crate) async fn handle_command(subcommand: CreateCommand) -> Result<(), String> {
let client = DaemonSocketClient::new();
match subcommand {
CreateCommand::Zone {
name,
primary_ns,
admin_email,
ttl,
serial,
} => {
let data = json!({
"name": name,
"primary_ns": primary_ns,
"admin_email": admin_email,
"ttl": ttl,
"serial": serial,
});
let response = client
.send_command(DaemonCommandKind::CreateZone, Some(data))
.await?;
println!("{}", response.message);
}
CreateCommand::Record {
name,
record_type,
value,
zone_name,
ttl,
priority,
} => {
let data = json!({
"name": name,
"record_type": record_type,
"value": value,
"zone_name": zone_name,
"ttl": ttl,
"priority": priority,
});
let response = client
.send_command(DaemonCommandKind::CreateRecord, Some(data))
.await?;
println!("{}", response.message);
}
}
Ok(())
}