Skip to content
Open
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: 9 additions & 0 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ let package = Package(
.package(url: "https://github.com/grpc/grpc-swift.git", from: "1.26.0"),
.package(url: "https://github.com/swift-server/async-http-client.git", from: "1.20.1"),
.package(url: "https://github.com/swiftlang/swift-docc-plugin.git", from: "1.1.0"),
.package(url: "https://github.com/jpsim/Yams.git", from: "6.2.1"),
],
targets: [
.executableTarget(
Expand All @@ -79,6 +80,7 @@ let package = Package(
"ContainerBuild",
"ContainerLog",
"ContainerResource",
"Yams",
],
path: "Tests/CLITests"
),
Expand All @@ -101,6 +103,7 @@ let package = Package(
"ContainerVersion",
"ContainerXPC",
"TerminalProgress",
"Yams",
],
path: "Sources/ContainerCommands"
),
Expand Down
1 change: 1 addition & 0 deletions Sources/ContainerCommands/Application.swift
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ extension Application {
public enum ListFormat: String, CaseIterable, ExpressibleByArgument {
case json
case table
case yaml
}

func isTranslated() throws -> Bool {
Expand Down
8 changes: 8 additions & 0 deletions Sources/ContainerCommands/System/SystemVersion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import ArgumentParser
import ContainerAPIClient
import ContainerVersion
import Foundation
import Yams

extension Application {
public struct SystemVersion: AsyncLoggableCommand {
Expand Down Expand Up @@ -63,6 +64,8 @@ extension Application {
printVersionTable(versions: versions)
case .json:
try printVersionJSON(versions: versions)
case .yaml:
try printVersionYAML(versions: versions)
}
}

Expand All @@ -78,6 +81,11 @@ extension Application {
let data = try JSONEncoder().encode(versions)
print(String(data: data, encoding: .utf8) ?? "[]")
}

private func printVersionYAML(versions: [VersionInfo]) throws {
let data = try YAMLEncoder().encode(versions)
print(data)
}
}

public struct VersionInfo: Codable {
Expand Down
21 changes: 18 additions & 3 deletions Tests/CLITests/Subcommands/System/TestCLIVersion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import Foundation
import Testing
import Yams

/// Tests for `container system version` output formats and build type detection.
final class TestCLIVersion: CLITest {
Expand All @@ -26,7 +27,7 @@ final class TestCLIVersion: CLITest {
let appName: String
}

struct VersionJSON: Codable {
struct VersionOutput: Codable {
let version: String
let buildType: String
let commit: String
Expand Down Expand Up @@ -68,7 +69,21 @@ final class TestCLIVersion: CLITest {
#expect(status == 0, "system version --format json should succeed, stderr: \(err)")
#expect(!out.isEmpty)

let decoded = try JSONDecoder().decode([VersionJSON].self, from: data)
let decoded = try JSONDecoder().decode([VersionOutput].self, from: data)
#expect(decoded[0].appName == "container")
#expect(!decoded[0].version.isEmpty)
#expect(!decoded[0].commit.isEmpty)

let expected = try expectedBuildType()
#expect(decoded[0].buildType == expected)
}

@Test func yamlFormat() throws {
let (data, out, err, status) = try run(arguments: ["system", "version", "--format", "yaml"])
#expect(status == 0, "system version --format yaml should succeed, stderr: \(err)")
#expect(!out.isEmpty)

let decoded = try YAMLDecoder().decode([VersionOutput].self, from: data)
#expect(decoded[0].appName == "container")
#expect(!decoded[0].version.isEmpty)
#expect(!decoded[0].commit.isEmpty)
Expand All @@ -92,7 +107,7 @@ final class TestCLIVersion: CLITest {
// Validate build type via JSON to avoid parsing table text loosely
let (data, _, err, status) = try run(arguments: ["system", "version", "--format", "json"])
#expect(status == 0, "version --format json should succeed, stderr: \(err)")
let decoded = try JSONDecoder().decode([VersionJSON].self, from: data)
let decoded = try JSONDecoder().decode([VersionOutput].self, from: data)

let expected = try expectedBuildType()
#expect(decoded[0].buildType == expected, "Expected build type \(expected) but got \(decoded[0].buildType)")
Expand Down
17 changes: 16 additions & 1 deletion docs/command-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ container system version [--format <format>]

**Options**

* `--format <format>`: Output format (values: json, table; default: table)
* `--format <format>`: Output format (values: json, table, yaml; default: table)

**Table Output**

Expand Down Expand Up @@ -1070,6 +1070,21 @@ Backward-compatible with previous CLI-only output. Top-level fields describe the
}
```

**YAML Output**

Equivalent to the JSON output but in YAML format. Each entry in the array represents a component.

```yaml
- version: 1.2.3
buildType: debug
commit: abcdef1
appName: container
- version: 1.2.3
buildType: release
commit: 1234abc
appName: container-apiserver
```

### `container system logs`

Displays logs from the container services. You can specify a time interval or follow new logs in real time.
Expand Down