# Buggy code
def serve(
    config_file=None,
    dev_addr=None,
    strict=None,
    theme=None,
    theme_dir=None,
    livereload="livereload",
):
    """
    Start the MkDocs development server

    By default it will serve the documentation on http://localhost:8000/ and
    it will rebuild the documentation and refresh the page automatically
    whenever a file is edited.
    """

    # Create a temporary build directory, and set some options to serve it
    tempdir = tempfile.mkdtemp()

    def builder():
        log.info("Building documentation...")
        config = load_config(
            config_file=config_file,
            dev_addr=dev_addr,
            strict=strict,
            theme=theme,
            theme_dir=theme_dir,
        )
        config["site_dir"] = tempdir
        live_server = livereload in ["dirty", "livereload"]
        dirty = livereload == "dirty"
        build(config, live_server=live_server, dirty=dirty)
        return config

    # Perform the initial build
    config = builder()

    host, port = config["dev_addr"].split(":", 1)

    try:
        if livereload in ["livereload", "dirty"]:
            _livereload(host, port, config, builder, tempdir)
        else:
            _static_server(host, port, tempdir)
    finally:
        shutil.rmtree(tempdir)


# Traceback (ValueError)
INFO    -  Building documentation...
INFO    -  Cleaning site directory
Traceback (most recent call last):
File "/home/sybren/.virtualenvs/flamenco/bin/mkdocs", line 11, in <module>
sys.exit(cli())
File "/home/sybren/.virtualenvs/flamenco/lib/python3.6/site-packages/click/core.py", line 722, in __call__
return self.main(*args, **kwargs)
File "/home/sybren/.virtualenvs/flamenco/lib/python3.6/site-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/home/sybren/.virtualenvs/flamenco/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/sybren/.virtualenvs/flamenco/lib/python3.6/site-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/sybren/.virtualenvs/flamenco/lib/python3.6/site-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/home/sybren/.virtualenvs/flamenco/lib/python3.6/site-packages/mkdocs/__main__.py", line 127, in serve_command
livereload=livereload
File "/home/sybren/.virtualenvs/flamenco/lib/python3.6/site-packages/mkdocs/commands/serve.py", line 116, in serve
_livereload(host, port, config, builder, tempdir)
File "/home/sybren/.virtualenvs/flamenco/lib/python3.6/site-packages/mkdocs/commands/serve.py", line 55, in _livereload
server.serve(root=site_dir, host=host, port=int(port), restart_delay=0)
ValueError: invalid literal for int() with base 10: ':0]:8081'

# Fixed code
def serve(
    config_file=None,
    dev_addr=None,
    strict=None,
    theme=None,
    theme_dir=None,
    livereload="livereload",
):
    """
    Start the MkDocs development server

    By default it will serve the documentation on http://localhost:8000/ and
    it will rebuild the documentation and refresh the page automatically
    whenever a file is edited.
    """

    # Create a temporary build directory, and set some options to serve it
    tempdir = tempfile.mkdtemp()

    def builder():
        log.info("Building documentation...")
        config = load_config(
            config_file=config_file,
            dev_addr=dev_addr,
            strict=strict,
            theme=theme,
            theme_dir=theme_dir,
        )
        config["site_dir"] = tempdir
        live_server = livereload in ["dirty", "livereload"]
        dirty = livereload == "dirty"
        build(config, live_server=live_server, dirty=dirty)
        return config

    try:
        # Perform the initial build
        config = builder()

        host, port = config["dev_addr"]

        if livereload in ["livereload", "dirty"]:
            _livereload(host, port, config, builder, tempdir)
        else:
            _static_server(host, port, tempdir)
    finally:
        shutil.rmtree(tempdir)