def list_(
        pkg=None,
        user=None,
        installed=False,
        env=None):
    '''
    List packages matching a search string.

    pkg
        Search string for matching package names
    user
        The user to run cabal list with
    installed
        If True, only return installed packages.
    env
        Environment variables to set when invoking cabal. Uses the
        same ``env`` format as the :py:func:`cmd.run
        <salt.modules.cmdmod.run>` execution function

    CLI example:

    .. code-block:: bash

        salt '*' cabal.list
        salt '*' cabal.list ShellCheck
    '''
    cmd = ['cabal list --simple-output']

    if installed:
        cmd.append('--installed')

    if pkg:
        cmd.append('"{0}"'.format(pkg))

    result = __salt__['cmd.run_all'](' '.join(cmd), runas=user, env=env)

    packages = {}
    for line in result['stdout'].splitlines():
        data = line.split()
        package_name = data[0]
        package_version = data[1]
        packages[package_name] = package_version

    return packages
List packages matching a search string.

    pkg
        Search string for matching package names
    user
        The user to run cabal list with
    installed
        If True, only return installed packages.
    env
        Environment variables to set when invoking cabal. Uses the
        same ``env`` format as the :py:func:`cmd.run
        <salt.modules.cmdmod.run>` execution function

    CLI example:

    .. code-block:: bash

        salt '*' cabal.list
        salt '*' cabal.list ShellCheck