mirror of
https://github.com/onyx-and-iris/vban-cli.git
synced 2026-03-02 21:19:11 +00:00
add new help formatters for different kinds of commands
This commit is contained in:
parent
c660778698
commit
c7365bfe4e
@ -4,9 +4,9 @@ from cyclopts import App, Argument, Parameter
|
||||
|
||||
from . import console
|
||||
from .context import Context
|
||||
from .help import CustomHelpFormatter
|
||||
from .help import BusHelpFormatter
|
||||
|
||||
app = App(name='bus', help_formatter=CustomHelpFormatter())
|
||||
app = App(name='bus', help_formatter=BusHelpFormatter())
|
||||
# See https://github.com/onyx-and-iris/vban-cli?tab=readme-ov-file#implementation-notes - 1.
|
||||
# app.command(eq.app.meta, name='eq')
|
||||
|
||||
|
||||
@ -3,9 +3,9 @@ from typing import Annotated
|
||||
from cyclopts import App, Argument, Parameter
|
||||
|
||||
from .context import Context
|
||||
from .help import CustomHelpFormatter
|
||||
from .help import StripSubcommandHelpFormatter
|
||||
|
||||
app = App(name='comp', help_formatter=CustomHelpFormatter())
|
||||
app = App(name='comp', help_formatter=StripSubcommandHelpFormatter())
|
||||
|
||||
|
||||
@app.meta.default
|
||||
|
||||
@ -3,9 +3,9 @@ from typing import Annotated
|
||||
from cyclopts import App, Argument, Parameter
|
||||
|
||||
from .context import Context
|
||||
from .help import CustomHelpFormatter
|
||||
from .help import StripSubcommandHelpFormatter
|
||||
|
||||
app = App(name='denoiser', help_formatter=CustomHelpFormatter())
|
||||
app = App(name='denoiser', help_formatter=StripSubcommandHelpFormatter())
|
||||
|
||||
|
||||
@app.meta.default
|
||||
|
||||
@ -3,11 +3,11 @@ from typing import Annotated
|
||||
from cyclopts import App, Argument, Parameter
|
||||
|
||||
from .context import Context
|
||||
from .help import CustomHelpFormatter
|
||||
from .help import CellHelpFormatter, EqHelpFormatter
|
||||
|
||||
cell_app = App(name='cell', help_formatter=CustomHelpFormatter())
|
||||
cell_app = App(name='cell', help_formatter=CellHelpFormatter())
|
||||
|
||||
app = App(name='eq', help_formatter=CustomHelpFormatter())
|
||||
app = App(name='eq', help_formatter=EqHelpFormatter())
|
||||
app.command(cell_app.meta, name='cell')
|
||||
|
||||
|
||||
|
||||
@ -3,9 +3,9 @@ from typing import Annotated
|
||||
from cyclopts import App, Argument, Parameter
|
||||
|
||||
from .context import Context
|
||||
from .help import CustomHelpFormatter
|
||||
from .help import StripSubcommandHelpFormatter
|
||||
|
||||
app = App(name='gate', help_formatter=CustomHelpFormatter())
|
||||
app = App(name='gate', help_formatter=StripSubcommandHelpFormatter())
|
||||
|
||||
|
||||
@app.meta.default
|
||||
|
||||
@ -4,31 +4,24 @@ from cyclopts.help import DefaultFormatter, HelpPanel
|
||||
from rich.console import Console, ConsoleOptions
|
||||
|
||||
|
||||
class CustomHelpFormatter(DefaultFormatter):
|
||||
"""Custom help formatter that injects an index argument into the usage line and filters it out from the parameters list.
|
||||
|
||||
This formatter modifies the usage line to include an <index> argument after the 'strip' command,
|
||||
and filters out any parameters related to 'index' from the Parameters section of the help output.
|
||||
"""
|
||||
|
||||
def render_usage(self, console: Console, options: ConsoleOptions, usage) -> None:
|
||||
"""Render the usage line with index argument injected."""
|
||||
if usage:
|
||||
modified_usage = re.sub(
|
||||
r'(\S+\s+[a-z]+)\s+(COMMAND)', r'\1 <index> \2', str(usage)
|
||||
)
|
||||
console.print(f'[bold]Usage:[/bold] {modified_usage}')
|
||||
class BaseHelpFormatter(DefaultFormatter):
|
||||
"""Base help formatter that provides common functionality."""
|
||||
|
||||
def __call__(
|
||||
self, console: Console, options: ConsoleOptions, panel: HelpPanel
|
||||
) -> None:
|
||||
"""Render a help panel, filtering out the index parameter from Parameters sections."""
|
||||
"""Render a help panel, filtering out hidden parameters from Parameters sections."""
|
||||
if panel.title == 'Parameters':
|
||||
filtered_entries = [
|
||||
entry
|
||||
for entry in panel.entries
|
||||
if not (
|
||||
entry.names and any('index' in name.lower() for name in entry.names)
|
||||
entry.names
|
||||
and any(
|
||||
param in name.lower()
|
||||
for name in entry.names
|
||||
for param in self.get_filtered_params()
|
||||
)
|
||||
)
|
||||
]
|
||||
|
||||
@ -41,3 +34,90 @@ class CustomHelpFormatter(DefaultFormatter):
|
||||
super().__call__(console, options, filtered_panel)
|
||||
else:
|
||||
super().__call__(console, options, panel)
|
||||
|
||||
def get_filtered_params(self):
|
||||
"""Return list of parameter names to filter out of help output."""
|
||||
return ['index', 'band', 'ctx', 'target', 'eq_kind']
|
||||
|
||||
|
||||
class StripHelpFormatter(BaseHelpFormatter):
|
||||
"""Help formatter for strip commands that injects <index> after 'strip'."""
|
||||
|
||||
def render_usage(self, console: Console, options: ConsoleOptions, usage) -> None:
|
||||
"""Render the usage line with index argument injected after 'strip'.
|
||||
|
||||
Handles both command groups (COMMAND) and individual commands (commandname [ARGS/OPTIONS]).
|
||||
"""
|
||||
if usage:
|
||||
modified_usage = re.sub(
|
||||
r'(\S+\s+strip)\s+(\w+\s+\[[^\]]+\]|\w+\s+\[[^\]]+\]|\w+(?:\s+\[[^\]]+\])*|COMMAND)',
|
||||
r'\1 <index> \2',
|
||||
str(usage),
|
||||
)
|
||||
if modified_usage == str(usage):
|
||||
modified_usage = re.sub(
|
||||
r'(\S+\s+strip)\s+(\w+)', r'\1 <index> \2', str(usage)
|
||||
)
|
||||
console.print(f'[bold]Usage:[/bold] {modified_usage}')
|
||||
|
||||
|
||||
class StripSubcommandHelpFormatter(BaseHelpFormatter):
|
||||
"""Help formatter for strip subcommands that injects <index> after 'strip'."""
|
||||
|
||||
def render_usage(self, console: Console, options: ConsoleOptions, usage) -> None:
|
||||
"""Render the usage line with index argument injected after 'strip'."""
|
||||
if usage:
|
||||
modified_usage = re.sub(
|
||||
r'(\S+\s+strip)\s+(\w+)\s+(COMMAND)', r'\1 <index> \2 \3', str(usage)
|
||||
)
|
||||
console.print(f'[bold]Usage:[/bold] {modified_usage}')
|
||||
|
||||
|
||||
class BusHelpFormatter(BaseHelpFormatter):
|
||||
"""Help formatter for bus commands that injects <index> after 'bus'."""
|
||||
|
||||
def render_usage(self, console: Console, options: ConsoleOptions, usage) -> None:
|
||||
"""Render the usage line with index argument injected after 'bus'.
|
||||
|
||||
Handles both command groups (COMMAND) and individual commands (commandname [ARGS/OPTIONS])."""
|
||||
if usage:
|
||||
modified_usage = re.sub(
|
||||
r'(\S+\s+bus)\s+(\w+\s+\[[^\]]+\]|\w+\s+\[[^\]]+\]|\w+(?:\s+\[[^\]]+\])*|COMMAND)',
|
||||
r'\1 <index> \2',
|
||||
str(usage),
|
||||
)
|
||||
if modified_usage == str(usage):
|
||||
modified_usage = re.sub(
|
||||
r'(\S+\s+bus)\s+(\w+)', r'\1 <index> \2', str(usage)
|
||||
)
|
||||
console.print(f'[bold]Usage:[/bold] {modified_usage}')
|
||||
|
||||
|
||||
class EqHelpFormatter(BaseHelpFormatter):
|
||||
"""Help formatter for eq commands that works with both strip and bus commands.
|
||||
|
||||
Injects <index> after 'strip' or 'bus' and <band> after 'cell'."""
|
||||
|
||||
def render_usage(self, console: Console, options: ConsoleOptions, usage) -> None:
|
||||
"""Render the usage line with proper <index> placement for both strip and bus commands."""
|
||||
if usage:
|
||||
modified_usage = re.sub(
|
||||
r'(\S+\s+)(\w+)(\s+eq\s+)(COMMAND)', r'\1\2 <index>\3\4', str(usage)
|
||||
)
|
||||
console.print(f'[bold]Usage:[/bold] {modified_usage}')
|
||||
|
||||
|
||||
class CellHelpFormatter(BaseHelpFormatter):
|
||||
"""Help formatter for cell commands that works with both strip and bus commands.
|
||||
|
||||
Injects <index> after 'strip' or 'bus' and <band> after 'cell'."""
|
||||
|
||||
def render_usage(self, console: Console, options: ConsoleOptions, usage) -> None:
|
||||
"""Render the usage line with proper <index> and <band> placement."""
|
||||
if usage:
|
||||
modified_usage = re.sub(
|
||||
r'(\S+\s+)(\w+)(\s+eq\s+cell\s+)(COMMAND)',
|
||||
r'\1\2 <index>\3<band> \4',
|
||||
str(usage),
|
||||
)
|
||||
console.print(f'[bold]Usage:[/bold] {modified_usage}')
|
||||
|
||||
@ -4,9 +4,9 @@ from cyclopts import App, Argument, Parameter
|
||||
|
||||
from . import comp, console, denoiser, eq, gate
|
||||
from .context import Context
|
||||
from .help import CustomHelpFormatter
|
||||
from .help import StripHelpFormatter
|
||||
|
||||
app = App(name='strip', help_formatter=CustomHelpFormatter())
|
||||
app = App(name='strip', help_formatter=StripHelpFormatter())
|
||||
app.command(eq.app.meta, name='eq')
|
||||
app.command(comp.app.meta, name='comp')
|
||||
app.command(gate.app.meta, name='gate')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user