-
Notifications
You must be signed in to change notification settings - Fork 805
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
pcurl command #109
pcurl command #109
Conversation
Added ability to convert NSURLReuqest to curl command.
def run(self, arguments, options): | ||
request = arguments[0] | ||
HTTPHeaderSring = '' | ||
HTTPMethod = fb.evaluateExpressionValue('(id)[{request} HTTPMethod]'.format(request=request)).GetObjectDescription() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer:
HTTPMethod = fb.evaluateExpressionValue("(id)[%s HTTPMethod]" % (request)).GetObjectDescription()
But then again, I ain't no Python guru.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IANAPG either, but I believe format
is preferred over %
. However, format
does not require named args, so a middle ground is:
HTTPMethod = fb.evaluateExpressionValue('(id)[{} HTTPMethod]'.format(request)).GetObjectDescription()
EDIT: However there's a readability advantage to the way @VTopoliuk has it now.
Overall LGTM, sans the comments. @kastiglione - any thoughts before we merge? |
Looks great to me! I'll let @kastiglione take a peek as well though. |
Great addition, thanks @VTopoliuk! I think this just needs to error when run on device and is good to go. |
I added --portable parameter to embed data into the final command. So now iOS Device is supported, but script will fire error if executed without --portable on device and request has body data. |
|
||
def options(self): | ||
return [ | ||
fb.FBCommandArgument(short='-p', long='--portable', arg='portable', boolean=True, default=False, help='Embed request data as base64.'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be useBase64Data
or something? portable
seems like a strange name for this parameter.
Or, just always do base64 data?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mattjgalloway actually 'portable' in this case means portable command or "you can run this command on other computers, not current one only"
http://dictionary.reference.com/browse/portable
base64 looks ugly and contains overhead on every run, not sure always output it is a good option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get how 'portable' makes sense here still. It sort of makes sense, but not intuitive to me.
Since you're copy-pasting the curl command anyway, I don't see why it matters that the base64 is ugly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my real-life test base64 is longer than one screen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok. Big amounts of data!
I still do think that portable
is a bad name. Maybe even it should be dataStyle
and then options are tmp
or base64
and it defaults to the one which makes most sense for the current platform.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to see what @kastiglione / @arigrant think too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"portable" is definitely opaque to me. I'm good with --base64
. Other suggestions: --inline(-data)
, --embed(-data)
…
I updated parameter name |
@VTopoliuk How about the nit? Can you fix that and then I think we're good to go! |
if len(HTTPHeaderSring) > 0: | ||
commandString += ' ' + HTTPHeaderSring | ||
if dataFile is not None: | ||
commandString += ' --data-binary @"{}"'.format(dataFile) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mattjgalloway actually same file are used in two cases:
- To embed data
- To write data to file
If I will place name generation under the not runtimeHelpers.isIOSDevice():
condition, then it will be not available here with --embed-data
option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh whoops sorry!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we go?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kastiglione do you think it's ready for merge?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left a couple comments. Primarily needs a fix for the location of dataFile
.
Add print JSON command.
…r with logic and.
if fb.evaluateIntegerExpression('[{} respondsToSelector:@selector(base64EncodedStringWithOptions:)]'.format(HTTPData)): | ||
dataAsString = fb.evaluateExpressionValue('(id)[(id){} base64EncodedStringWithOptions:0]'.format(HTTPData)).GetObjectDescription() | ||
elif not runtimeHelpers.isIOSDevice(): | ||
fb.evaluateExpression('(BOOL)[{} writeToFile:@"{}" atomically:NO]'.format(HTTPData, dataFile)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to at least warn if this fails.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, you are totally right!
Prevent overly eager regex match in `fv` command
Looks like you'll need to merge master into this branch now. |
Added ability to convert NSURLReuqest to curl command.
…r with logic and.
Conflicts: commands/FBPrintCommands.py
@VTopoliuk shall we merge this? cc @mattjgalloway |
Let's do it. |
Added ability to convert NSURLReuqest to curl command.
Example:
Also you can embed data into terminal command with --embed-data parameter, result: