Skip to content

Commit 7afae0d

Browse files
authored
Use clap for better looking help messages (#187)
* Use clap as argument parser * Fixed formatting
1 parent a7f4998 commit 7afae0d

File tree

8 files changed

+443
-600
lines changed

8 files changed

+443
-600
lines changed

Cargo.lock

Lines changed: 122 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,4 @@ async-channel = "2.5.0"
4848
mpris = "2.0.1"
4949
runtime-format = "0.1.3"
5050
strfmt = "0.2.4"
51+
clap = { version = "4.5.53", features = ["derive"] }

src/args.rs

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
use clap::Parser;
2+
use std::path::PathBuf;
3+
4+
#[derive(Parser)]
5+
#[command(version, about, long_about = None)]
6+
#[command(arg_required_else_help(false))]
7+
pub struct ArgsServer {
8+
/// Use a custom config file instead of looking for one.
9+
#[arg(long, value_name = "Config File Path")]
10+
pub config: Option<PathBuf>,
11+
12+
/// Use a custom Stylesheet file instead of looking for one
13+
#[arg(long, short, value_name = "CSS File Path")]
14+
pub style: Option<PathBuf>,
15+
16+
/// OSD margin from top edge (0.5 would be screen center). Default is 0.85
17+
#[arg(long, value_name = "from 0.0 to 1.0")]
18+
pub top_margin: Option<String>,
19+
}
20+
21+
#[derive(Parser)]
22+
#[command(version, about, long_about = None)]
23+
#[command(arg_required_else_help(true))]
24+
pub struct ArgsClient {
25+
/// Use a custom config file instead of looking for one.
26+
#[arg(long, value_name = "Config File Path")]
27+
pub config: Option<PathBuf>,
28+
29+
/// Which monitor to display osd on
30+
#[arg(long, value_name = "Monitor identifier (e.g., HDMI-A-1, DP-1)")]
31+
pub monitor: Option<String>,
32+
33+
/// Shows capslock osd. Note: Doesn't toggle CapsLock, just displays the status
34+
#[arg(long, default_value_t = false)]
35+
pub caps_lock: bool,
36+
37+
/// Shows capslock osd. Uses LED class NAME.
38+
/// Note: Doesn't toggle CapsLock, just displays the status
39+
#[arg(long, value_name = "LED class name (/sys/class/leds/NAME)")]
40+
pub caps_lock_led: Option<String>,
41+
42+
/// Shows numlock osd. Note: Doesn't toggle NumLock, just displays the status
43+
#[arg(long, default_value_t = false)]
44+
pub num_lock: bool,
45+
46+
/// Shows numlock osd. Uses LED class NAME.
47+
/// Note: Doesn't toggle NumLock, just displays the status
48+
#[arg(long, value_name = "LED class name (/sys/class/leds/NAME)")]
49+
pub num_lock_led: Option<String>,
50+
51+
/// Shows scrolllock osd. Note: Doesn't toggle ScrollLock, just displays the status
52+
#[arg(long, default_value_t = false)]
53+
pub scroll_lock: bool,
54+
55+
/// Shows scrolllock osd. Uses LED class NAME.
56+
/// Note: Doesn't toggle ScrollLock, just displays the status",
57+
#[arg(long, value_name = "LED class name (/sys/class/leds/NAME)")]
58+
pub scroll_lock_led: Option<String>,
59+
60+
/// Shows volume osd and raises, loweres or mutes default sink volume
61+
#[arg(long, value_name = "raise|lower|mute-toggle|(±)number")]
62+
pub output_volume: Option<String>,
63+
64+
/// Shows volume osd and raises, loweres or mutes default source volume
65+
#[arg(long, value_name = "raise|lower|mute-toggle|(±)number")]
66+
pub input_volume: Option<String>,
67+
68+
/// Sets the maximum Volume
69+
#[arg(long, value_name = "(+)number")]
70+
pub max_volume: Option<String>,
71+
72+
/// For which device to increase/decrease audio
73+
#[arg(
74+
long,
75+
value_name = "Pulseaudio device name (pactl list short sinks|sources)"
76+
)]
77+
pub device: Option<String>,
78+
79+
/// Shows brightness osd and raises or loweres all available sources of brightness device
80+
#[arg(long, value_name = "raise|lower|(±)number")]
81+
pub brightness: Option<String>,
82+
83+
/// Sets the minimum Brightness
84+
#[arg(long, value_name = "(+)number")]
85+
pub min_brightness: Option<String>,
86+
87+
/// Shows Playerctl osd and runs the playerctl command
88+
#[arg(long, value_name = "play-pause|play|pause|stop|next|prev|shuffle")]
89+
pub playerctl: Option<String>,
90+
91+
/// For which player to run the playerctl commands
92+
#[arg(long, value_name = "auto|all|(playerctl -l)")]
93+
pub player: Option<String>,
94+
95+
/// Message to display
96+
#[arg(long, value_name = "text")]
97+
pub custom_message: Option<String>,
98+
99+
/// Icon to display when using custom-message/custom-progress.
100+
/// Icon name is from Freedesktop specification
101+
/// (https://specifications.freedesktop.org/icon-naming-spec/latest/)
102+
#[arg(long, value_name = "Icon name")]
103+
pub custom_icon: Option<String>,
104+
105+
/// Progress to display (0.0 <-> 1.0)
106+
#[arg(long, value_name = "Progress from 0.0 to 1.0")]
107+
pub custom_progress: Option<String>,
108+
109+
/// Segmented progress to display (value:num-segments). Ex: 2:4
110+
#[arg(long, value_name = "Progress from 0 to num-segments")]
111+
pub custom_segmented_progress: Option<String>,
112+
113+
/// Text to display when using custom-progress or custom-segmented-progress
114+
#[arg(long, value_name = "Progress text")]
115+
pub custom_progress_text: Option<String>,
116+
}

src/argtypes.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ pub enum ArgTypes {
1313
CustomProgressText = (i32::MIN + 6) as isize,
1414
MinBrightness = (i32::MIN + 7) as isize,
1515
// Other
16-
None = 0,
1716
CapsLock = 1,
1817
SinkVolumeRaise = 2,
1918
SinkVolumeLower = 3,
@@ -36,7 +35,6 @@ pub enum ArgTypes {
3635
impl fmt::Display for ArgTypes {
3736
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3837
let string = match self {
39-
ArgTypes::None => "NONE",
4038
ArgTypes::CapsLock => "CAPSLOCK",
4139
ArgTypes::MaxVolume => "MAX-VOLUME",
4240
ArgTypes::SinkVolumeRaise => "SINK-VOLUME-RAISE",

0 commit comments

Comments
 (0)