#!python
# vim: set filetype=python

# Copyright 2015-2017 Lionheart Software LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import argparse

from github_issues_tools.github_issues_tools import GitHubIssuesTools

if __name__ == "__main__":
    parser = argparse.ArgumentParser(prog='github-issues-tools')
    subparsers = parser.add_subparsers()

    parser_export_labels = subparsers.add_parser("export-labels", help="Export all labels from a repository.")
    parser_export_labels.set_defaults(command="export-labels")
    parser_export_labels.add_argument("--api-key")
    parser_export_labels.add_argument("--organization")
    parser_export_labels.add_argument("--repository")

    parser_copy_labels = subparsers.add_parser("copy-labels", help="Copies labels from one repository to another.")
    parser_copy_labels.set_defaults(command="copy-labels")
    parser_copy_labels.add_argument("--api-key")
    parser_copy_labels.add_argument("--source-organization")
    parser_copy_labels.add_argument("--source-repository")
    parser_copy_labels.add_argument("--target-organization")
    parser_copy_labels.add_argument("--target-repository")

    args = parser.parse_args()
    if args.api_key is None:
        parser.print_help()
    else:
        github_issues_tools = GitHubIssuesTools(args.api_key)
        if args.command == "copy-labels":
            github_issues_tools.copy_labels(
                source_organization=args.source_organization,
                source_repository=args.source_repository,
                target_organization=args.target_organization,
                target_repository=args.target_repository,
            )
        elif args.command == "export-labels":
            github_issues_tools.export_labels(
                organization=args.organization,
                repository=args.repository,
            )

