Return goal(s) for a file or directory

    CLI Example:

    .. code-block:: bash

        salt '*' moosefs.getgoal /path/to/file [-[n][h|H]]
        salt '*' moosefs.getgoal /path/to/dir/ [-[n][h|H][r]]

def getgoal(path, opts=None):
    '''
    Return goal(s) for a file or directory

    CLI Example:

    .. code-block:: bash

        salt '*' moosefs.getgoal /path/to/file [-[n][h|H]]
        salt '*' moosefs.getgoal /path/to/dir/ [-[n][h|H][r]]
    '''
    cmd = 'mfsgetgoal'
    ret = {}
    if opts:
        cmd += ' -' + opts
    else:
        opts = ''
    cmd += ' ' + path
    out = __salt__['cmd.run_all'](cmd, python_shell=False)

    output = out['stdout'].splitlines()
    if 'r' not in opts:
        goal = output[0].split(': ')
        ret = {
            'goal': goal[1],
        }
    else:
        for line in output:
            if not line:
                continue
            if path in line:
                continue
            comps = line.split()
            keytext = comps[0] + ' with goal'
            if keytext not in ret:
                ret[keytext] = {}
            ret[keytext][comps[3]] = comps[5]
    return ret