# Path: vcstool/commands/help.py
# def get_entrypoint(command):
#     # accept command with same prefix if unique
#     commands = [cmd.command for cmd in vcstool_commands]
#     commands = [cmd for cmd in commands if cmd.startswith(command)]
#     if len(commands) != 1:
#         print(
#             "vcs: '%s' is not a vcs command. See 'vcs help'." % command,
#             file=sys.stderr)
#         if commands:
#             print(
#                 '\nDid you mean one of these?\n' + '\n   '.join(commands),
#                 file=sys.stderr)
#         return None
# 
#     return load_entry_point(
#         'vcstool', 'console_scripts', 'vcs-' + commands[0])
# 
# Path: vcstool/commands/help.py
# def get_parser(add_help=True):
#     parser = argparse.ArgumentParser(
#         prog='vcs', description=_get_description(),
#         epilog=_get_epilog(), add_help=add_help)
#     group = parser.add_mutually_exclusive_group()
#     group.add_argument(
#         'command', metavar='<command>', nargs='?',
#         help='The available commands: ' + ', '.join(
#             [cmd.command for cmd in vcstool_commands]))
#     group.add_argument(
#         '--clients', action='store_true', default=False,
#         help='Show the available VCS clients')
#     group.add_argument(
#         '--commands', action='store_true', default=False,
#         help='Output the available commands for auto-completion')
#     group.add_argument(
#         '--commands-descriptions', action='store_true', default=False,
#         help='Output the available commands along with their descriptions')
#     from vcstool import __version__
#     group.add_argument(
#         '--version', action='version', version='%(prog)s ' + __version__,
#         help='Show the vcstool version')
#     return parser
# 
# Path: vcstool/commands/help.py
# def main(args=None, stdout=None, stderr=None):
#     set_streams(stdout=stdout, stderr=stderr)
# 
#     # no help to extract command first (which might be followed by --help)
#     parser = get_parser(add_help=False)
#     ns, _ = parser.parse_known_args(args)
# 
#     # help for a specific command
#     if ns.command:
#         # relay help request foe specific command
#         entrypoint = get_entrypoint(ns.command)
#         if not entrypoint:
#             return 1
#         return entrypoint(['--help'])
# 
#     # regular parsing validating options and arguments
#     parser = get_parser()
#     ns = parser.parse_args(args)
# 
#     if ns.clients:
#         print('The available VCS clients are:')
#         for client in vcstool_clients:
#             print('  ' + client.type)
#         return 0
# 
#     if ns.commands:
#         print(' '.join([cmd.command for cmd in vcstool_commands]))
#         return 0
# 
#     if ns.commands_descriptions:
#         print('\n'.join(['{}\t{}'.format(cmd.command, cmd.help)
#                          for cmd in vcstool_commands]))
#         return 0
# 
#     # output detailed command list
#     parser = get_parser_with_command_only()
#     parser.print_help()
#     return 0
# 
# Path: vcstool/streams.py
# def set_streams(stdout=None, stderr=None):
#     _set_streams(stdout_=stdout, stderr_=stderr)


import sys
from vcstool.commands.help import get_entrypoint
from vcstool.commands.help import get_parser
from vcstool.commands.help import main as help_main
from vcstool.streams import set_streams



def main(args=None, stdout=None, stderr=None):
    set_streams(stdout=stdout, stderr=stderr)

    # no help to extract command first (which might be followed by --help)
    parser = get_parser(add_help=False)
    ns, _ = parser.parse_known_args(args)

# Path: vcstool/commands/help.py
# def get_entrypoint(command):
#     # accept command with same prefix if unique
#     commands = [cmd.command for cmd in vcstool_commands]
#     commands = [cmd for cmd in commands if cmd.startswith(command)]
#     if len(commands) != 1:
#         print(
#             "vcs: '%s' is not a vcs command. See 'vcs help'." % command,
#             file=sys.stderr)
#         if commands:
#             print(
#                 '\nDid you mean one of these?\n' + '\n   '.join(commands),
#                 file=sys.stderr)
#         return None
# 
#     return load_entry_point(
#         'vcstool', 'console_scripts', 'vcs-' + commands[0])
# 
# Path: vcstool/commands/help.py
# def get_parser(add_help=True):
#     parser = argparse.ArgumentParser(
#         prog='vcs', description=_get_description(),
#         epilog=_get_epilog(), add_help=add_help)
#     group = parser.add_mutually_exclusive_group()
#     group.add_argument(
#         'command', metavar='<command>', nargs='?',
#         help='The available commands: ' + ', '.join(
#             [cmd.command for cmd in vcstool_commands]))
#     group.add_argument(
#         '--clients', action='store_true', default=False,
#         help='Show the available VCS clients')
#     group.add_argument(
#         '--commands', action='store_true', default=False,
#         help='Output the available commands for auto-completion')
#     group.add_argument(
#         '--commands-descriptions', action='store_true', default=False,
#         help='Output the available commands along with their descriptions')
#     from vcstool import __version__
#     group.add_argument(
#         '--version', action='version', version='%(prog)s ' + __version__,
#         help='Show the vcstool version')
#     return parser
# 
# Path: vcstool/commands/help.py
# def main(args=None, stdout=None, stderr=None):
#     set_streams(stdout=stdout, stderr=stderr)
# 
#     # no help to extract command first (which might be followed by --help)
#     parser = get_parser(add_help=False)
#     ns, _ = parser.parse_known_args(args)
# 
#     # help for a specific command
#     if ns.command:
#         # relay help request foe specific command
#         entrypoint = get_entrypoint(ns.command)
#         if not entrypoint:
#             return 1
#         return entrypoint(['--help'])
# 
#     # regular parsing validating options and arguments
#     parser = get_parser()
#     ns = parser.parse_args(args)
# 
#     if ns.clients:
#         print('The available VCS clients are:')
#         for client in vcstool_clients:
#             print('  ' + client.type)
#         return 0
# 
#     if ns.commands:
#         print(' '.join([cmd.command for cmd in vcstool_commands]))
#         return 0
# 
#     if ns.commands_descriptions:
#         print('\n'.join(['{}\t{}'.format(cmd.command, cmd.help)
#                          for cmd in vcstool_commands]))
#         return 0
# 
#     # output detailed command list
#     parser = get_parser_with_command_only()
#     parser.print_help()
#     return 0
# 
# Path: vcstool/streams.py
# def set_streams(stdout=None, stderr=None):
#     _set_streams(stdout_=stdout, stderr_=stderr)


# Path: vcstool/commands/vcs.py
import sys
from vcstool.commands.help import get_entrypoint
from vcstool.commands.help import get_parser
from vcstool.commands.help import main as help_main
from vcstool.streams import set_streams




def main(args=None, stdout=None, stderr=None):
    set_streams(stdout=stdout, stderr=stderr)

    # no help to extract command first (which might be followed by --help)
    parser = get_parser(add_help=False)
    ns, _ = parser.parse_known_args(args)

    args = args if args is not None else sys.argv[1:]