from globus_cli.parser.shared_parser import GlobusCLISharedParser
from globus_cli.parser.command_tree import build_command_tree


def _gen_parser():
    """
    Produces a top-level argument parser built out of all of the various
    subparsers for different services.
    """
    # create the top parser and give it subparsers
    top_level_parser = GlobusCLISharedParser()
    subparsers = top_level_parser.add_subparsers(
        title='Commands',
        parser_class=GlobusCLISharedParser, metavar='')

    build_command_tree(subparsers)

    # return the created parser in all of its glory
    return top_level_parser


def _load_args():
    """
    Load commandline arguments, and do any necessary post-processing.
    """
    parser = _gen_parser()
    args = parser.parse_args()

    return args


def run_command():
    """
    Whatever arguments were loaded, they set a function to be invoked on the
    arguments themselves -- somewhat circular, but a nifty way of passing the
    args to a function that this module doesn't even know about
    """
    args = _load_args()
    args.func(args)

from __future__ import print_function

import sys

from globus_cli.parser.shared_parser import GlobusCLISharedParser
from globus_cli.parser.command_tree import build_command_tree


def _gen_parser():
    """
    Produces a top-level argument parser built out of all of the various
    subparsers for different services.
    """
    # create the top parser and give it subparsers
    top_level_parser = GlobusCLISharedParser()
    subparsers = top_level_parser.add_subparsers(
        title='Commands',
        parser_class=GlobusCLISharedParser, metavar='')

    build_command_tree(subparsers)

    # return the created parser in all of its glory
    return top_level_parser


def _load_args():
    """
    Load commandline arguments, and do any necessary post-processing.
    """
    parser = _gen_parser()
    args = parser.parse_args()

    return args


def run_command():
    """
    Whatever arguments were loaded, they set a function to be invoked on the
    arguments themselves -- somewhat circular, but a nifty way of passing the
    args to a function that this module doesn't even know about
    """
    args = _load_args()
    try:
        args.func(args)
    except NotImplementedError as e:
        print('NotImplementedError: {}'.format(e.message), file=sys.stderr)
        sys.exit(1)

Add special handling for NotImplementedError
Add special handling for NotImplementedError

If the function called by run_command() raises a NotImplementedError,
don't print the full stacktrace. Do a mild amount of custom formatting,
then exit with status 1 (failure).

+ from __future__ import print_function
+ 
+ import sys
+ 
  from globus_cli.parser.shared_parser import GlobusCLISharedParser
  from globus_cli.parser.command_tree import build_command_tree
  
  
  def _gen_parser():
      """
      Produces a top-level argument parser built out of all of the various
      subparsers for different services.
      """
      # create the top parser and give it subparsers
      top_level_parser = GlobusCLISharedParser()
      subparsers = top_level_parser.add_subparsers(
          title='Commands',
          parser_class=GlobusCLISharedParser, metavar='')
  
      build_command_tree(subparsers)
  
      # return the created parser in all of its glory
      return top_level_parser
  
  
  def _load_args():
      """
      Load commandline arguments, and do any necessary post-processing.
      """
      parser = _gen_parser()
      args = parser.parse_args()
  
      return args
  
  
  def run_command():
      """
      Whatever arguments were loaded, they set a function to be invoked on the
      arguments themselves -- somewhat circular, but a nifty way of passing the
      args to a function that this module doesn't even know about
      """
      args = _load_args()
+     try:
-     args.func(args)
+         args.func(args)
+     except NotImplementedError as e:
+         print('NotImplementedError: {}'.format(e.message), file=sys.stderr)
+         sys.exit(1)
  
Add special handling for NotImplementedError
## Code Before:
from globus_cli.parser.shared_parser import GlobusCLISharedParser
from globus_cli.parser.command_tree import build_command_tree


def _gen_parser():
    """
    Produces a top-level argument parser built out of all of the various
    subparsers for different services.
    """
    # create the top parser and give it subparsers
    top_level_parser = GlobusCLISharedParser()
    subparsers = top_level_parser.add_subparsers(
        title='Commands',
        parser_class=GlobusCLISharedParser, metavar='')

    build_command_tree(subparsers)

    # return the created parser in all of its glory
    return top_level_parser


def _load_args():
    """
    Load commandline arguments, and do any necessary post-processing.
    """
    parser = _gen_parser()
    args = parser.parse_args()

    return args


def run_command():
    """
    Whatever arguments were loaded, they set a function to be invoked on the
    arguments themselves -- somewhat circular, but a nifty way of passing the
    args to a function that this module doesn't even know about
    """
    args = _load_args()
    args.func(args)

## Instruction:
Add special handling for NotImplementedError
## Code After:
from __future__ import print_function

import sys

from globus_cli.parser.shared_parser import GlobusCLISharedParser
from globus_cli.parser.command_tree import build_command_tree


def _gen_parser():
    """
    Produces a top-level argument parser built out of all of the various
    subparsers for different services.
    """
    # create the top parser and give it subparsers
    top_level_parser = GlobusCLISharedParser()
    subparsers = top_level_parser.add_subparsers(
        title='Commands',
        parser_class=GlobusCLISharedParser, metavar='')

    build_command_tree(subparsers)

    # return the created parser in all of its glory
    return top_level_parser


def _load_args():
    """
    Load commandline arguments, and do any necessary post-processing.
    """
    parser = _gen_parser()
    args = parser.parse_args()

    return args


def run_command():
    """
    Whatever arguments were loaded, they set a function to be invoked on the
    arguments themselves -- somewhat circular, but a nifty way of passing the
    args to a function that this module doesn't even know about
    """
    args = _load_args()
    try:
        args.func(args)
    except NotImplementedError as e:
        print('NotImplementedError: {}'.format(e.message), file=sys.stderr)
        sys.exit(1)
