From 00e7039db79a8e44742ebde22bfa7c33e7eb1149 Mon Sep 17 00:00:00 2001 From: Jatin Arora Date: Fri, 30 Mar 2018 10:38:08 +0530 Subject: [PATCH 1/2] Add support for printing json format for Swift Dictionaries and Arrays --- commands/FBPrintCommands.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/commands/FBPrintCommands.py b/commands/FBPrintCommands.py index 74b9b84..46b161c 100755 --- a/commands/FBPrintCommands.py +++ b/commands/FBPrintCommands.py @@ -35,6 +35,7 @@ def lldbcommands(): FBPrintData(), FBPrintTargetActions(), FBPrintJSON(), + FBPrintSwiftJSON(), FBPrintAsCurl(), FBPrintToClipboard(), FBPrintObjectInObjc(), @@ -492,6 +493,29 @@ def run(self, arguments, options): print jsonString +class FBPrintSwiftJSON(fb.FBCommand): + + def name(self): + return 'psjson' + + def description(self): + return 'Print JSON representation of Swift Dictionary or Swift Array object' + + def options(self): + return [ fb.FBCommandArgument(arg='plain', short='-p', long='--plain', boolean=True, default=False, help='Plain JSON') ] + + def args(self): + return [ fb.FBCommandArgument(arg='object', type='NSObject *', help='The NSDictionary or NSArray object to print') ] + + def run(self, arguments, options): + #Convert to NSObject first to allow for objc runtime to process it + objectToPrint = fb.evaluateInputExpression('{obj} as NSObject'.format(obj=arguments[0])) + pretty = 1 if options.plain is None else 0 + jsonData = fb.evaluateObjectExpression('[NSJSONSerialization dataWithJSONObject:(NSObject*){} options:{} error:nil]'.format(objectToPrint, pretty)) + jsonString = fb.evaluateExpressionValue('(NSString*)[[NSString alloc] initWithData:(NSObject*){} encoding:4]'.format(jsonData)).GetObjectDescription() + + print jsonString + class FBPrintAsCurl(fb.FBCommand): def name(self): return 'pcurl' From 15ebcebe480bedfe8765667e5f5b850e069cca9a Mon Sep 17 00:00:00 2001 From: Jatin Arora Date: Fri, 30 Mar 2018 10:44:45 +0530 Subject: [PATCH 2/2] Fix arguments messaging --- commands/FBPrintCommands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/FBPrintCommands.py b/commands/FBPrintCommands.py index 46b161c..d3168a0 100755 --- a/commands/FBPrintCommands.py +++ b/commands/FBPrintCommands.py @@ -505,7 +505,7 @@ def options(self): return [ fb.FBCommandArgument(arg='plain', short='-p', long='--plain', boolean=True, default=False, help='Plain JSON') ] def args(self): - return [ fb.FBCommandArgument(arg='object', type='NSObject *', help='The NSDictionary or NSArray object to print') ] + return [ fb.FBCommandArgument(arg='object', type='NSObject *', help='The Swift Dictionary or Swift Array to print') ] def run(self, arguments, options): #Convert to NSObject first to allow for objc runtime to process it