# Path: gh/base.py
# class Command(object):
#     __metaclass__ = ABCMeta
#     name = None
#     usage = None
#     repository = ()
#     user = ''
#     subcommands = {}
#     SUCCESS = 0
#     FAILURE = 1
#     COMMAND_UNKNOWN = 127
# 
#     def __init__(self):
#         super(Command, self).__init__()
#         assert self.name
#         commands[self.name] = self
#         self.gh = GitHub()
#         self.gh.set_user_agent('github-cli/{0} (http://git.io/MEmEmw)'.format(
#             __version__
#         ))
#         self.parser = CustomOptionParser(usage=self.usage)
# 
#     @abstractmethod
#     def run(self, options, args):
#         return self.FAILURE
# 
#     def get_repo(self, options):
#         self.repo = None
#         if self.repository:
#             self.repo = self.gh.repository(*self.repository)
# 
#         if not (self.repo or options.loc_aware):
#             self.parser.error('A repository is required.')
# 
#     def get_user(self):
#         if not self.user:
#             self.login()
#             self.user = self.gh.user()
# 
#     def login(self):
#         # Get the full path to the configuration file
#         config = github_config()
#         parser = ConfigParser()
# 
#         # Check to make sure the file exists and we are allowed to read it
#         if os.path.isfile(config) and os.access(config, os.R_OK | os.W_OK):
#             parser.readfp(open(config))
#             self.gh.login(token=parser.get('github', 'token'))
#         else:
#         # Either the file didn't exist or we didn't have the correct
#         # permissions
#             user = ''
#             while not user:
#                 # We will not stop until we are given a username
#                 user = input('Username: ')
# 
#             self.user = user
# 
#             pw = ''
#             while not pw:
#                 # Nor will we stop until we're given a password
#                 pw = getpass('Password: ')
# 
#             # Get an authorization for this
#             auth = self.gh.authorize(
#                 user, pw, ['user', 'repo', 'gist'], 'github-cli',
#                 'http://git.io/MEmEmw'
#             )
#             parser.add_section('github')
#             parser.set('github', 'token', auth.token)
#             self.gh.login(token=auth.token)
#             # Create the file if it doesn't exist. Otherwise completely blank
#             # out what was there before. Kind of dangerous and destructive but
#             # somewhat necessary
#             parser.write(open(config, 'w+'))
# 
#     def help(self):
#         self.parser.print_help()
#         if self.subcommands:
#             print('\nSubcommands:')
#             for command in sorted(self.subcommands.keys()):
#                 print('  {0}:\n\t{1}'.format(
#                     command, self.subcommands[command]
#                 ))
#         sys.exit(0)
# 
# Path: gh/util.py
# def get_repository_tuple():
# def find_git_config():
# def github_config():
# def trim_numbers(number):
# def read_stdin():
# def mktmpfile(prefix='gh-'):
# def rmtmpfile(name):
# def wrap(text):
# def get_issue_number(args, parser, error):
# 
# Path: gh/compat.py
# def fix_encoding(content):
#     if sys.version_info < (3, 0):
#         return content.encode('ascii', 'replace')
#     return content


from gh.base import Command
from gh.util import tc
from gh.compat import fix_encoding
                               default=-1,
                               )

    def run(self, options, args):
        self.get_repo(options)

        opts, args = self.parser.parse_args(args)

        if opts.help:
            self.help()

        return self.print_issues(opts)

    # Formatting and printing
    def format_short_issue(self, issue):
        extra = []

        if issue.milestone:
            extra.append(issue.milestone.title)

        if issue.assignee:
            extra.append(issue.assignee.login)

        if extra:
            extra = ' (' + ' -- '.join(extra) + ')'
        else:
            extra = ''

        issue.title = fix_encoding(issue.title)


# Path: gh/base.py
# class Command(object):
#     __metaclass__ = ABCMeta
#     name = None
#     usage = None
#     repository = ()
#     user = ''
#     subcommands = {}
#     SUCCESS = 0
#     FAILURE = 1
#     COMMAND_UNKNOWN = 127
# 
#     def __init__(self):
#         super(Command, self).__init__()
#         assert self.name
#         commands[self.name] = self
#         self.gh = GitHub()
#         self.gh.set_user_agent('github-cli/{0} (http://git.io/MEmEmw)'.format(
#             __version__
#         ))
#         self.parser = CustomOptionParser(usage=self.usage)
# 
#     @abstractmethod
#     def run(self, options, args):
#         return self.FAILURE
# 
#     def get_repo(self, options):
#         self.repo = None
#         if self.repository:
#             self.repo = self.gh.repository(*self.repository)
# 
#         if not (self.repo or options.loc_aware):
#             self.parser.error('A repository is required.')
# 
#     def get_user(self):
#         if not self.user:
#             self.login()
#             self.user = self.gh.user()
# 
#     def login(self):
#         # Get the full path to the configuration file
#         config = github_config()
#         parser = ConfigParser()
# 
#         # Check to make sure the file exists and we are allowed to read it
#         if os.path.isfile(config) and os.access(config, os.R_OK | os.W_OK):
#             parser.readfp(open(config))
#             self.gh.login(token=parser.get('github', 'token'))
#         else:
#         # Either the file didn't exist or we didn't have the correct
#         # permissions
#             user = ''
#             while not user:
#                 # We will not stop until we are given a username
#                 user = input('Username: ')
# 
#             self.user = user
# 
#             pw = ''
#             while not pw:
#                 # Nor will we stop until we're given a password
#                 pw = getpass('Password: ')
# 
#             # Get an authorization for this
#             auth = self.gh.authorize(
#                 user, pw, ['user', 'repo', 'gist'], 'github-cli',
#                 'http://git.io/MEmEmw'
#             )
#             parser.add_section('github')
#             parser.set('github', 'token', auth.token)
#             self.gh.login(token=auth.token)
#             # Create the file if it doesn't exist. Otherwise completely blank
#             # out what was there before. Kind of dangerous and destructive but
#             # somewhat necessary
#             parser.write(open(config, 'w+'))
# 
#     def help(self):
#         self.parser.print_help()
#         if self.subcommands:
#             print('\nSubcommands:')
#             for command in sorted(self.subcommands.keys()):
#                 print('  {0}:\n\t{1}'.format(
#                     command, self.subcommands[command]
#                 ))
#         sys.exit(0)
# 
# Path: gh/util.py
# def get_repository_tuple():
# def find_git_config():
# def github_config():
# def trim_numbers(number):
# def read_stdin():
# def mktmpfile(prefix='gh-'):
# def rmtmpfile(name):
# def wrap(text):
# def get_issue_number(args, parser, error):
# 
# Path: gh/compat.py
# def fix_encoding(content):
#     if sys.version_info < (3, 0):
#         return content.encode('ascii', 'replace')
#     return content


# Path: gh/commands/issue/ls.py
from gh.base import Command
from gh.util import tc
from gh.compat import fix_encoding

                               default=-1,
                               )

    def run(self, options, args):
        self.get_repo(options)

        opts, args = self.parser.parse_args(args)

        if opts.help:
            self.help()

        return self.print_issues(opts)

    # Formatting and printing
    def format_short_issue(self, issue):
        extra = []

        if issue.milestone:
            extra.append(issue.milestone.title)

        if issue.assignee:
            extra.append(issue.assignee.login)

        if extra:
            extra = ' (' + ' -- '.join(extra) + ')'
        else:
            extra = ''

        issue.title = fix_encoding(issue.title)


        return (self.fs.format(issue, bold=tc['bold'], default=tc['default'])