#!/bin/bash
#
# Copyright (c) 2020 Bubble, Inc.  All rights reserved. For personal (non-commercial) use, see license: https://getbubblenow.com/bubble-license/
#
#
# Write a constant value to stdout.
#
# This will only ever write the constant value to stdout if it can successfully be read.
# If the constant can be read, its value is printed with the .toString() method.
# If an error occurs, nothing is written to stdout, and the error will be written to stderr.
# If the value of the constant is null, nothing is printed to stdout, and "null" is printed to stderr.
#
# Usage:
#
#     bconst classAndMember
#
#   classAndMember   : the full name of a Java class, followed by a dot and the constant member name
#
# For example:
#
#     bconst bubble.ApiConstants.ROOT_NETWORK_UUID
#
# Environment variables
#
#   BUBBLE_API     : which API to use. Default is local (http://127.0.0.1:PORT, where PORT is found in .bubble.env)
#   BUBBLE_USER    : account to use. Default is root
#   BUBBLE_PASS    : password for account. Default is root
#   BUBBLE_INCLUDE : path to look for JSON include files. default value is to assume we are being run from
#                      bubble repo, bubble-models repo, or bubble-client and use include files from minimal model.
#
SCRIPT="${0}"
SCRIPT_DIR=$(cd $(dirname ${SCRIPT}) && pwd)
. ${SCRIPT_DIR}/bubble_common

CLASS_AND_MEMBER="${1:?sole param should be something like: bubble.pkg.SomeClass.SOME_CONSTANT}"
shift

BUBBLE_QUIET=1 exec ${SCRIPT_DIR}/bubble const "${CLASS_AND_MEMBER}" "${@}"
