def panfl(filters, to, search_dirs, data_dir, sys_path):
    """
    Allows Panflute to be run as a command line executable:

    * to be used in Pandoctools shell scripts as Pandoc filter with
      multiple arguments (should have -t/--to option in this case):
      ``pandoc -t json | panfl -t markdown foo.bar | pandoc -f json``

    * to be used as a Pandoc filter (in this case only one positional
      argument is allowed of all options):
      ``pandoc --filter panfl``

    MIND THAT Panflute temporarily prepends folder of the filter
    (or relevant dir provided if module spec) TO THE `sys.path` before
    importing the filter!
    """
    if to is None:
        if (len(filters) > 1) or search_dirs or not sys_path or data_dir:
            raise ValueError('When no `--to` option then Pandoc filter mode assumed and ' +
                             'only one positional argument is allowed of all options.')
        else:
            filters, search_dirs = None, None
            sys_path, data_dir = True, False
    else:
        filters, search_dirs = list(filters), list(search_dirs)
        # `load()` in `stdio()` needs `to` in the 2nd arg
        sys.argv[1:] = []
        sys.argv.append(to)

    stdio(filters, search_dirs, data_dir, sys_path, panfl_=True)