Skip to content

Commit

Permalink
Merge pull request #147 from MDSilber/master
Browse files Browse the repository at this point in the history
Adds command to copy object description to clipboard
  • Loading branch information
kastiglione committed Mar 11, 2016
2 parents 9e26eb8 + bf66fbb commit 8d31874
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions commands/FBPrintCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import os
import re
import subprocess

import lldb
import fblldbbase as fb
Expand All @@ -34,6 +35,7 @@ def lldbcommands():
FBPrintTargetActions(),
FBPrintJSON(),
FBPrintAsCurl(),
FBPrintToClipboard(),
FBPrintInObjc(),
FBPrintInSwift(),
FBPrintObjectInObjc(),
Expand Down Expand Up @@ -176,7 +178,7 @@ def args(self):

def run(self, arguments, options):
startResponder = arguments[0]

isMac = runtimeHelpers.isMacintoshArch()
responderClass = 'UIResponder'
if isMac:
Expand Down Expand Up @@ -324,15 +326,15 @@ def name(self):

def description(self):
return "Print application's 'Documents' directory path."

def options(self):
return [
fb.FBCommandArgument(short='-o', long='--open', arg='open', boolean=True, default=False, help='open in Finder'),
]

def run(self, arguments, options):
# in iOS SDK NSDocumentDirectory == 9 NSUserDomainMask == 1
NSDocumentDirectory = '9'
# in iOS SDK NSDocumentDirectory == 9 NSUserDomainMask == 1
NSDocumentDirectory = '9'
NSUserDomainMask = '1'
path = fb.evaluateExpressionValue('(NSString*)[NSSearchPathForDirectoriesInDomains(' + NSDocumentDirectory + ', ' + NSUserDomainMask + ', YES) lastObject]')
pathString = '{}'.format(path).split('"')[1]
Expand All @@ -341,7 +343,7 @@ def run(self, arguments, options):
print pathString
if options.open:
os.system('open '+ pathString)


class FBPrintData(fb.FBCommand):
def name(self):
Expand Down Expand Up @@ -440,7 +442,7 @@ def run(self, arguments, options):
print '{target}: {actions}'.format(target=targetDescription, actions=actionsDescription)

class FBPrintJSON(fb.FBCommand):

def name(self):
return 'pjson'

Expand All @@ -460,9 +462,9 @@ def run(self, arguments, options):
pretty = 1 if options.plain is None else 0
jsonData = fb.evaluateObjectExpression('[NSJSONSerialization dataWithJSONObject:{} options:{} error:nil]'.format(objectToPrint, pretty))
jsonString = fb.evaluateExpressionValue('(NSString*)[[NSString alloc] initWithData:{} encoding:4]'.format(jsonData)).GetObjectDescription()

print jsonString

class FBPrintAsCurl(fb.FBCommand):
def name(self):
return 'pcurl'
Expand All @@ -488,7 +490,7 @@ def run(self, arguments, options):
URL = fb.evaluateExpressionValue('(id)[{} URL]'.format(request)).GetObjectDescription()
timeout = fb.evaluateExpression('(NSTimeInterval)[{} timeoutInterval]'.format(request))
HTTPHeaders = fb.evaluateObjectExpression('(id)[{} allHTTPHeaderFields]'.format(request))
HTTPHeadersCount = fb.evaluateIntegerExpression('[{} count]'.format(HTTPHeaders))
HTTPHeadersCount = fb.evaluateIntegerExpression('[{} count]'.format(HTTPHeaders))
allHTTPKeys = fb.evaluateObjectExpression('[{} allKeys]'.format(HTTPHeaders))
for index in range(0, HTTPHeadersCount):
key = fb.evaluateObjectExpression('[{} objectAtIndex:{}]'.format(allHTTPKeys, index))
Expand Down Expand Up @@ -525,10 +527,27 @@ def run(self, arguments, options):
commandString += ' ' + HTTPHeaderSring
if dataFile is not None:
commandString += ' --data-binary @"{}"'.format(dataFile)

commandString += ' "{}"'.format(URL)
print commandString

class FBPrintToClipboard(fb.FBCommand):
def name(self):
return 'pbcopy'

def description(self):
return 'Print object and copy output to clipboard'

def args(self):
return [ fb.FBCommandArgument(arg='object', type='id', help='The object to print') ]

def run(self, arguments, options):
lldbOutput = fb.evaluateExpressionValue("[{changeset} description]".format(changeset = arguments[0])).GetObjectDescription()
process = subprocess.Popen(
'pbcopy', env={'LANG': 'en_US.UTF-8'}, stdin=subprocess.PIPE)
process.communicate(lldbOutput.encode('utf-8'))
print "Object copied to clipboard"

class FBPrintInObjc(fb.FBCommand):
def name(self):
return 'pobjc'
Expand Down

0 comments on commit 8d31874

Please sign in to comment.