Skip to content

Commit cd7c3a1

Browse files
authored
[options]: Replace --disable-progress-updates with --progress (none | ansi) (#808)
Part 1 of #641
1 parent 745cc18 commit cd7c3a1

File tree

7 files changed

+42
-43
lines changed

7 files changed

+42
-43
lines changed

Sources/ContainerClient/Flags.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,12 @@ public struct Flags {
204204
public struct Progress: ParsableArguments {
205205
public init() {}
206206

207-
public init(disableProgressUpdates: Bool) {
208-
self.disableProgressUpdates = disableProgressUpdates
207+
public enum ProgressType: String, ExpressibleByArgument {
208+
case none
209+
case ansi
209210
}
210211

211-
@Flag(name: .long, help: "Disable progress bar updates")
212-
public var disableProgressUpdates = false
212+
@Option(name: .long, help: ArgumentHelp("Progress type (format: none|ansi)", valueName: "type"))
213+
public var progress: ProgressType = .ansi
213214
}
214215
}

Sources/ContainerCommands/Container/ContainerRun.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ extension Application {
6161
let id = Utility.createContainerID(name: self.managementFlags.name)
6262

6363
var progressConfig: ProgressConfig
64-
if progressFlags.disableProgressUpdates {
65-
progressConfig = try ProgressConfig(disableProgressUpdates: progressFlags.disableProgressUpdates)
66-
} else {
64+
switch self.progressFlags.progress {
65+
case .none: progressConfig = try ProgressConfig(disableProgressUpdates: true)
66+
case .ansi:
6767
progressConfig = try ProgressConfig(
6868
showTasks: true,
6969
showItems: true,

Sources/ContainerCommands/Image/ImagePull.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import ArgumentParser
1818
import ContainerClient
1919
import Containerization
20-
import ContainerizationError
2120
import ContainerizationOCI
2221
import TerminalProgress
2322

@@ -57,10 +56,9 @@ extension Application {
5756

5857
public init() {}
5958

60-
public init(platform: String? = nil, scheme: String = "auto", reference: String, disableProgress: Bool = false) {
59+
public init(platform: String? = nil, scheme: String = "auto", reference: String) {
6160
self.global = Flags.Global()
6261
self.registry = Flags.Registry(scheme: scheme)
63-
self.progressFlags = Flags.Progress(disableProgressUpdates: disableProgress)
6462
self.platform = platform
6563
self.reference = reference
6664
}
@@ -80,9 +78,9 @@ extension Application {
8078
let processedReference = try ClientImage.normalizeReference(reference)
8179

8280
var progressConfig: ProgressConfig
83-
if self.progressFlags.disableProgressUpdates {
84-
progressConfig = try ProgressConfig(disableProgressUpdates: self.progressFlags.disableProgressUpdates)
85-
} else {
81+
switch self.progressFlags.progress {
82+
case .none: progressConfig = try ProgressConfig(disableProgressUpdates: true)
83+
case .ansi:
8684
progressConfig = try ProgressConfig(
8785
showTasks: true,
8886
showItems: true,

Sources/ContainerCommands/Image/ImagePush.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ extension Application {
6868
let image = try await ClientImage.get(reference: reference)
6969

7070
var progressConfig: ProgressConfig
71-
if progressFlags.disableProgressUpdates {
72-
progressConfig = try ProgressConfig(disableProgressUpdates: progressFlags.disableProgressUpdates)
73-
} else {
71+
switch self.progressFlags.progress {
72+
case .none: progressConfig = try ProgressConfig(disableProgressUpdates: true)
73+
case .ansi:
7474
progressConfig = try ProgressConfig(
7575
description: "Pushing image \(image.reference)",
7676
itemsName: "blobs",
@@ -79,6 +79,7 @@ extension Application {
7979
ignoreSmallSize: true
8080
)
8181
}
82+
8283
let progress = ProgressBar(config: progressConfig)
8384
defer {
8485
progress.finish()

Tests/CLITests/Subcommands/Build/CLIRunBase.swift

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,28 @@ class TestCLIRunBase: CLITest {
2222
var terminal: Terminal!
2323
var containerName: String = UUID().uuidString
2424

25-
var ContainerImage: String {
25+
var containerImage: String {
2626
fatalError("Subclasses must override this property")
2727
}
2828

29-
var Interactive: Bool {
29+
var interactive: Bool {
3030
false
3131
}
3232

33-
var Tty: Bool {
33+
var tty: Bool {
3434
false
3535
}
3636

37-
var Entrypoint: String? {
37+
var entrypoint: String? {
3838
nil
3939
}
4040

41-
var Command: [String]? {
41+
var command: [String]? {
4242
nil
4343
}
4444

45-
var DisableProgressUpdates: Bool {
46-
false
45+
var progress: String {
46+
"ansi"
4747
}
4848

4949
override init() throws {
@@ -108,24 +108,23 @@ class TestCLIRunBase: CLITest {
108108
name,
109109
]
110110

111-
if Interactive && Tty {
111+
if interactive && tty {
112112
arguments.append("-it")
113113
} else {
114-
if Interactive { arguments.append("-i") }
115-
if Tty { arguments.append("-t") }
114+
if interactive { arguments.append("-i") }
115+
if tty { arguments.append("-t") }
116116
}
117117

118-
if DisableProgressUpdates {
119-
arguments.append("--disable-progress-updates")
120-
}
118+
arguments.append("--progress")
119+
arguments.append(progress)
121120

122-
if let entrypoint = Entrypoint {
121+
if let entrypoint = entrypoint {
123122
arguments += ["--entrypoint", entrypoint]
124123
}
125124

126-
arguments.append(ContainerImage)
125+
arguments.append(containerImage)
127126

128-
if let command = Command {
127+
if let command = command {
129128
arguments += command
130129
}
131130
return try runInteractive(arguments: arguments)

Tests/CLITests/Subcommands/Build/TestCLITermIO.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,24 @@ import Testing
2020

2121
extension TestCLIRunBase {
2222
class TestCLITermIO: TestCLIRunBase {
23-
override var ContainerImage: String {
23+
override var containerImage: String {
2424
"ghcr.io/linuxcontainers/alpine:3.20"
2525
}
2626

27-
override var Interactive: Bool {
27+
override var interactive: Bool {
2828
true
2929
}
3030

31-
override var Tty: Bool {
31+
override var tty: Bool {
3232
true
3333
}
3434

35-
override var Command: [String]? {
35+
override var command: [String]? {
3636
["/bin/sh"]
3737
}
3838

39-
override var DisableProgressUpdates: Bool {
40-
true
39+
override var progress: String {
40+
"none"
4141
}
4242

4343
@Test func testTermIODoesNotPanic() async throws {

docs/command-reference.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ container run [<options>] <image> [<arguments> ...]
7979

8080
**Progress Options**
8181

82-
* `--disable-progress-updates`: Disable progress bar updates
82+
* `--progress <type>`: Progress type (format: none|ansi) (default: ansi)
8383

8484
**Examples**
8585

@@ -395,7 +395,7 @@ Pulls an image from a registry. Supports specifying a platform and controlling p
395395
**Usage**
396396

397397
```bash
398-
container image pull [--debug] [--scheme <scheme>] [--disable-progress-updates] [--arch <arch>] [--os <os>] [--platform <platform>] <reference>
398+
container image pull [--debug] [--scheme <scheme>] [--progress <type>] [--arch <arch>] [--os <os>] [--platform <platform>] <reference>
399399
```
400400

401401
**Arguments**
@@ -405,7 +405,7 @@ container image pull [--debug] [--scheme <scheme>] [--disable-progress-updates]
405405
**Options**
406406

407407
* `--scheme <scheme>`: Scheme to use when connecting to the container registry. One of (http, https, auto) (default: auto)
408-
* `--disable-progress-updates`: Disable progress bar updates
408+
* `--progress <type>`: Progress type (format: none|ansi) (default: ansi)
409409
* `-a, --arch <arch>`: Limit the pull to the specified architecture
410410
* `--os <os>`: Limit the pull to the specified OS
411411
* `--platform <platform>`: Limit the pull to the specified platform (format: os/arch[/variant], takes precedence over --os and --arch)
@@ -417,7 +417,7 @@ Pushes an image to a registry. The flags mirror those for `image pull` with the
417417
**Usage**
418418

419419
```bash
420-
container image push [--scheme <scheme>] [--disable-progress-updates] [--arch <arch>] [--os <os>] [--platform <platform>] [--debug] <reference>
420+
container image push [--scheme <scheme>] [--progress <type>] [--arch <arch>] [--os <os>] [--platform <platform>] [--debug] <reference>
421421
```
422422

423423
**Arguments**
@@ -427,7 +427,7 @@ container image push [--scheme <scheme>] [--disable-progress-updates] [--arch <a
427427
**Options**
428428

429429
* `--scheme <scheme>`: Scheme to use when connecting to the container registry. One of (http, https, auto) (default: auto)
430-
* `--disable-progress-updates`: Disable progress bar updates
430+
* `--progress <type>`: Progress type (format: none|ansi) (default: ansi)
431431
* `-a, --arch <arch>`: Limit the push to the specified architecture
432432
* `--os <os>`: Limit the push to the specified OS
433433
* `--platform <platform>`: Limit the push to the specified platform (format: os/arch[/variant], takes precedence over --os and --arch)

0 commit comments

Comments
 (0)