.. versionadded:: 0.17.0

    Sets alternative for <name> to <path>, if <path> is defined
    as an alternative for <name>.

    name
        is the master name for this link group
        (e.g. pager)

    path
        is the location of one of the alternative target files.
        (e.g. /usr/bin/less)

    .. code-block:: yaml

        foo:
          alternatives.set:
            - path: /usr/bin/foo-2.0

def set_(name, path):
    '''
    .. versionadded:: 0.17.0

    Sets alternative for <name> to <path>, if <path> is defined
    as an alternative for <name>.

    name
        is the master name for this link group
        (e.g. pager)

    path
        is the location of one of the alternative target files.
        (e.g. /usr/bin/less)

    .. code-block:: yaml

        foo:
          alternatives.set:
            - path: /usr/bin/foo-2.0
    '''
    ret = {'name': name,
           'path': path,
           'result': True,
           'changes': {},
           'comment': ''}

    current = __salt__['alternatives.show_current'](name)
    if current == path:
        ret['comment'] = 'Alternative for {0} already set to {1}'.format(name, path)
        return ret

    display = __salt__['alternatives.display'](name)
    isinstalled = False
    for line in display.splitlines():
        if line.startswith(path):
            isinstalled = True
            break

    if isinstalled:
        if __opts__['test']:
            ret['comment'] = (
                'Alternative for {0} will be set to path {1}'
            ).format(name, path)
            ret['result'] = None
            return ret
        __salt__['alternatives.set'](name, path)
        current = __salt__['alternatives.show_current'](name)
        if current == path:
            ret['comment'] = (
                'Alternative for {0} set to path {1}'
            ).format(name, current)
            ret['changes'] = {'path': current}
        else:
            ret['comment'] = 'Alternative for {0} not updated'.format(name)

        return ret

    else:
        ret['result'] = False
        ret['comment'] = (
            'Alternative {0} for {1} doesn\'t exist'
            ).format(path, name)

    return ret