#!/usr/bin/env python
#
# Copyright (C) 2013-2016 DNAnexus, Inc.
#
# This file is part of dx-toolkit (DNAnexus platform client libraries).
#
#   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 json, argparse

parser = argparse.ArgumentParser(description='Creates a DNAnexus link from an object ID or "<project ID>:<object ID>" string.  The result is of the form {"$dnanexus_link": "<object ID>"} or {"$dnanexus_link": {"project": <project ID>, "id": <object ID>}}, as appropriate.')
parser.add_argument('object', help='Data object ID or "<Project ID>:<Data object ID>" to package into a DNAnexus link')
args = parser.parse_args()

if ':' in args.object:
    proj_id, obj_id = args.object.split(":")
    print(json.dumps({"$dnanexus_link": {"project": proj_id, "id": obj_id}}))
else:
    print(json.dumps({"$dnanexus_link": args.object}))
