Skip to content

Commit 56713d7

Browse files
committed
fix: fix review issue
1 parent 1d03bea commit 56713d7

File tree

5 files changed

+32
-42
lines changed

5 files changed

+32
-42
lines changed

Sources/ContainerClient/Core/ClientHealthCheck.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,12 @@ extension ClientHealthCheck {
4343
guard let apiServerCommit = reply.string(key: .apiServerCommit) else {
4444
throw ContainerizationError(.internalError, message: "failed to decode apiServerCommit in health check")
4545
}
46-
// Optional fields for newer servers
47-
let apiServerBuild = reply.string(key: .apiServerBuild)
48-
let apiServerAppName = reply.string(key: .apiServerAppName)
46+
guard let apiServerBuild = reply.string(key: .apiServerBuild) else {
47+
throw ContainerizationError(.internalError, message: "failed to decode apiServerBuild in health check")
48+
}
49+
guard let apiServerAppName = reply.string(key: .apiServerAppName) else {
50+
throw ContainerizationError(.internalError, message: "failed to decode apiServerAppName in health check")
51+
}
4952
return .init(
5053
appRoot: appRoot,
5154
installRoot: installRoot,

Sources/ContainerClient/Core/SystemHealth.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ public struct SystemHealth: Sendable, Codable {
3030
/// The Git commit ID for the container services.
3131
public let apiServerCommit: String
3232

33-
/// Optional build type of the API server (debug|release). Present on newer servers.
34-
public let apiServerBuild: String?
33+
/// The build type of the API server (debug|release).
34+
public let apiServerBuild: String
3535

36-
/// Optional app name label returned by the server.
37-
public let apiServerAppName: String?
36+
/// The app name label returned by the server.
37+
public let apiServerAppName: String
3838
}

Sources/ContainerCommands/Application.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ public struct Application: AsyncParsableCommand {
7171
RegistryCommand.self,
7272
]
7373
),
74+
CommandGroup(
75+
name: "Volume",
76+
subcommands: [
77+
VolumeCommand.self
78+
]
79+
),
7480
CommandGroup(
7581
name: "Other",
7682
subcommands: Self.otherCommands()

Sources/ContainerCommands/System/SystemCommand.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ extension Application {
3131
SystemStart.self,
3232
SystemStatus.self,
3333
SystemStop.self,
34-
VersionCommand.self,
34+
SystemVersion.self,
3535
],
3636
aliases: ["s"]
3737
)

Sources/ContainerCommands/System/Version.swift

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import ContainerVersion
2020
import Foundation
2121

2222
extension Application {
23-
public struct VersionCommand: AsyncParsableCommand {
23+
public struct SystemVersion: AsyncParsableCommand {
2424
public static let configuration = CommandConfiguration(
2525
commandName: "version",
2626
abstract: "Show version information"
@@ -39,7 +39,7 @@ extension Application {
3939
version: ReleaseVersion.version(),
4040
buildType: ReleaseVersion.buildType(),
4141
commit: ReleaseVersion.gitCommit() ?? "unspecified",
42-
appName: "container CLI"
42+
appName: "container"
4343
)
4444

4545
// Try to get API server version info
@@ -48,47 +48,36 @@ extension Application {
4848
let health = try await ClientHealthCheck.ping(timeout: .seconds(2))
4949
serverInfo = VersionInfo(
5050
version: health.apiServerVersion,
51-
buildType: health.apiServerBuild ?? "unknown",
51+
buildType: health.apiServerBuild,
5252
commit: health.apiServerCommit,
53-
appName: "container API Server"
53+
appName: health.apiServerAppName
5454
)
5555
} catch {
5656
serverInfo = nil
5757
}
5858

59+
let versions = [cliInfo, serverInfo].compactMap { $0 }
60+
5961
switch format {
6062
case .table:
61-
printVersionTable(cli: cliInfo, server: serverInfo)
63+
printVersionTable(versions: versions)
6264
case .json:
63-
try printVersionJSON(cli: cliInfo, server: serverInfo)
65+
try printVersionJSON(versions: versions)
6466
}
6567
}
6668

6769

68-
private func printVersionTable(cli: VersionInfo, server: VersionInfo?) {
69-
var rows: [[String]] = [
70-
["COMPONENT", "VERSION", "BUILD", "COMMIT"],
71-
["CLI", cli.version, cli.buildType, cli.commit]
72-
]
73-
74-
if let server = server {
75-
rows.append(["API Server", server.version, server.buildType, server.commit])
76-
}
77-
70+
private func printVersionTable(versions: [VersionInfo]) {
71+
let header = ["COMPONENT", "VERSION", "BUILD", "COMMIT"]
72+
let rows = [header] + versions.map { [$0.appName, $0.version, $0.buildType, $0.commit] }
73+
7874
let table = TableOutput(rows: rows)
7975
print(table.format())
8076
}
8177

82-
private func printVersionJSON(cli: VersionInfo, server: VersionInfo?) throws {
83-
let output = VersionJSON(
84-
version: cli.version,
85-
buildType: cli.buildType,
86-
commit: cli.commit,
87-
appName: cli.appName,
88-
server: server
89-
)
90-
let data = try JSONEncoder().encode(output)
91-
print(String(data: data, encoding: .utf8) ?? "{}")
78+
private func printVersionJSON(versions: [VersionInfo]) throws {
79+
let data = try JSONEncoder().encode(versions)
80+
print(String(data: data, encoding: .utf8) ?? "[]")
9281
}
9382
}
9483

@@ -98,12 +87,4 @@ extension Application {
9887
let commit: String
9988
let appName: String
10089
}
101-
102-
struct VersionJSON: Codable {
103-
let version: String
104-
let buildType: String
105-
let commit: String
106-
let appName: String
107-
let server: VersionInfo?
108-
}
10990
}

0 commit comments

Comments
 (0)