@@ -20,7 +20,7 @@ import ContainerVersion
2020import Foundation
2121
2222extension 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