#!/usr/bin/python
import sys
import getopt
from viprdatacli.fileaccess import ViprUmount, ViprScriptError

def cliHelp(script_name):
    print 'usage: ' + script_name + ' [-h] [local_dir]'
    print 'options:'
    print '    -h                 : print this help text'
    print '    local_dir          : the local directory under which mount points'
    print '                         were created (defaults to .)'

#main
if __name__ == '__main__':
    #----------------------------------------------------------------------
    # command-line parsing
    #----------------------------------------------------------------------
    opts, leftover = getopt.getopt(sys.argv[1:], "h")
    options = dict(opts)
    
    if ("-h" in options):
        cliHelp(sys.argv[0])
        exit(1)

    parent_dir = '.'
    if (len(leftover) > 0):
        parent_dir = leftover[0]
    
    try:
        vumount = ViprUmount(parent_dir)
        vumount.execute()
    except Exception as e:
        print e.message
        exit(2)
