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

Validate monitors run command's --timezone argument #1847

Merged
merged 3 commits into from
Nov 29, 2023
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
122 changes: 85 additions & 37 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ backtrace = "0.3.67"
brotli2 = "0.3.2"
bytecount = "0.6.3"
chardet = "0.2.4"
chrono = { version = "0.4.23", features = ["serde"] }
chrono = { version = "0.4.31", features = ["serde"] }
clap = { version = "4.1.6", default-features = false, features = [
"std",
"suggestions",
Expand Down Expand Up @@ -77,6 +77,7 @@ which = "4.4.0"
zip = "0.6.4"
data-encoding = "2.3.3"
magic_string = "0.3.4"
chrono-tz = "0.8.4"

[dev-dependencies]
insta = { version = "1.26.0", features = ["redactions", "yaml"] }
Expand Down
11 changes: 9 additions & 2 deletions src/commands/monitors/run.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use chrono_tz::Tz;
use log::warn;
use std::process;
use std::time::{Duration, Instant};
Expand Down Expand Up @@ -73,10 +74,16 @@ pub fn make_command(command: Command) -> Command {
.arg(
Arg::new("timezone")
.long("timezone")
.value_parser(|value: &str| {
value.parse::<Tz>().map_err(|err| {
err + "\n\tSee here for a list of valid timezone strings: \
https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List"
})
})
.requires("schedule")
.help(
"A tz database string (e.g. \"Europe/Vienna\") representing the monitor's \
execution schedule's timezone. Requires --schedule.",
execution schedule's timezone. Requires --schedule.",
),
)
}
Expand Down Expand Up @@ -202,7 +209,7 @@ fn parse_monitor_config_args(matches: &ArgMatches) -> Result<Option<MonitorConfi
schedule,
checkin_margin: matches.get_one("checkin_margin").copied(),
max_runtime: matches.get_one("max_runtime").copied(),
timezone: matches.get_one("timezone").cloned(),
timezone: matches.get_one("timezone").map(Tz::to_string),
}))
}

Expand Down
Loading