
import argparse
import argcomplete
import plotter

def parse_arguments():
    """Argument Parser, providing available scripts"""
    parser = argparse.ArgumentParser()
    subparsers = parser.add_subparsers(
        title = 'plotter',
        description = 'available plotting scripts'
    )
    module_subparser = {}
    for module_str in plotter.__all__:
        module = __import__('.'.join(('plotter', module_str)), fromlist=module_str)
        module_subparser[module_str] = subparsers.add_parser(
            module_str, parents=[module.get_parser(add_help=False)],
            help=module.__doc__.split('\n', 1)[0]
        )
    configure = subparsers.add_parser('configure', help='configure this script.')

    argcomplete.autocomplete(parser)
    args = parser.parse_args()
    return args


if __name__ == '__main__':
    args = parse_arguments()
    from plotter.plotn import main
    main(args)


import argparse
import argcomplete
import plotter

def parse_arguments():
    """Argument Parser, providing available scripts"""
    parser = argparse.ArgumentParser()
    subparsers = parser.add_subparsers(
        title = 'plotter',
        description = 'available plotting scripts',
        dest='used_subparser',
    )
    module_subparser = {}
    for module_str in plotter.__all__:
        module = __import__('plotter.' + module_str, fromlist=module_str)
        module_subparser[module_str] = subparsers.add_parser(
            module_str, parents=[module.get_parser(add_help=False)],
            help=module.__doc__.split('\n', 1)[0]
        )
        module_subparser[module_str].set_defaults(run=module.main)
    configure = subparsers.add_parser('configure', help='configure this script.')

    argcomplete.autocomplete(parser)
    args = parser.parse_args()
    return args


if __name__ == '__main__':
    args = parse_arguments()
    args.run(args)

Use `set_defaults` of subparser to launch scripts
Use `set_defaults` of subparser to launch scripts

  
  import argparse
  import argcomplete
  import plotter
  
  def parse_arguments():
      """Argument Parser, providing available scripts"""
      parser = argparse.ArgumentParser()
      subparsers = parser.add_subparsers(
          title = 'plotter',
-         description = 'available plotting scripts'
+         description = 'available plotting scripts',
+         dest='used_subparser',
      )
      module_subparser = {}
      for module_str in plotter.__all__:
-         module = __import__('.'.join(('plotter', module_str)), fromlist=module_str)
+         module = __import__('plotter.' + module_str, fromlist=module_str)
          module_subparser[module_str] = subparsers.add_parser(
              module_str, parents=[module.get_parser(add_help=False)],
              help=module.__doc__.split('\n', 1)[0]
          )
+         module_subparser[module_str].set_defaults(run=module.main)
      configure = subparsers.add_parser('configure', help='configure this script.')
  
      argcomplete.autocomplete(parser)
      args = parser.parse_args()
      return args
  
  
  if __name__ == '__main__':
      args = parse_arguments()
-     from plotter.plotn import main
-     main(args)
+     args.run(args)
  
Use `set_defaults` of subparser to launch scripts
## Code Before:

import argparse
import argcomplete
import plotter

def parse_arguments():
    """Argument Parser, providing available scripts"""
    parser = argparse.ArgumentParser()
    subparsers = parser.add_subparsers(
        title = 'plotter',
        description = 'available plotting scripts'
    )
    module_subparser = {}
    for module_str in plotter.__all__:
        module = __import__('.'.join(('plotter', module_str)), fromlist=module_str)
        module_subparser[module_str] = subparsers.add_parser(
            module_str, parents=[module.get_parser(add_help=False)],
            help=module.__doc__.split('\n', 1)[0]
        )
    configure = subparsers.add_parser('configure', help='configure this script.')

    argcomplete.autocomplete(parser)
    args = parser.parse_args()
    return args


if __name__ == '__main__':
    args = parse_arguments()
    from plotter.plotn import main
    main(args)

## Instruction:
Use `set_defaults` of subparser to launch scripts
## Code After:

import argparse
import argcomplete
import plotter

def parse_arguments():
    """Argument Parser, providing available scripts"""
    parser = argparse.ArgumentParser()
    subparsers = parser.add_subparsers(
        title = 'plotter',
        description = 'available plotting scripts',
        dest='used_subparser',
    )
    module_subparser = {}
    for module_str in plotter.__all__:
        module = __import__('plotter.' + module_str, fromlist=module_str)
        module_subparser[module_str] = subparsers.add_parser(
            module_str, parents=[module.get_parser(add_help=False)],
            help=module.__doc__.split('\n', 1)[0]
        )
        module_subparser[module_str].set_defaults(run=module.main)
    configure = subparsers.add_parser('configure', help='configure this script.')

    argcomplete.autocomplete(parser)
    args = parser.parse_args()
    return args


if __name__ == '__main__':
    args = parse_arguments()
    args.run(args)
