# Path: ghtools/cli.py
# def catch_api_errors():
# def fail(message, exit_code=1):
# def get_client(nickname):
# def parse_identifier(identifier, require_repo=False):
# 
# Path: ghtools/github/organisation.py
# class Organisation(object):
# 
#     def __init__(self, org, client=None):
#         self._ident = Identifier.from_string(org)
#         self.org = self._ident.org
#         self.client = client or make_client(self._ident)
# 
#     def add_team_member(self, team, login):
#         self.client.put('/teams/{0}/members/{1}'.format(team['id'], login), data=' ')
# 
#     def add_team_repo(self, team, repo_name):
#         self.client.put('/teams/{0}/repos/{1}/{2}'.format(team['id'], self.org, repo_name), data=' ')
# 
#     def create_repo(self, repo):
#         keys = [
#             'name',
#             'description',
#             'homepage',
#             'private',
#             'has_issues',
#             'has_wiki',
#             'has_downloads'
#         ]
#         payload = dict((k, repo[k]) for k in keys)
#         res = self.client.post('/orgs/{0}/repos'.format(self.org), data=payload)
#         return res.json()
# 
#     def create_team(self, team):
#         res = self.client.post('/orgs/{0}/teams'.format(self.org), data=team)
#         return res.json()
# 
#     def get_repo(self, repo):
#         url = '/repos/{0}/{1}'.format(self.org, repo)
#         res = self.client.get(url)
#         return res.json()
# 
#     def list_members(self):
#         return self.client.paged_get('/orgs/{0}/members'.format(self.org))
# 
#     def list_repos(self):
#         return self.client.paged_get('/orgs/{0}/repos'.format(self.org))
# 
#     def list_teams(self):
#         return self.client.paged_get('/orgs/{0}/teams'.format(self.org))
# 
#     def list_team_members(self, team):
#         return self.client.paged_get('/teams/{0}/members'.format(team['id']))
# 
#     def list_team_repos(self, team):
#         return self.client.paged_get('/teams/{0}/repos'.format(team['id']))
# 
# 
#     def __str__(self):
#         return '<Organisation {0}>'.format(self._ident)


import json
from argh import ArghParser, arg
from ghtools import cli
from ghtools.github.organisation import Organisation
parser.add_argument('org',
                    help='Organisation identifier '
                         '(e.g. rails, enterprise:mycorp)')

json_arg = arg('-j', '--json',
               default=False,
               action='store_true',
               help='Print full JSON representations')


@json_arg
def repos(args):
    """
    Print a list of organisation repositories
    """
    with cli.catch_api_errors():
        org = Organisation(args.org)
        for repo in org.list_repos():
            if args.json:
                print(json.dumps(repo, indent=2))
            else:
                print(repo['name'])
parser.add_commands([repos])


@json_arg
def members(args):
    """
    Print a list of organisation members
    """

# Path: ghtools/cli.py
# def catch_api_errors():
# def fail(message, exit_code=1):
# def get_client(nickname):
# def parse_identifier(identifier, require_repo=False):
# 
# Path: ghtools/github/organisation.py
# class Organisation(object):
# 
#     def __init__(self, org, client=None):
#         self._ident = Identifier.from_string(org)
#         self.org = self._ident.org
#         self.client = client or make_client(self._ident)
# 
#     def add_team_member(self, team, login):
#         self.client.put('/teams/{0}/members/{1}'.format(team['id'], login), data=' ')
# 
#     def add_team_repo(self, team, repo_name):
#         self.client.put('/teams/{0}/repos/{1}/{2}'.format(team['id'], self.org, repo_name), data=' ')
# 
#     def create_repo(self, repo):
#         keys = [
#             'name',
#             'description',
#             'homepage',
#             'private',
#             'has_issues',
#             'has_wiki',
#             'has_downloads'
#         ]
#         payload = dict((k, repo[k]) for k in keys)
#         res = self.client.post('/orgs/{0}/repos'.format(self.org), data=payload)
#         return res.json()
# 
#     def create_team(self, team):
#         res = self.client.post('/orgs/{0}/teams'.format(self.org), data=team)
#         return res.json()
# 
#     def get_repo(self, repo):
#         url = '/repos/{0}/{1}'.format(self.org, repo)
#         res = self.client.get(url)
#         return res.json()
# 
#     def list_members(self):
#         return self.client.paged_get('/orgs/{0}/members'.format(self.org))
# 
#     def list_repos(self):
#         return self.client.paged_get('/orgs/{0}/repos'.format(self.org))
# 
#     def list_teams(self):
#         return self.client.paged_get('/orgs/{0}/teams'.format(self.org))
# 
#     def list_team_members(self, team):
#         return self.client.paged_get('/teams/{0}/members'.format(team['id']))
# 
#     def list_team_repos(self, team):
#         return self.client.paged_get('/teams/{0}/repos'.format(team['id']))
# 
# 
#     def __str__(self):
#         return '<Organisation {0}>'.format(self._ident)


# Path: ghtools/command/org.py
import json
from argh import ArghParser, arg
from ghtools import cli
from ghtools.github.organisation import Organisation

parser.add_argument('org',
                    help='Organisation identifier '
                         '(e.g. rails, enterprise:mycorp)')

json_arg = arg('-j', '--json',
               default=False,
               action='store_true',
               help='Print full JSON representations')


@json_arg
def repos(args):
    """
    Print a list of organisation repositories
    """
    with cli.catch_api_errors():
        org = Organisation(args.org)
        for repo in org.list_repos():
            if args.json:
                print(json.dumps(repo, indent=2))
            else:
                print(repo['name'])
parser.add_commands([repos])


@json_arg
def members(args):
    """
    Print a list of organisation members
    """

    with cli.catch_api_errors():