-
Notifications
You must be signed in to change notification settings - Fork 754
Feat: add container registry list #1119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a62e977
Chore: update license
tico88612 dc3823b
Style: changed Registry-related struct
tico88612 ff56a11
Feat: container registry list
tico88612 eb22abe
Docs: container registry list
tico88612 e5afc83
Fix: add command name in Registry
tico88612 1d4c9c8
Test: add container registry list
tico88612 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // Copyright © 2026 Apple Inc. and the container project authors. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // https://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| import ArgumentParser | ||
| import ContainerAPIClient | ||
| import ContainerizationOCI | ||
| import ContainerizationOS | ||
| import Foundation | ||
|
|
||
| extension Application { | ||
| public struct RegistryList: AsyncLoggableCommand { | ||
| @OptionGroup | ||
| public var logOptions: Flags.Logging | ||
|
|
||
| @Option(name: .long, help: "Format of the output") | ||
| var format: ListFormat = .table | ||
|
|
||
| @Flag(name: .shortAndLong, help: "Only output the registry name") | ||
| var quiet = false | ||
|
|
||
| public init() {} | ||
| public static let configuration = CommandConfiguration( | ||
| commandName: "list", | ||
| abstract: "List image registry logins", | ||
| aliases: ["ls"]) | ||
|
|
||
| public func run() async throws { | ||
| let keychain = KeychainHelper(securityDomain: Constants.keychainID) | ||
| let registries = try keychain.list() | ||
| try printRegistries(registries: registries, format: format) | ||
| } | ||
|
|
||
| private func createHeader() -> [[String]] { | ||
| [["HOSTNAME", "USERNAME", "MODIFIED", "CREATED"]] | ||
| } | ||
|
|
||
| private func printRegistries(registries: [RegistryInfo], format: ListFormat) throws { | ||
| if format == .json { | ||
| let printables = registries.map { | ||
| PrintableRegistry($0) | ||
| } | ||
| let data = try JSONEncoder().encode(printables) | ||
| print(String(decoding: data, as: UTF8.self)) | ||
|
|
||
| return | ||
| } | ||
|
|
||
| if self.quiet { | ||
| registries.forEach { | ||
| print($0.hostname) | ||
| } | ||
| return | ||
| } | ||
|
|
||
| var rows = createHeader() | ||
| for registry in registries { | ||
| rows.append(registry.asRow) | ||
| } | ||
|
|
||
| let formatter = TableOutput(rows: rows) | ||
| print(formatter.format()) | ||
| } | ||
| } | ||
| } | ||
| extension RegistryInfo { | ||
| fileprivate var asRow: [String] { | ||
| [ | ||
| self.hostname, | ||
| self.username, | ||
| self.modifiedDate.ISO8601Format(), | ||
| self.createdDate.ISO8601Format(), | ||
| ] | ||
| } | ||
| } | ||
| struct PrintableRegistry: Codable { | ||
| let hostname: String | ||
| let username: String | ||
| let modifiedDate: Date | ||
| let createdDate: Date | ||
|
|
||
| init(_ registry: RegistryInfo) { | ||
| self.hostname = registry.hostname | ||
| self.username = registry.username | ||
| self.modifiedDate = registry.modifiedDate | ||
| self.createdDate = registry.createdDate | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // Copyright © 2026 Apple Inc. and the container project authors. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // https://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| import Foundation | ||
| import Testing | ||
|
|
||
| class TestCLIRegistry: CLITest { | ||
| @Test func testListDefaultFormat() throws { | ||
| let (_, output, error, status) = try run(arguments: ["registry", "list"]) | ||
| #expect(status == 0, "registry list should succeed, stderr: \(error)") | ||
|
|
||
| // Check for table header | ||
| let requiredHeaders = ["HOSTNAME", "USERNAME", "MODIFIED", "CREATED"] | ||
| #expect( | ||
| requiredHeaders.allSatisfy { output.contains($0) }, | ||
| "output should contain all required headers" | ||
| ) | ||
| } | ||
|
|
||
| @Test func testListQuietMode() throws { | ||
| let (_, output, error, status) = try run(arguments: ["registry", "list", "-q"]) | ||
| #expect(status == 0, "registry list -q should succeed, stderr: \(error)") | ||
|
|
||
| #expect(!output.contains("HOSTNAME"), "quiet mode should not contain headers") | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.