Thrift-1376: Make port specification option in thrift remote
authorJake Farrell <jfarrell@apache.org>
Fri, 7 Oct 2011 00:14:34 +0000 (00:14 +0000)
committerJake Farrell <jfarrell@apache.org>
Fri, 7 Oct 2011 00:14:34 +0000 (00:14 +0000)
Client: py
Patch: Dave Watson

The thrift-generated Python service client allows overriding the default host/port by doing "-h host:port" on the command line. Oftentimes, you want to override the host but not the port, as most services run on well-defined ports.

git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1179905 13f79535-47bb-0310-9956-ffa450edef68

compiler/cpp/src/generate/t_py_generator.cc

index 53c190a..1a75fd8 100644 (file)
@@ -1430,7 +1430,7 @@ void t_py_generator::generate_service_remote(t_service* tservice) {
   f_remote <<
     "if len(sys.argv) <= 1 or sys.argv[1] == '--help':" << endl <<
     "  print ''" << endl <<
-    "  print 'Usage: ' + sys.argv[0] + ' [-h host:port] [-u url] [-f[ramed]] function [arg1 [arg2...]]'" << endl <<
+    "  print 'Usage: ' + sys.argv[0] + ' [-h host[:port]] [-u url] [-f[ramed]] function [arg1 [arg2...]]'" << endl <<
     "  print ''" << endl <<
     "  print 'Functions:'" << endl;
   for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
@@ -1469,7 +1469,8 @@ void t_py_generator::generate_service_remote(t_service* tservice) {
     "if sys.argv[argi] == '-h':" << endl <<
     "  parts = sys.argv[argi+1].split(':')" << endl <<
     "  host = parts[0]" << endl <<
-    "  port = int(parts[1])" << endl <<
+    "  if len(parts) > 1:" << endl <<
+    "    port = int(parts[1])" << endl <<
     "  argi += 2" << endl <<
     endl <<
     "if sys.argv[argi] == '-u':" << endl <<