#!/usr/bin/env python
#TODO: This is a template for a script that is trying to get the variable
#      CHPL_(HOST|TARGET)_FOOBAR, the module (file) name should be
#      chpl_foobar.py. To put it more generally, the module name should be the
#      lowercased environment variable, with any varying words removed.
import os, optparse
from sys import stdout, stderr

import utils
from utils import memoize

#TODO: @memoize causes the calls to this function to get cached
@memoize
def get(flag='host'):
    if flag == 'host':
        FOOBAR_val = os.environ.get('CHPL_HOST_FOOBAR', '')
    elif flag == 'target':
        FOOBAR_val = os.environ.get('CHPL_TARGET_FOOBAR', '')
    else:
        raise ValueError("Invalid flag: '{0}'".format(flag))

    if not FOOBAR_val:
        #TODO: Set the default for FOOBAR_val

    return FOOBAR_val


def _main():
    #TODO: If you don't need to parse options, remove these lines through parser.parse_args()
    parser = optparse.OptionParser(usage='usage: %prog [--host|target])')
    parser.add_option('--host', dest='flag', action='store_const',
                      const='host', default='host')
    parser.add_option('--target', dest='flag', action='store_const',
                      const='target')
    (options, args) = parser.parse_args()

    FOOBAR_val = get(options.flag)
    stdout.write("{0}\n".format(compiler_val))


if __name__ == '__main__':
    _main()
