feat(cli): show platform-specific options in help (#101)

This commit is contained in:
Marco Cadetg
2025-12-19 08:04:25 +01:00
committed by GitHub
parent 9089403d32
commit 4108b68625
2 changed files with 25 additions and 7 deletions

View File

@@ -126,6 +126,7 @@ The experimental eBPF support provides efficient process identification but has
- [x] **Help Screen**: Toggle help screen with keyboard shortcuts (h key)
- [x] **Clipboard Support**: Copy remote address to clipboard (c key)
- [x] **Service/Port Toggle**: Toggle between service names and port numbers (p key)
- [x] **Platform-Specific CLI Help**: Show only relevant options per platform (hide Linux sandbox options on macOS, hide PKTAP notes on Linux)
- [ ] **Resizable Columns**: Dynamic column width adjustment
- [ ] **Connection Grouping**: Group connections by process/service
- [ ] **ASCII Graphs**: Terminal-based graphs for bandwidth/packet visualization

View File

@@ -1,7 +1,19 @@
use clap::{Arg, Command};
#[cfg(target_os = "linux")]
const INTERFACE_HELP: &str = "Network interface to monitor (use \"any\" to capture all interfaces)";
#[cfg(not(target_os = "linux"))]
const INTERFACE_HELP: &str = "Network interface to monitor";
#[cfg(target_os = "macos")]
const BPF_HELP: &str = "BPF filter expression for packet capture (e.g., \"tcp port 443\"). Note: Using a BPF filter disables PKTAP (process info falls back to lsof)";
#[cfg(not(target_os = "macos"))]
const BPF_HELP: &str = "BPF filter expression for packet capture (e.g., \"tcp port 443\", \"dst port 80\")";
pub fn build_cli() -> Command {
Command::new("rustnet")
let cmd = Command::new("rustnet")
.version(env!("CARGO_PKG_VERSION"))
.author("Network Monitor")
.about("Cross-platform network monitoring tool")
@@ -10,7 +22,7 @@ pub fn build_cli() -> Command {
.short('i')
.long("interface")
.value_name("INTERFACE")
.help("Network interface to monitor")
.help(INTERFACE_HELP)
.required(false),
)
.arg(
@@ -61,20 +73,25 @@ pub fn build_cli() -> Command {
.short('f')
.long("bpf-filter")
.value_name("FILTER")
.help("BPF filter expression for packet capture (e.g., \"tcp port 443\", \"dst port 80\"). Note: On macOS, using a BPF filter disables PKTAP (process info falls back to lsof)")
.help(BPF_HELP)
.required(false),
)
);
#[cfg(target_os = "linux")]
let cmd = cmd
.arg(
Arg::new("no-sandbox")
.long("no-sandbox")
.help("Disable Landlock sandboxing (Linux only)")
.help("Disable Landlock sandboxing")
.action(clap::ArgAction::SetTrue),
)
.arg(
Arg::new("sandbox-strict")
.long("sandbox-strict")
.help("Require full sandbox enforcement or exit (Linux only)")
.help("Require full sandbox enforcement or exit")
.action(clap::ArgAction::SetTrue)
.conflicts_with("no-sandbox"),
)
);
cmd
}