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
|
use std::{net::Ipv4Addr, path::PathBuf};
use clap::{Args, Parser, ValueEnum, ValueHint};
use clap_verbosity_flag::{InfoLevel, Verbosity};
use derivative::Derivative;
use strum::EnumIter;
#[derive(Clone, Debug, Derivative, Parser)]
#[derivative(Default)]
#[command(name = "bandwhich", version)]
pub struct Opt {
#[arg(short, long)]
/// The network interface to listen on, eg. eth0
pub interface: Option<String>,
#[arg(short, long)]
/// Machine friendlier output
pub raw: bool,
#[arg(short, long)]
/// Do not attempt to resolve IPs to their hostnames
pub no_resolve: bool,
#[arg(short, long)]
/// Show DNS queries
pub show_dns: bool,
#[arg(short, long)]
/// A dns server ip to use instead of the system default
pub dns_server: Option<Ipv4Addr>,
#[arg(long, value_hint = ValueHint::FilePath)]
/// Enable debug logging to a file
pub log_to: Option<PathBuf>,
#[command(flatten)]
#[derivative(Default(value = "Verbosity::new(0, 0)"))]
pub verbosity: Verbosity<InfoLevel>,
#[command(flatten)]
pub render_opts: RenderOpts,
}
#[derive(Copy, Clone, Debug, Default, Args)]
pub struct RenderOpts {
#[arg(short, long)]
/// Show processes table only
pub processes: bool,
#[arg(short, long)]
/// Show connections table only
pub connections: bool,
#[arg(short, long)]
/// Show remote addresses table only
pub addresses: bool,
#[arg(short, long, value_enum, default_value_t)]
/// Choose a specific family of units
pub unit_family: UnitFamily,
#[arg(short, long)]
/// Show total (cumulative) usages
pub total_utilization: bool,
}
// IMPRV: it would be nice if we can `#[cfg_attr(not(build), derive(strum::EnumIter))]` this
// unfortunately there is no configuration option for build script detection
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, ValueEnum, EnumIter)]
pub enum UnitFamily {
#[default]
/// bytes, in powers of 2^10
BinBytes,
/// bits, in powers of 2^10
BinBits,
/// bytes, in powers of 10^3
SiBytes,
/// bits, in powers of 10^3
SiBits,
}
|