Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for printing json format for Swift Dictionaries and Arrays #238

Merged
merged 2 commits into from
May 19, 2018
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