mirror of
https://github.com/frappe/bench.git
synced 2025-01-10 17:24:41 +00:00
feat: Pass --use-feature='dynamic-feed' for new CLI
This commit is contained in:
parent
806d543fac
commit
b92fb1401b
@ -30,7 +30,7 @@ from bench.utils import (
|
||||
from bench.utils.bench import get_env_cmd
|
||||
|
||||
# these variables are used to show dynamic outputs on the terminal
|
||||
fancy = False
|
||||
dynamic_feed = False
|
||||
bench.LOG_BUFFER = []
|
||||
|
||||
# set when commands are executed via the CLI
|
||||
|
@ -1,40 +1,28 @@
|
||||
# imports - third party imports
|
||||
import click
|
||||
from click.core import _check_multicommand
|
||||
|
||||
def print_bench_version(ctx, param, value):
|
||||
"""Prints current bench version"""
|
||||
if not value or ctx.resilient_parsing:
|
||||
return
|
||||
|
||||
import bench
|
||||
click.echo(bench.VERSION)
|
||||
ctx.exit()
|
||||
|
||||
class MultiCommandGroup(click.Group):
|
||||
def add_command(self, cmd, name=None):
|
||||
"""Registers another :class:`Command` with this group. If the name
|
||||
is not provided, the name of the command is used.
|
||||
|
||||
Note: This is a custom Group that allows passing a list of names for
|
||||
the command name.
|
||||
"""
|
||||
name = name or cmd.name
|
||||
if name is None:
|
||||
raise TypeError('Command has no name.')
|
||||
_check_multicommand(self, name, cmd, register=True)
|
||||
|
||||
try:
|
||||
self.commands[name] = cmd
|
||||
except TypeError:
|
||||
if isinstance(name, list):
|
||||
for _name in name:
|
||||
self.commands[_name] = cmd
|
||||
# imports - module imports
|
||||
from bench.utils.cli import (
|
||||
MultiCommandGroup,
|
||||
print_bench_version,
|
||||
use_experimental_feature,
|
||||
)
|
||||
|
||||
|
||||
@click.group(cls=MultiCommandGroup)
|
||||
@click.option('--version', is_flag=True, is_eager=True, callback=print_bench_version, expose_value=False)
|
||||
def bench_command(bench_path='.'):
|
||||
@click.option(
|
||||
"--version",
|
||||
is_flag=True,
|
||||
is_eager=True,
|
||||
callback=print_bench_version,
|
||||
expose_value=False,
|
||||
)
|
||||
@click.option(
|
||||
"--use-feature", is_eager=True, callback=use_experimental_feature, expose_value=False
|
||||
)
|
||||
def bench_command(bench_path="."):
|
||||
import bench
|
||||
|
||||
bench.set_frappe_version(bench_path=bench_path)
|
||||
|
||||
|
||||
|
@ -23,3 +23,6 @@ class ValidationError(Exception):
|
||||
|
||||
class CannotUpdateReleaseBench(ValidationError):
|
||||
pass
|
||||
|
||||
class FeatureDoesNotExistError(CommandFailedError):
|
||||
pass
|
||||
|
@ -61,7 +61,7 @@ def log(message, level=0, no_log=False):
|
||||
|
||||
color, prefix = levels.get(level, levels[0])
|
||||
|
||||
if bench.cli.from_command_line and bench.cli.fancy:
|
||||
if bench.cli.from_command_line and bench.cli.dynamic_feed:
|
||||
bench.LOG_BUFFER.append(
|
||||
{"prefix": prefix, "message": message, "color": color,}
|
||||
)
|
||||
|
42
bench/utils/cli.py
Normal file
42
bench/utils/cli.py
Normal file
@ -0,0 +1,42 @@
|
||||
import click
|
||||
from click.core import _check_multicommand
|
||||
|
||||
|
||||
def print_bench_version(ctx, param, value):
|
||||
"""Prints current bench version"""
|
||||
if not value or ctx.resilient_parsing:
|
||||
return
|
||||
|
||||
import bench
|
||||
click.echo(bench.VERSION)
|
||||
ctx.exit()
|
||||
|
||||
|
||||
class MultiCommandGroup(click.Group):
|
||||
def add_command(self, cmd, name=None):
|
||||
"""Registers another :class:`Command` with this group. If the name
|
||||
is not provided, the name of the command is used.
|
||||
|
||||
Note: This is a custom Group that allows passing a list of names for
|
||||
the command name.
|
||||
"""
|
||||
name = name or cmd.name
|
||||
if name is None:
|
||||
raise TypeError('Command has no name.')
|
||||
_check_multicommand(self, name, cmd, register=True)
|
||||
|
||||
try:
|
||||
self.commands[name] = cmd
|
||||
except TypeError:
|
||||
if isinstance(name, list):
|
||||
for _name in name:
|
||||
self.commands[_name] = cmd
|
||||
|
||||
|
||||
def use_experimental_feature(ctx, param, value):
|
||||
if value == "dynamic-feed":
|
||||
import bench.cli
|
||||
bench.cli.dynamic_feed = True
|
||||
else:
|
||||
from bench.exceptions import FeatureDoesNotExistError
|
||||
raise FeatureDoesNotExistError(f"Feature {value} does not exist")
|
@ -37,7 +37,7 @@ def step(title: str = None, success: str = None):
|
||||
def wrapper_fn(*args, **kwargs):
|
||||
import bench.cli
|
||||
|
||||
if bench.cli.from_command_line and bench.cli.fancy:
|
||||
if bench.cli.from_command_line and bench.cli.dynamic_feed:
|
||||
kw = args[0].__dict__
|
||||
|
||||
_title = f"{click.style('⏼', fg='bright_yellow')} {title.format(**kw)}"
|
||||
@ -45,7 +45,7 @@ def step(title: str = None, success: str = None):
|
||||
|
||||
retval = fn(*args)
|
||||
|
||||
if bench.cli.from_command_line and bench.cli.fancy:
|
||||
if bench.cli.from_command_line and bench.cli.dynamic_feed:
|
||||
click.clear()
|
||||
|
||||
for l in bench.LOG_BUFFER:
|
||||
|
Loading…
Reference in New Issue
Block a user