diff --git a/Sources/ContainerClient/Flags.swift b/Sources/ContainerClient/Flags.swift index a218deb2..91d50498 100644 --- a/Sources/ContainerClient/Flags.swift +++ b/Sources/ContainerClient/Flags.swift @@ -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 } } diff --git a/Sources/ContainerCommands/Container/ContainerRun.swift b/Sources/ContainerCommands/Container/ContainerRun.swift index 7807bed1..ec65329c 100644 --- a/Sources/ContainerCommands/Container/ContainerRun.swift +++ b/Sources/ContainerCommands/Container/ContainerRun.swift @@ -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, diff --git a/Sources/ContainerCommands/Image/ImagePull.swift b/Sources/ContainerCommands/Image/ImagePull.swift index 0633b4e5..3f14cef8 100644 --- a/Sources/ContainerCommands/Image/ImagePull.swift +++ b/Sources/ContainerCommands/Image/ImagePull.swift @@ -17,7 +17,6 @@ import ArgumentParser import ContainerClient import Containerization -import ContainerizationError import ContainerizationOCI import TerminalProgress @@ -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 } @@ -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, diff --git a/Sources/ContainerCommands/Image/ImagePush.swift b/Sources/ContainerCommands/Image/ImagePush.swift index 5c61a682..35c50850 100644 --- a/Sources/ContainerCommands/Image/ImagePush.swift +++ b/Sources/ContainerCommands/Image/ImagePush.swift @@ -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", @@ -79,6 +79,7 @@ extension Application { ignoreSmallSize: true ) } + let progress = ProgressBar(config: progressConfig) defer { progress.finish() diff --git a/Tests/CLITests/Subcommands/Build/CLIRunBase.swift b/Tests/CLITests/Subcommands/Build/CLIRunBase.swift index 23f11d51..f794e516 100644 --- a/Tests/CLITests/Subcommands/Build/CLIRunBase.swift +++ b/Tests/CLITests/Subcommands/Build/CLIRunBase.swift @@ -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 { @@ -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) diff --git a/Tests/CLITests/Subcommands/Build/TestCLITermIO.swift b/Tests/CLITests/Subcommands/Build/TestCLITermIO.swift index 26d4cce4..21ec51e3 100644 --- a/Tests/CLITests/Subcommands/Build/TestCLITermIO.swift +++ b/Tests/CLITests/Subcommands/Build/TestCLITermIO.swift @@ -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 { diff --git a/docs/command-reference.md b/docs/command-reference.md index 85923584..68fda381 100644 --- a/docs/command-reference.md +++ b/docs/command-reference.md @@ -79,7 +79,7 @@ container run [] [ ...] **Progress Options** -* `--disable-progress-updates`: Disable progress bar updates +* `--progress `: Progress type (format: none|ansi) (default: ansi) **Examples** @@ -395,7 +395,7 @@ Pulls an image from a registry. Supports specifying a platform and controlling p **Usage** ```bash -container image pull [--debug] [--scheme ] [--disable-progress-updates] [--arch ] [--os ] [--platform ] +container image pull [--debug] [--scheme ] [--progress ] [--arch ] [--os ] [--platform ] ``` **Arguments** @@ -405,7 +405,7 @@ container image pull [--debug] [--scheme ] [--disable-progress-updates] **Options** * `--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 `: Progress type (format: none|ansi) (default: ansi) * `-a, --arch `: Limit the pull to the specified architecture * `--os `: Limit the pull to the specified OS * `--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 **Usage** ```bash -container image push [--scheme ] [--disable-progress-updates] [--arch ] [--os ] [--platform ] [--debug] +container image push [--scheme ] [--progress ] [--arch ] [--os ] [--platform ] [--debug] ``` **Arguments** @@ -427,7 +427,7 @@ container image push [--scheme ] [--disable-progress-updates] [--arch `: Scheme to use when connecting to the container registry. One of (http, https, auto) (default: auto) -* `--disable-progress-updates`: Disable progress bar updates +* `--progress `: Progress type (format: none|ansi) (default: ansi) * `-a, --arch `: Limit the push to the specified architecture * `--os `: Limit the push to the specified OS * `--platform `: Limit the push to the specified platform (format: os/arch[/variant], takes precedence over --os and --arch)