mirror of
https://github.com/apple/container.git
synced 2026-09-23 16:15:37 +00:00
Validate container system logs --last flag (#1561)
- Closes #1530. ## Type of Change - [x] Bug fix - [ ] New feature - [ ] Breaking change - [ ] Documentation update ## Motivation and Context Reject invalid `--last` values in system logs, matching the format accepted by `log show`. ## Testing - [x] Tested locally - [x] Added/updated tests - [x] Added/updated docs
This commit is contained in:
@@ -35,7 +35,7 @@ extension Application {
|
||||
|
||||
@Option(
|
||||
name: .long,
|
||||
help: "Fetch logs starting from the specified time period (minus the current time); supported formats: m, h, d"
|
||||
help: "Fetch logs starting from the specified time period (minus the current time); supported formats: <number>[m|h|d] (defaults to seconds)"
|
||||
)
|
||||
var last: String = "5m"
|
||||
|
||||
@@ -44,6 +44,19 @@ extension Application {
|
||||
|
||||
public init() {}
|
||||
|
||||
public func validate() throws {
|
||||
if follow { return }
|
||||
if let value = Int(last), value > 0 { return }
|
||||
guard let unit = last.last, "mhd".contains(unit),
|
||||
let value = Int(last.dropLast()), value > 0
|
||||
else {
|
||||
throw ContainerizationError(
|
||||
.invalidArgument,
|
||||
message: "invalid --last value '\(last)': expected a positive integer (seconds) or a value with suffix m, h, or d (e.g. 30, 5m, 1h, 2d)"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
public func run() async throws {
|
||||
let process = Process()
|
||||
let sigHandler = AsyncSignalHandler.create(notify: [SIGINT, SIGTERM])
|
||||
|
||||
Reference in New Issue
Block a user