# Path: gh/base.py
# class Command(object):
# class CustomOptionParser(OptionParser):
#     SUCCESS = 0
#     FAILURE = 1
#     COMMAND_UNKNOWN = 127
#     def __init__(self):
#     def run(self, options, args):
#     def get_repo(self, options):
#     def get_user(self):
#     def login(self):
#     def help(self):
#     def __init__(self, *args, **kwargs):
# def load_command(name):
# 
# Path: gh/util.py
# def get_repository_tuple():
#     """Parse the git config file for this repository if it exists.
# 
#     :returns: namedtuple with attributes, owner and repo
#     """
#     # If there are multiple remotes, this could choose the wrong one
#     reg = compile(
#         '(?:https://|git@)github\.com(?::|/)([^\./-]*)/(.*)'
#     )
#     config = find_git_config()
#     r = ()
#     if config:
#         fd = open(config)
#         for line in fd:
#             match = reg.search(line)
#             if match and match.groups():
#                 r = match.groups()
#                 break
# 
#         fd.close()
# 
#     if r and r[1].endswith('.git'):
#         r = (r[0], r[1][:-4])
#     return r


from gh.base import main_parser, load_command, commands
from gh.util import get_repository_tuple
import sys


def main():
    opts, args = main_parser.parse_args()

    if opts.help and not args:
        args = ['help']

    if not args:
        main_parser.error('You must give a command. '
                          '(Use `gh help` to see a list of commands)')

    repository = ()
    if opts.repository and '/' in opts.repository:
        repository = opts.repository.split('/', 1)

    if opts.loc_aware and not repository:
        repository = get_repository_tuple()

    command = args[0].lower()
    load_command(command)
    status = 1

    if command in commands:
        commands[command].repository = repository
        status = commands[command].run(opts, args[1:])

# Path: gh/base.py
# class Command(object):
# class CustomOptionParser(OptionParser):
#     SUCCESS = 0
#     FAILURE = 1
#     COMMAND_UNKNOWN = 127
#     def __init__(self):
#     def run(self, options, args):
#     def get_repo(self, options):
#     def get_user(self):
#     def login(self):
#     def help(self):
#     def __init__(self, *args, **kwargs):
# def load_command(name):
# 
# Path: gh/util.py
# def get_repository_tuple():
#     """Parse the git config file for this repository if it exists.
# 
#     :returns: namedtuple with attributes, owner and repo
#     """
#     # If there are multiple remotes, this could choose the wrong one
#     reg = compile(
#         '(?:https://|git@)github\.com(?::|/)([^\./-]*)/(.*)'
#     )
#     config = find_git_config()
#     r = ()
#     if config:
#         fd = open(config)
#         for line in fd:
#             match = reg.search(line)
#             if match and match.groups():
#                 r = match.groups()
#                 break
# 
#         fd.close()
# 
#     if r and r[1].endswith('.git'):
#         r = (r[0], r[1][:-4])
#     return r


# Path: gh/main.py
from gh.base import main_parser, load_command, commands
from gh.util import get_repository_tuple
import sys



def main():
    opts, args = main_parser.parse_args()

    if opts.help and not args:
        args = ['help']

    if not args:
        main_parser.error('You must give a command. '
                          '(Use `gh help` to see a list of commands)')

    repository = ()
    if opts.repository and '/' in opts.repository:
        repository = opts.repository.split('/', 1)

    if opts.loc_aware and not repository:
        repository = get_repository_tuple()

    command = args[0].lower()
    load_command(command)
    status = 1

    if command in commands:
        commands[command].repository = repository
        status = commands[command].run(opts, args[1:])

        if status == commands[command].COMMAND_UNKNOWN: