aranet_cli/lib.rs
1#![deny(unsafe_code)]
2
3//! Command-line interface for Aranet environmental sensors.
4//!
5//! This crate provides a comprehensive CLI for interacting with Aranet devices
6//! including the Aranet4, Aranet2, AranetRn+ (Radon), and Aranet Radiation sensors.
7//!
8//! # Features
9//!
10//! - **Device scanning**: Discover nearby Aranet devices via BLE
11//! - **Current readings**: Display real-time sensor values with color-coded status
12//! - **Historical data**: Download and export measurement history
13//! - **Device configuration**: Adjust measurement interval, Bluetooth range, and Smart Home mode
14//! - **Continuous monitoring**: Watch mode for ongoing data collection
15//! - **Multiple output formats**: Text, JSON, and CSV output support
16//! - **Configuration file**: Persistent settings for default device and preferences
17//! - **Shell completions**: Generate completions for bash, zsh, fish, and PowerShell
18//!
19//! # Commands
20//!
21//! | Command | Description |
22//! |---------|-------------|
23//! | `scan` | Scan for nearby Aranet devices |
24//! | `read` | Read current sensor values |
25//! | `status` | Quick one-line status display |
26//! | `history` | Download historical data |
27//! | `info` | Display device information |
28//! | `set` | Configure device settings |
29//! | `watch` | Continuously monitor a device |
30//! | `config` | Manage CLI configuration |
31//! | `alias` | Manage device aliases |
32//! | `sync` | Sync history to the local cache |
33//! | `cache` | Query cached data |
34//! | `report` | Summarize cached history |
35//! | `doctor` | Run Bluetooth diagnostics |
36//! | `completions` | Generate shell completions |
37//!
38//! # Output Formats
39//!
40//! The CLI supports three output formats:
41//!
42//! - **Text** (default): Human-readable colored output
43//! - **JSON**: Machine-readable JSON format
44//! - **CSV**: Comma-separated values for spreadsheets and data analysis
45//!
46//! # Configuration
47//!
48//! The CLI stores configuration in `~/.config/aranet/config.toml` (or platform equivalent).
49//! Configuration options include:
50//!
51//! - `device`: Default device address
52//! - `format`: Default output format
53//! - `no_color`: Disable colored output
54//! - `fahrenheit`: Use Fahrenheit for temperature display
55//!
56//! # Environment Variables
57//!
58//! - `ARANET_DEVICE`: Default device address (overridden by `--device` flag)
59//! - `NO_COLOR`: Disable colored output when set
60//!
61//! # Examples
62//!
63//! Scan for devices:
64//! ```bash
65//! aranet scan
66//! ```
67//!
68//! Read current values from a specific device:
69//! ```bash
70//! aranet read --device AA:BB:CC:DD:EE:FF
71//! ```
72//!
73//! Download history as CSV:
74//! ```bash
75//! aranet history --device AA:BB:CC:DD:EE:FF --format csv --output data.csv
76//! ```
77//!
78//! Watch a device continuously:
79//! ```bash
80//! aranet watch --device AA:BB:CC:DD:EE:FF --interval 60
81//! ```
82//!
83//! Set measurement interval:
84//! ```bash
85//! aranet set --device AA:BB:CC:DD:EE:FF interval 5
86//! ```
87
88// This crate is primarily a binary CLI application.
89// The main entry point and command implementations are in main.rs.
90// This lib.rs serves as documentation and could be extended to expose
91// public APIs for programmatic use if needed in the future.
92
93// Re-export core dependencies for convenience
94pub use aranet_core;
95pub use aranet_types;
96
97/// Get the current local time formatted with the given `time` format description string.
98///
99/// Falls back to UTC if the local timezone cannot be determined.
100pub fn local_now_fmt(fmt: &str) -> String {
101 let now = time::OffsetDateTime::now_local().unwrap_or_else(|_| time::OffsetDateTime::now_utc());
102 let format = time::format_description::parse(fmt).unwrap_or_default();
103 now.format(&format).unwrap_or_default()
104}
105
106// Config module - needed by both TUI and GUI
107pub mod config;
108
109// TUI module - publicly exposed for aranet-tui crate to use
110#[cfg(feature = "tui")]
111pub mod tui;
112
113// GUI module - publicly exposed for aranet-gui crate to use
114#[cfg(feature = "gui")]
115pub mod gui;