Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix clippy warnings #24

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 40 additions & 14 deletions core/src/action.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use std::str::FromStr;
use std::{
fmt::{Debug, Display},
str::FromStr,
};

use clap::{Parser, ValueEnum};
use thiserror::Error;
use strum::{Display, EnumIter};
use thiserror::Error;

#[derive(Debug, Parser)]
pub enum Action {
Expand Down Expand Up @@ -44,7 +47,7 @@ pub enum Action {
pub enum SystemCommand {
Poweroff,
Restart,
Halt
Halt,
}

impl FromStr for Action {
Expand Down Expand Up @@ -78,18 +81,41 @@ impl FromStr for Action {
}
}

impl ToString for Action {
fn to_string(&self) -> String {
impl Display for Action {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Action::Kill { task, force: false } => format!("kill {task}"),
Action::Kill { task, force: true } => format!("force-kill {task}"),
Action::Deactivate { task, force: false } => format!("deactivate {task}"),
Action::Deactivate { task, force: true } => format!("force-deactivate {task}"),
Action::Start { task, force: false } => format!("start {task}"),
Action::Start { task, force: true } => format!("force-start {task}"),
Action::Restart { task, force: false } => format!("restart {task}"),
Action::Restart { task, force: true } => format!("force-restart {task}"),
Action::System { command } => format!("system {command}"),
Action::Kill { task, force } => {
if *force {
f.write_str("force-")?;
}
f.write_str("kill ")?;
f.write_str(task)
}
Action::Deactivate { task, force } => {
if *force {
f.write_str("force-")?;
}
f.write_str("deactivate ")?;
f.write_str(task)
}
Action::Start { task, force } => {
if *force {
f.write_str("force-")?;
}
f.write_str("start")?;
f.write_str(task)
}
Action::Restart { task, force } => {
if *force {
f.write_str("force-")?;
}
f.write_str("restart ")?;
f.write_str(task)
}
Action::System { command } => {
f.write_str("system ")?;
Display::fmt(command, f)
}
}
}
}
Expand Down
20 changes: 9 additions & 11 deletions core/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,19 @@ pub struct Alfad {
}

impl Alfad {
pub fn run(self) -> Result<()>{
pub fn run(self) -> Result<()> {
let mut signals = SignalsInfo::<WithOrigin>::new(SIGS).unwrap();

smol::spawn(async move {
while let Some(sig) = signals.next().await {
match sig {
Origin {
signal: SIGCHLD,
process: Some(proc),
..
} => {
// Ignore Err(_) since ECHILD is expected
waitpid(Some(Pid::from_raw(proc.pid)), None).ok();
}
_ => {}
if let Origin {
signal: SIGCHLD,
process: Some(proc),
..
} = sig
{
// Ignore Err(_) since ECHILD is expected
waitpid(Some(Pid::from_raw(proc.pid)), None).ok();
}
}
})
Expand Down
Loading