@@ -152,15 +152,34 @@ struct SwiftInspect: ParsableCommand {
152
152
] )
153
153
}
154
154
155
+ struct UniversalOptions : ParsableArguments {
156
+ @Argument ( help: " The pid or partial name of the target process " )
157
+ var nameOrPid : String
158
+ }
159
+
160
+ struct BacktraceOptions : ParsableArguments {
161
+ @Flag ( help: " Show the backtrace for each allocation " )
162
+ var backtrace : Bool
163
+
164
+ @Flag ( help: " Show a long-form backtrace for each allocation " )
165
+ var backtraceLong : Bool
166
+
167
+ var style : Backtrace . Style ? {
168
+ backtrace ? . oneLine :
169
+ backtraceLong ? . long :
170
+ nil
171
+ }
172
+ }
173
+
155
174
struct DumpConformanceCache : ParsableCommand {
156
175
static let configuration = CommandConfiguration (
157
176
abstract: " Print the contents of the target's protocol conformance cache. " )
158
177
159
- @Argument ( help : " The pid or partial name of the target process " )
160
- var nameOrPid : String
178
+ @OptionGroup ( )
179
+ var options : UniversalOptions
161
180
162
181
func run( ) throws {
163
- try withReflectionContext ( nameOrPid: nameOrPid) { context, _ in
182
+ try withReflectionContext ( nameOrPid: options . nameOrPid) { context, _ in
164
183
try dumpConformanceCache ( context: context)
165
184
}
166
185
}
@@ -169,22 +188,18 @@ struct DumpConformanceCache: ParsableCommand {
169
188
struct DumpRawMetadata : ParsableCommand {
170
189
static let configuration = CommandConfiguration (
171
190
abstract: " Print the target's metadata allocations. " )
172
- @Argument ( help: " The pid or partial name of the target process " )
173
191
174
- var nameOrPid : String
175
-
176
- @Flag ( help: " Show the backtrace for each allocation " )
177
- var backtrace : Bool
192
+ @OptionGroup ( )
193
+ var universalOptions : UniversalOptions
178
194
179
- @Flag ( help : " Show a long-form backtrace for each allocation " )
180
- var backtraceLong : Bool
195
+ @OptionGroup ( )
196
+ var backtraceOptions : BacktraceOptions
181
197
182
198
func run( ) throws {
183
- let style = backtrace ? Backtrace . Style. oneLine :
184
- backtraceLong ? Backtrace . Style. long :
185
- nil
186
- try withReflectionContext ( nameOrPid: nameOrPid) {
187
- try dumpRawMetadata ( context: $0, inspector: $1, backtraceStyle: style)
199
+ try withReflectionContext ( nameOrPid: universalOptions. nameOrPid) {
200
+ try dumpRawMetadata ( context: $0,
201
+ inspector: $1,
202
+ backtraceStyle: backtraceOptions. style)
188
203
}
189
204
}
190
205
}
@@ -193,23 +208,17 @@ struct DumpGenericMetadata: ParsableCommand {
193
208
static let configuration = CommandConfiguration (
194
209
abstract: " Print the target's generic metadata allocations. " )
195
210
196
- @Argument ( help : " The pid or partial name of the target process " )
197
- var nameOrPid : String
211
+ @OptionGroup ( )
212
+ var universalOptions : UniversalOptions
198
213
199
- @Flag ( help: " Show the backtrace for each allocation " )
200
- var backtrace : Bool
201
-
202
- @Flag ( help: " Show a long-form backtrace for each allocation " )
203
- var backtraceLong : Bool
214
+ @OptionGroup ( )
215
+ var backtraceOptions : BacktraceOptions
204
216
205
217
func run( ) throws {
206
- let style = backtrace ? Backtrace . Style. oneLine :
207
- backtraceLong ? Backtrace . Style. long :
208
- nil
209
- try withReflectionContext ( nameOrPid: nameOrPid) {
218
+ try withReflectionContext ( nameOrPid: universalOptions. nameOrPid) {
210
219
try dumpGenericMetadata ( context: $0,
211
220
inspector: $1,
212
- backtraceStyle: style)
221
+ backtraceStyle: backtraceOptions . style)
213
222
}
214
223
}
215
224
}
@@ -218,11 +227,11 @@ struct DumpCacheNodes: ParsableCommand {
218
227
static let configuration = CommandConfiguration (
219
228
abstract: " Print the target's metadata cache nodes. " )
220
229
221
- @Argument ( help : " The pid or partial name of the target process " )
222
- var nameOrPid : String
230
+ @OptionGroup ( )
231
+ var options : UniversalOptions
223
232
224
233
func run( ) throws {
225
- try withReflectionContext ( nameOrPid: nameOrPid) {
234
+ try withReflectionContext ( nameOrPid: options . nameOrPid) {
226
235
try dumpMetadataCacheNodes ( context: $0,
227
236
inspector: $1)
228
237
}
0 commit comments