Esempio n. 1
0
def _prepare_cli(ctx: click.Context, app: Union[AppT, str], quiet: bool,
                 debug: bool, workdir: str, datadir: str, json: bool,
                 no_color: bool, loop: str) -> None:
    """Faust command-line interface."""
    state = ctx.ensure_object(State)
    state.app = app
    state.quiet = quiet
    state.debug = debug
    state.workdir = workdir
    state.datadir = datadir
    state.json = json
    state.no_color = no_color
    state.loop = loop

    root = cast(_FaustRootContextT, ctx.find_root())
    if root.side_effects:
        if workdir:
            os.environ['F_WORKDIR'] = workdir
            # XXX I'm not sure this is the best place to chdir [ask]
            os.chdir(Path(workdir).absolute())
        if datadir:
            # This is the only way we can set the datadir for App.__init__,
            # so that default values will have the right path prefix.
            # WARNING: Note that the faust.app module *MUST not* have
            # been imported before setting the envvar.
            os.environ['F_DATADIR'] = datadir
        if not no_color and terminal.isatty(sys.stdout):
            enable_all_colors()
        else:
            disable_all_colors()
        if json:
            disable_all_colors()
Esempio n. 2
0
def cli(ctx: click.Context, app: str, quiet: bool, debug: bool, workdir: str,
        datadir: str, json: bool, no_color: bool, loop: str) -> None:
    """Faust command-line interface."""
    ctx.obj = {
        'app': app,
        'quiet': quiet,
        'debug': debug,
        'workdir': workdir,
        'datadir': datadir,
        'json': json,
        'no_color': no_color,
        'loop': loop,
    }
    if workdir:
        os.environ['F_WORKDIR'] = workdir
        # XXX I'm not sure this is the best place to chdir [ask]
        os.chdir(Path(workdir).absolute())
    if datadir:
        # This is the only way we can set the datadir for App.__init__,
        # so that default values will have the right path prefix.
        # WARNING: Note that the faust.app module *MUST not* have
        # been imported before setting the envvar.
        os.environ['F_DATADIR'] = datadir
    if not no_color and terminal.isatty(sys.stdout):
        enable_all_colors()
    else:
        disable_all_colors()
    if json:
        disable_all_colors()