Add print version

This commit is contained in:
Adrian Woźniak 2021-07-03 23:34:22 +02:00
parent be1cf97349
commit b39057c243
No known key found for this signature in database
GPG Key ID: DE43476F72AD3F6C

View File

@ -180,7 +180,7 @@ pub struct Service {
#[derive(Debug, Options)] #[derive(Debug, Options)]
pub struct Switcher { pub struct Switcher {
#[options(help = "Help message")] #[options(help = "Print help message")]
help: bool, help: bool,
#[options(help = "GPU Card number")] #[options(help = "GPU Card number")]
card: Option<u32>, card: Option<u32>,
@ -210,6 +210,8 @@ pub enum Command {
pub struct Opts { pub struct Opts {
#[options(help = "Help message")] #[options(help = "Help message")]
help: bool, help: bool,
#[options(help = "Print version")]
version: bool,
#[options(command)] #[options(command)]
command: Option<Command>, command: Option<Command>,
} }
@ -352,20 +354,17 @@ fn main() -> std::io::Result<()> {
let opts: Opts = Opts::parse_args_default_or_exit(); let opts: Opts = Opts::parse_args_default_or_exit();
if opts.version {
println!("{}", env!("CARGO_PKG_VERSION"));
std::process::exit(0);
}
match opts.command { match opts.command {
None => return Ok(()), None => service(config),
Some(Command::Monitor(_)) => { Some(Command::Monitor(_)) => monitor_cards(config),
monitor_cards(config)?; Some(Command::Service(_)) => service(config),
} Some(Command::SetAutomatic(switcher)) => change_mode(switcher, FanMode::Automatic, config),
Some(Command::Service(_)) => { Some(Command::SetManual(switcher)) => change_mode(switcher, FanMode::Manual, config),
service(config)?;
}
Some(Command::SetAutomatic(switcher)) => {
change_mode(switcher, FanMode::Automatic, config)?;
}
Some(Command::SetManual(switcher)) => {
change_mode(switcher, FanMode::Manual, config)?;
}
Some(Command::Available(_)) => { Some(Command::Available(_)) => {
println!("Available cards"); println!("Available cards");
controllers(&config, false)?.into_iter().for_each(|card| { controllers(&config, false)?.into_iter().for_each(|card| {
@ -375,8 +374,7 @@ fn main() -> std::io::Result<()> {
card.hw_mon.name().unwrap_or_default() card.hw_mon.name().unwrap_or_default()
); );
}); });
}
}
Ok(()) Ok(())
} }
}
}