Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions commands/FBPrintCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def lldbcommands():
FBPrintData(),
FBPrintTargetActions(),
FBPrintJSON(),
FBPrintSwiftJSON(),
FBPrintAsCurl(),
FBPrintToClipboard(),
FBPrintObjectInObjc(),
Expand Down Expand Up @@ -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 Swift Dictionary or Swift Array 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'
Expand Down