def _build_parameters(host, tile_dir, tiles_port, ui_port):
    """Helper to build the parameters needed for starting tilestream.

    :param tile_dir: Optional directory on the remote host that holds one or
        more mbtiles files to be published. If ommitted the default of
        `~/Documents/MapBox/tiles` will be used by tilestream.
    :type tile_dir: str

    :param ui_port: Port on which the tilestream ui should be available.
    :type ui_port: int

    :param tiles_port: Port on which tilestream tile service should be
        available. You may want to use a different port here and then run a
        CDN such as cloudflare in front of the tile service.
    :type tiles_port: int

    :param host: Host name under which the service will run. Must match the
        hostname to which requests are made (even if you run it behind mod
        proxy).
    :type host: str

    :returns: A string containing parameters for starting tilestream.
    :rtype: str
    """
    params = ''
    if tile_dir is not None:
        params += ' --tiles=%s' % tile_dir
    params += ' --uiPort=%i' % ui_port
    params += ' --tilePort=%i' % tiles_port
    if host is not None:
        params += ' --host=%s' % host
    return params
