ts fn can go. its getting less uses!

This commit is contained in:
lda
2026-04-28 18:15:41 +07:00 Verified
parent aa698a9f4b
commit d0fa6bf526
9 changed files with 40 additions and 28 deletions
+10 -6
View File
@@ -39,8 +39,11 @@ pub enum Command {
#[derive(Args)]
pub struct LeasesArgs {
/// Include best-known current neighbor state for each lease IP.
#[arg(long)]
/// Legacy: include neighbor state on lease rows. Prefer `wakey inventory`.
#[arg(
long,
help = "Deprecated: include neighbor state on lease rows. Prefer `wakey inventory`."
)]
pub include_state: bool,
/// Print machine-readable JSON instead of a table.
#[arg(long)]
@@ -201,10 +204,11 @@ pub async fn run(cli: Cli) -> Result<()> {
json = args.json,
"dispatching leases command"
);
let leases = wakey::get_leases(wakey_core::LeaseQuery {
include_state: args.include_state,
})
.await?;
let leases = if args.include_state {
wakey::get_leases_with_neighbor_state().await?
} else {
wakey::get_leases().await?
};
if args.json {
println!("{}", serde_json::to_string_pretty(&leases)?);
} else {
+3 -3
View File
@@ -7,9 +7,9 @@ pub use wakey_linux;
pub use service::{
broadcast_wake_targets, get_interface_summaries, get_interface_summary, get_ips, get_leases,
inventory, leases_without_state, local_observation_to_fact, merge_devices,
merge_devices_with_observations, resolve_devices, resolve_query, resolve_selector,
resolve_wake_targets, wake_explicit, wake_from_query, wake_targets,
get_leases_with_neighbor_state, inventory, leases_without_state, local_observation_to_fact,
merge_devices, merge_devices_with_observations, resolve_devices, resolve_query,
resolve_selector, resolve_wake_targets, wake_explicit, wake_from_query, wake_targets,
};
pub use wakey_linux::dhcp::{list_local_observations, observe_dhcp_event, observe_neighbor_event};
+1 -4
View File
@@ -21,10 +21,7 @@ pub async fn resolve_devices(input: impl Into<String>) -> Result<Vec<Device>> {
/// directly from raw Linux source rows.
pub async fn inventory(query: InventoryQuery) -> Result<DeviceInventory> {
let neighbors = wakey_linux::devices::query_neighbors(&query).await?;
let leases = get_leases(wakey_core::LeaseQuery {
include_state: false,
})
.await?;
let leases = get_leases().await?;
let observations = match wakey_linux::dhcp::list_local_observations().await {
Ok(observations) => observations
.into_iter()
+12 -6
View File
@@ -1,16 +1,22 @@
use anyhow::{Context, Result};
use wakey_core::{DhcpLease, DhcpLeaseWithState, LeaseQuery};
use wakey_core::{DhcpLease, DhcpLeaseWithState};
/// Read DHCP leases and optionally enrich them with current neighbor-state data.
pub async fn get_leases(query: LeaseQuery) -> Result<Vec<DhcpLeaseWithState>> {
/// Read DHCP leases from dnsmasq plus remembered hook names.
pub async fn get_leases() -> Result<Vec<DhcpLeaseWithState>> {
let leases = wakey_linux::dhcp::read_dhcp_leases_with_names()
.await
.context("failed to read DHCP leases")?;
if query.include_state {
Ok(wakey_linux::dhcp::enrich_leases_with_nud_state(leases).await)
} else {
Ok(leases_without_state(leases))
}
/// Read DHCP leases and enrich them with current neighbor state.
///
/// Prefer inventory for device status; this exists for the legacy leases view.
pub async fn get_leases_with_neighbor_state() -> Result<Vec<DhcpLeaseWithState>> {
let leases = wakey_linux::dhcp::read_dhcp_leases_with_names()
.await
.context("failed to read DHCP leases")?;
Ok(wakey_linux::dhcp::enrich_leases_with_nud_state(leases).await)
}
/// Wrap raw DHCP leases in the current service output shape without neighbor state.
+1 -1
View File
@@ -9,7 +9,7 @@ pub use inventory::{
inventory, local_observation_to_fact, merge_devices, merge_devices_with_observations,
resolve_devices,
};
pub use leases::{get_leases, leases_without_state};
pub use leases::{get_leases, get_leases_with_neighbor_state, leases_without_state};
pub use query::{resolve_query, resolve_selector};
pub use wake::{
broadcast_wake_targets, resolve_wake_targets, wake_explicit, wake_from_query, wake_targets,
+1 -1
View File
@@ -293,7 +293,7 @@ function buildCommandPayload(
return { command: { kind: "devs", dev: null, up_only: false } };
}
if (kind === "leases") {
return { command: { kind: "leases", include_state: true } };
return { command: { kind: "leases", include_state: false } };
}
if (kind === "inventory") {
return {
+6 -1
View File
@@ -25,8 +25,13 @@ pub struct DhcpLeaseWithState {
pub nud_state: Option<NeighborState>,
}
/// Options for lease retrieval from the service layer.
/// Legacy options for lease retrieval from the service layer.
///
/// Prefer inventory for device state; lease rows are now best treated as a raw
/// dnsmasq snapshot.
#[deprecated(note = "prefer get_leases() or inventory; neighbor state belongs in inventory")]
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct LeaseQuery {
#[deprecated(note = "prefer inventory for device state")]
pub include_state: bool,
}
+3 -1
View File
@@ -6,7 +6,9 @@ mod query;
mod wake;
pub use device::{Device, DeviceId, DeviceInventory, DeviceObservationFact, Presence};
pub use dhcp::{DhcpLease, DhcpLeaseWithState, LeaseQuery};
#[allow(deprecated)]
pub use dhcp::LeaseQuery;
pub use dhcp::{DhcpLease, DhcpLeaseWithState};
pub use interface::{InterfaceAddr, InterfaceSummary};
pub use neighbor::{NeighborEntry, NeighborParseError, NeighborState, parse_neighbor_line};
pub use query::{InventoryQuery, InventoryQueryBuilder, NamePath, Query, QueryInput};
+1 -3
View File
@@ -109,9 +109,7 @@ pub async fn list_local_observations_from_path(
Ok(list_local_observations_from_store(store))
}
fn list_local_observations_from_store(
store: LocalObservationStore,
) -> Vec<LocalDeviceObservation> {
fn list_local_observations_from_store(store: LocalObservationStore) -> Vec<LocalDeviceObservation> {
let mut out = Vec::with_capacity(store.dhcp_clients.len() + store.neighbors.len());
out.extend(
store