Skip to content

Commit

Permalink
Make Clippy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
unflxw committed Nov 4, 2024
1 parent 28dd446 commit e29909e
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 35 deletions.
18 changes: 7 additions & 11 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ impl Cli {
warnings
}

pub fn warn(&self) -> () {
pub fn warn(&self) {
for warning in self.warnings() {
warn!("{}", warning);
}
Expand Down Expand Up @@ -288,8 +288,7 @@ mod tests {

#[test]
fn cli_warnings_log_and_no_log() {
for (args, warning) in vec![
(
for (args, warning) in [(
vec!["--log", "some-group", "--no-log"],
"using --no-log alongside --log; no logs will be sent to AppSignal"
),
Expand All @@ -304,8 +303,7 @@ mod tests {
(
vec!["--log-source", "some-log-source", "--no-stdout", "--no-stderr"],
"using --no-stdout and --no-stderr alongside --log-source; no logs will be sent to AppSignal"
),
] {
)] {
let cli = Cli::try_parse_from(
with_required_args(args)
).expect("failed to parse CLI arguments");
Expand All @@ -322,16 +320,14 @@ mod tests {

#[test]
fn cli_warnings_no_log_and_no_checkins() {
for (args, warning) in vec![
(
for (args, warning) in [(
vec!["--no-log"],
"using --no-log without either --cron or --heartbeat; no data will be sent to AppSignal"
),
(
vec!["--no-stdout", "--no-stderr"],
"using --no-stdout and --no-stderr without either --cron or --heartbeat; no data will be sent to AppSignal"
),
] {
)] {
let cli = Cli::try_parse_from(
with_required_args(args)

Expand Down Expand Up @@ -368,7 +364,7 @@ mod tests {

#[test]
fn cli_log_config_no_log_options() {
for (args, origin) in vec![
for (args, origin) in [
(vec!["--no-log"], LogOrigin::None),
(vec!["--no-stdout", "--no-stderr"], LogOrigin::None),
(vec!["--no-stdout"], LogOrigin::Stderr),
Expand All @@ -385,7 +381,7 @@ mod tests {

#[test]
fn cli_check_in_config() {
for (args, cron, heartbeat) in vec![
for (args, cron, heartbeat) in [
(
vec![
"--cron",
Expand Down
4 changes: 2 additions & 2 deletions src/exit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// See: https://gitlab.com/nbdkit/nbdkit/-/blob/master/common/utils/exit-with-parent.c

#[cfg(target_os = "linux")]
fn set_exit_with_parent() -> () {
fn set_exit_with_parent() {
use libc::{c_int, c_long, SIGTERM};

extern "C" {
Expand All @@ -17,7 +17,7 @@ fn set_exit_with_parent() -> () {
}

#[cfg(target_os = "macos")]
fn set_exit_with_parent() -> () {
fn set_exit_with_parent() {
// macOS does not have the `prctl` function, so we do nothing.
// This means that the child process will not be terminated when
// the parent process exits.
Expand Down
12 changes: 3 additions & 9 deletions src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use serde::Serialize;

use crate::client::client;
use crate::ndjson;
use crate::timestamp::Timestamp;
use crate::package::NAME;
use crate::timestamp::Timestamp;

pub struct LogConfig {
pub api_key: String,
Expand Down Expand Up @@ -52,17 +52,11 @@ impl LogOrigin {
}

pub fn is_out(&self) -> bool {
match self {
Self::Stdout | Self::All => true,
_ => false,
}
matches!(self, Self::Stdout | Self::All)
}

pub fn is_err(&self) -> bool {
match self {
Self::Stderr | Self::All => true,
_ => false,
}
matches!(self, Self::Stderr | Self::All)
}
}

Expand Down
16 changes: 8 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ mod log;
mod client;
mod exit;
mod ndjson;
mod package;
mod signals;
mod timestamp;
mod package;

use crate::check_in::{CronKind, HeartbeatConfig};
use crate::cli::Cli;
use crate::client::client;
use crate::log::{LogConfig, LogMessage, LogSeverity};
use crate::package::NAME;
use crate::signals::{has_terminating_intent, reset_sigpipe, signal_stream};
use crate::timestamp::SystemTimestamp;
use crate::package::NAME;

use ::log::{debug, error, trace};
use std::os::unix::process::ExitStatusExt;
Expand Down Expand Up @@ -56,7 +56,7 @@ fn main() {
}
}

fn command(argv: &Vec<String>, log: &LogConfig) -> Command {
fn command(argv: &[String], log: &LogConfig) -> Command {
let mut command = Command::new(argv[0].clone());
for arg in argv[1..].iter() {
command.arg(arg);
Expand Down Expand Up @@ -114,7 +114,7 @@ async fn pipe_lines(
}
}

async fn send_request(request: Result<reqwest::Request, reqwest::Error>) -> () {
async fn send_request(request: Result<reqwest::Request, reqwest::Error>) {
let request = match request {
Ok(request) => request,
Err(err) => {
Expand Down Expand Up @@ -181,7 +181,7 @@ async fn log_loop(

loop {
if messages.len() >= 100 {
let request = log.request(messages.drain(..).collect());
let request = log.request(std::mem::take(&mut messages));
tasks.spawn(send_request(request));
interval.reset();
}
Expand Down Expand Up @@ -220,8 +220,8 @@ async fn log_loop(
break;
}

if messages.len() > 0 {
let request = log.request(messages.drain(..).collect());
if !messages.is_empty() {
let request = log.request(std::mem::take(&mut messages));
tasks.spawn(send_request(request));
}
}
Expand All @@ -230,7 +230,7 @@ async fn log_loop(
}
}

if messages.len() > 0 {
if !messages.is_empty() {
let request = log.request(messages);
tasks.spawn(send_request(request));
}
Expand Down
7 changes: 2 additions & 5 deletions src/signals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,15 @@ const CHILD_FORWARDABLE_SIGNALS: [Signal; 8] = [
// The objective is to ensure that only signals which were sent with the explicit
// intent to terminate the child process cause this process to terminate.
pub fn has_terminating_intent(signal: &Signal) -> bool {
match signal {
Signal::SIGINT | Signal::SIGTERM | Signal::SIGQUIT => true,
_ => false,
}
matches!(signal, Signal::SIGINT | Signal::SIGTERM | Signal::SIGQUIT)
}

pub fn signal_stream() -> io::Result<impl Stream<Item = Signal>> {
let mut signals = StreamMap::new();

for nix_signal in &CHILD_FORWARDABLE_SIGNALS {
signals.insert(
nix_signal.clone(),
*nix_signal,
SignalStream::new(signal(nix_to_tokio(nix_signal))?),
);
}
Expand Down

0 comments on commit e29909e

Please sign in to comment.