
import argparse
import os
import pdb

import pkg_resources


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('script')
    args = parser.parse_args()

    script_name = os.path.basename(args.script)
    ep = pkg_resources.iter_entry_points('console_scripts', script_name).next()
    f = ep.load()

    pdb.runcall(f)

if __name__ == '__main__':
    import sys
    sys.exit(main())


import argparse
import os
import pdb
import sys

import pkg_resources


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('script')
    args, scriptargs = parser.parse_known_args()

    script_name = os.path.basename(args.script)
    ep = pkg_resources.iter_entry_points('console_scripts', script_name).next()
    f = ep.load()

    sys.argv = [args.script]
    sys.argv.extend(scriptargs)
    pdb.runcall(f)

if __name__ == '__main__':
    sys.exit(main())

Allow script args to be passed; reconstitute sys.argv for script
Allow script args to be passed; reconstitute sys.argv for script

Signed-off-by: Dan Mick <b07550071eaa6a9296289c43bbd6c90559196431@inktank.com>

  
  import argparse
  import os
  import pdb
+ import sys
  
  import pkg_resources
  
  
  def main():
      parser = argparse.ArgumentParser()
      parser.add_argument('script')
-     args = parser.parse_args()
+     args, scriptargs = parser.parse_known_args()
  
      script_name = os.path.basename(args.script)
      ep = pkg_resources.iter_entry_points('console_scripts', script_name).next()
      f = ep.load()
  
+     sys.argv = [args.script]
+     sys.argv.extend(scriptargs)
      pdb.runcall(f)
  
  if __name__ == '__main__':
-     import sys
      sys.exit(main())
  
Allow script args to be passed; reconstitute sys.argv for script
## Code Before:

import argparse
import os
import pdb

import pkg_resources


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('script')
    args = parser.parse_args()

    script_name = os.path.basename(args.script)
    ep = pkg_resources.iter_entry_points('console_scripts', script_name).next()
    f = ep.load()

    pdb.runcall(f)

if __name__ == '__main__':
    import sys
    sys.exit(main())

## Instruction:
Allow script args to be passed; reconstitute sys.argv for script
## Code After:

import argparse
import os
import pdb
import sys

import pkg_resources


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('script')
    args, scriptargs = parser.parse_known_args()

    script_name = os.path.basename(args.script)
    ep = pkg_resources.iter_entry_points('console_scripts', script_name).next()
    f = ep.load()

    sys.argv = [args.script]
    sys.argv.extend(scriptargs)
    pdb.runcall(f)

if __name__ == '__main__':
    sys.exit(main())
