88internal import ArgumentParser
99private import Darwin
1010private import Foundation
11+ private import JSON
12+ private import JSONAST
13+ private import JSONEncoding
1114
1215extension MAS {
1316 /// Outputs mas config & related system info.
@@ -16,24 +19,30 @@ extension MAS {
1619 abstract: " Output mas config & related system info " ,
1720 )
1821
22+ @OptionGroup
23+ private var outputFormatOptionGroup : OutputFormatOptionGroup
24+
1925 func run( ) {
20- printer. info (
21- """
22- mas ▁▁▁▁ \( version)
23- slice ▁▁ \( runningSliceArchitecture)
24- slices ▁ \( supportedSliceArchitectures. joined ( separator: " " ) )
25- dist ▁▁▁ \( distribution)
26- origin ▁ \( gitOrigin)
27- rev ▁▁▁▁ \( gitRevision)
28- swift ▁▁ \( swiftVersion)
29- driver ▁ \( swiftDriverVersion)
30- store ▁▁ \( appStoreRegion)
31- region ▁ \( macRegion)
32- macos ▁▁ \( macOSVersion)
33- mac ▁▁▁▁ \( configStringValue ( " hw.product " ) )
34- cpu ▁▁▁▁ \( configStringValue ( " machdep.cpu.brand_string " ) )
35- arch ▁▁▁ \( configStringValue ( " hw.machine " ) )
36- """ ,
26+ outputFormatOptionGroup. info (
27+ JSON . encode (
28+ KeyValuePairs (
29+ dictionaryLiteral:
30+ ( " mas " , version) ,
31+ ( " slice " , runningSliceArchitecture) ,
32+ ( " slices " , supportedSliceArchitectures. joined ( separator: " " ) ) ,
33+ ( " dist " , distribution) ,
34+ ( " origin " , gitOrigin) ,
35+ ( " rev " , gitRevision) ,
36+ ( " swift " , swiftVersion) ,
37+ ( " driver " , swiftDriverVersion) ,
38+ ( " store " , appStoreRegion) ,
39+ ( " region " , macRegion) ,
40+ ( " macos " , macOSVersion) ,
41+ ( " mac " , configStringValue ( " hw.product " ) ) ,
42+ ( " cpu " , configStringValue ( " machdep.cpu.brand_string " ) ) ,
43+ ( " arch " , configStringValue ( " hw.machine " ) ) ,
44+ ) ,
45+ ) ,
3746 )
3847 }
3948 }
@@ -78,8 +87,10 @@ private var supportedSliceArchitectures: [String] {
7887 ?? [ ] // swiftformat:disable:this indent
7988}
8089
81- private var macOSVersion : Substring {
82- ProcessInfo . processInfo. operatingSystemVersionString. dropFirst ( 8 ) . replacing ( " Build " , with: " " , maxReplacements: 1 )
90+ private var macOSVersion : String {
91+ String (
92+ ProcessInfo . processInfo. operatingSystemVersionString. dropFirst ( 8 ) . replacing ( " Build " , with: " " , maxReplacements: 1 ) ,
93+ )
8394}
8495
8596private func configStringValue( _ name: String ) -> String {
0 commit comments