Skip to content

Commit c28927d

Browse files
committed
address review feedback
1 parent a9d19ac commit c28927d

2 files changed

Lines changed: 44 additions & 52 deletions

File tree

Sources/ContainerCommands/Flags+ProgressConfig.swift

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,11 @@ import Foundation
1919
import TerminalProgress
2020

2121
extension Flags.Progress {
22-
/// Resolves `.auto` into `.ansi` or `.plain` based on the terminal.
23-
///
24-
/// When the progress type is `.auto`, the terminal file handle is checked
25-
/// with `isatty`. If the output is a TTY, `.ansi` is used; otherwise
26-
/// `.plain` is selected so that piped or redirected output still shows
27-
/// simple line-by-line status text.
28-
private func resolvedProgress(terminal: FileHandle = .standardError) -> ProgressType {
22+
/// Resolves `.auto` into `.ansi` or `.plain` based on whether stderr is a TTY.
23+
private func resolvedProgress() -> ProgressType {
2924
switch progress {
3025
case .auto:
31-
return isatty(terminal.fileDescriptor) == 1 ? .ansi : .plain
26+
return isatty(FileHandle.standardError.fileDescriptor) == 1 ? .ansi : .plain
3227
case .none, .ansi, .plain:
3328
return progress
3429
}

Tests/CLITests/Subcommands/Images/TestCLIProgressAuto.swift

Lines changed: 41 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -19,55 +19,52 @@ import Testing
1919

2020
class TestCLIProgressAuto: CLITest {
2121
@Test func testAutoProgressFallsBackToPlainWhenPiped() throws {
22-
do {
23-
let (_, _, error, status) = try run(arguments: [
24-
"image", "pull",
25-
"--progress", "auto",
26-
alpine,
27-
])
28-
#expect(status == 0, "image pull should succeed, stderr: \(error)")
29-
let lines = error.components(separatedBy: .newlines)
30-
.filter { !$0.contains("Warning! Running debug build") && !$0.isEmpty }
31-
#expect(!lines.isEmpty, "expected plain progress output on stderr when piped")
32-
#expect(!error.contains("\u{1B}["), "expected no ANSI escapes in piped output")
33-
} catch {
34-
Issue.record("failed to test auto progress: \(error)")
35-
return
36-
}
22+
let (_, _, error, status) = try run(arguments: [
23+
"image", "pull",
24+
"--progress", "auto",
25+
alpine,
26+
])
27+
#expect(status == 0, "image pull should succeed, stderr: \(error)")
28+
let lines = error.components(separatedBy: .newlines)
29+
.filter { !$0.contains("Warning! Running debug build") && !$0.isEmpty }
30+
#expect(!lines.isEmpty, "expected plain progress output on stderr when piped")
31+
#expect(!error.contains("\u{1B}["), "expected no ANSI escapes in piped output")
3732
}
3833

3934
@Test func testExplicitPlainProgress() throws {
40-
do {
41-
let (_, _, error, status) = try run(arguments: [
42-
"image", "pull",
43-
"--progress", "plain",
44-
alpine,
45-
])
46-
#expect(status == 0, "image pull --progress plain should succeed, stderr: \(error)")
47-
let lines = error.components(separatedBy: .newlines)
48-
.filter { !$0.contains("Warning! Running debug build") && !$0.isEmpty }
49-
#expect(!lines.isEmpty, "expected plain progress output on stderr")
50-
#expect(!error.contains("\u{1B}["), "expected no ANSI escapes with --progress plain")
51-
} catch {
52-
Issue.record("failed to test plain progress: \(error)")
53-
return
54-
}
35+
let (_, _, error, status) = try run(arguments: [
36+
"image", "pull",
37+
"--progress", "plain",
38+
alpine,
39+
])
40+
#expect(status == 0, "image pull --progress plain should succeed, stderr: \(error)")
41+
let lines = error.components(separatedBy: .newlines)
42+
.filter { !$0.contains("Warning! Running debug build") && !$0.isEmpty }
43+
#expect(!lines.isEmpty, "expected plain progress output on stderr")
44+
#expect(!error.contains("\u{1B}["), "expected no ANSI escapes with --progress plain")
45+
}
46+
47+
@Test func testExplicitAnsiProgress() throws {
48+
let (_, _, error, status) = try run(arguments: [
49+
"image", "pull",
50+
"--progress", "ansi",
51+
alpine,
52+
])
53+
#expect(status == 0, "image pull --progress ansi should succeed, stderr: \(error)")
54+
let lines = error.components(separatedBy: .newlines)
55+
.filter { !$0.contains("Warning! Running debug build") && !$0.isEmpty }
56+
#expect(!lines.isEmpty, "expected ansi progress output on stderr")
5557
}
5658

5759
@Test func testNoneProgressSuppressesOutput() throws {
58-
do {
59-
let (_, _, error, status) = try run(arguments: [
60-
"image", "pull",
61-
"--progress", "none",
62-
alpine,
63-
])
64-
#expect(status == 0, "image pull --progress none should succeed, stderr: \(error)")
65-
let lines = error.components(separatedBy: .newlines)
66-
.filter { !$0.contains("Warning! Running debug build") && !$0.isEmpty }
67-
#expect(lines.isEmpty, "expected no progress output on stderr with --progress none")
68-
} catch {
69-
Issue.record("failed to test none progress: \(error)")
70-
return
71-
}
60+
let (_, _, error, status) = try run(arguments: [
61+
"image", "pull",
62+
"--progress", "none",
63+
alpine,
64+
])
65+
#expect(status == 0, "image pull --progress none should succeed, stderr: \(error)")
66+
let lines = error.components(separatedBy: .newlines)
67+
.filter { !$0.contains("Warning! Running debug build") && !$0.isEmpty }
68+
#expect(lines.isEmpty, "expected no progress output on stderr with --progress none")
7269
}
7370
}

0 commit comments

Comments
 (0)