Skip to content
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
9 changes: 5 additions & 4 deletions Sources/ContainerClient/Flags.swift
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,12 @@ public struct Flags {
public struct Progress: ParsableArguments {
public init() {}

public init(disableProgressUpdates: Bool) {
self.disableProgressUpdates = disableProgressUpdates
public enum ProgressType: String, ExpressibleByArgument {
case none
case ansi
}

@Flag(name: .long, help: "Disable progress bar updates")
public var disableProgressUpdates = false
@Option(name: .long, help: ArgumentHelp("Progress type (format: none|ansi)", valueName: "type"))
public var progress: ProgressType = .ansi
}
}
6 changes: 3 additions & 3 deletions Sources/ContainerCommands/Container/ContainerRun.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ extension Application {
let id = Utility.createContainerID(name: self.managementFlags.name)

var progressConfig: ProgressConfig
if progressFlags.disableProgressUpdates {
progressConfig = try ProgressConfig(disableProgressUpdates: progressFlags.disableProgressUpdates)
} else {
switch self.progressFlags.progress {
case .none: progressConfig = try ProgressConfig(disableProgressUpdates: true)
case .ansi:
progressConfig = try ProgressConfig(
showTasks: true,
showItems: true,
Expand Down
10 changes: 4 additions & 6 deletions Sources/ContainerCommands/Image/ImagePull.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import ArgumentParser
import ContainerClient
import Containerization
import ContainerizationError
import ContainerizationOCI
import TerminalProgress

Expand Down Expand Up @@ -57,10 +56,9 @@ extension Application {

public init() {}

public init(platform: String? = nil, scheme: String = "auto", reference: String, disableProgress: Bool = false) {
public init(platform: String? = nil, scheme: String = "auto", reference: String) {
self.global = Flags.Global()
self.registry = Flags.Registry(scheme: scheme)
self.progressFlags = Flags.Progress(disableProgressUpdates: disableProgress)
self.platform = platform
self.reference = reference
}
Expand All @@ -80,9 +78,9 @@ extension Application {
let processedReference = try ClientImage.normalizeReference(reference)

var progressConfig: ProgressConfig
if self.progressFlags.disableProgressUpdates {
progressConfig = try ProgressConfig(disableProgressUpdates: self.progressFlags.disableProgressUpdates)
} else {
switch self.progressFlags.progress {
case .none: progressConfig = try ProgressConfig(disableProgressUpdates: true)
case .ansi:
progressConfig = try ProgressConfig(
showTasks: true,
showItems: true,
Expand Down
7 changes: 4 additions & 3 deletions Sources/ContainerCommands/Image/ImagePush.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ extension Application {
let image = try await ClientImage.get(reference: reference)

var progressConfig: ProgressConfig
if progressFlags.disableProgressUpdates {
progressConfig = try ProgressConfig(disableProgressUpdates: progressFlags.disableProgressUpdates)
} else {
switch self.progressFlags.progress {
case .none: progressConfig = try ProgressConfig(disableProgressUpdates: true)
case .ansi:
progressConfig = try ProgressConfig(
description: "Pushing image \(image.reference)",
itemsName: "blobs",
Expand All @@ -79,6 +79,7 @@ extension Application {
ignoreSmallSize: true
)
}

let progress = ProgressBar(config: progressConfig)
defer {
progress.finish()
Expand Down
31 changes: 15 additions & 16 deletions Tests/CLITests/Subcommands/Build/CLIRunBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,28 @@ class TestCLIRunBase: CLITest {
var terminal: Terminal!
var containerName: String = UUID().uuidString

var ContainerImage: String {
var containerImage: String {
fatalError("Subclasses must override this property")
}

var Interactive: Bool {
var interactive: Bool {
false
}

var Tty: Bool {
var tty: Bool {
false
}

var Entrypoint: String? {
var entrypoint: String? {
nil
}

var Command: [String]? {
var command: [String]? {
nil
}

var DisableProgressUpdates: Bool {
false
var progress: String {
"ansi"
}

override init() throws {
Expand Down Expand Up @@ -108,24 +108,23 @@ class TestCLIRunBase: CLITest {
name,
]

if Interactive && Tty {
if interactive && tty {
arguments.append("-it")
} else {
if Interactive { arguments.append("-i") }
if Tty { arguments.append("-t") }
if interactive { arguments.append("-i") }
if tty { arguments.append("-t") }
}

if DisableProgressUpdates {
arguments.append("--disable-progress-updates")
}
arguments.append("--progress")
arguments.append(progress)

if let entrypoint = Entrypoint {
if let entrypoint = entrypoint {
arguments += ["--entrypoint", entrypoint]
}

arguments.append(ContainerImage)
arguments.append(containerImage)

if let command = Command {
if let command = command {
arguments += command
}
return try runInteractive(arguments: arguments)
Expand Down
12 changes: 6 additions & 6 deletions Tests/CLITests/Subcommands/Build/TestCLITermIO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,24 @@ import Testing

extension TestCLIRunBase {
class TestCLITermIO: TestCLIRunBase {
override var ContainerImage: String {
override var containerImage: String {
"ghcr.io/linuxcontainers/alpine:3.20"
}

override var Interactive: Bool {
override var interactive: Bool {
true
}

override var Tty: Bool {
override var tty: Bool {
true
}

override var Command: [String]? {
override var command: [String]? {
["/bin/sh"]
}

override var DisableProgressUpdates: Bool {
true
override var progress: String {
"none"
}

@Test func testTermIODoesNotPanic() async throws {
Expand Down
10 changes: 5 additions & 5 deletions docs/command-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ container run [<options>] <image> [<arguments> ...]

**Progress Options**

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

**Examples**

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

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

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

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

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

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

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