diff --git a/src/vban_cli/bus.py b/src/vban_cli/bus.py index 6c2d673..9378fae 100644 --- a/src/vban_cli/bus.py +++ b/src/vban_cli/bus.py @@ -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') diff --git a/src/vban_cli/comp.py b/src/vban_cli/comp.py index f73a75f..75ecef0 100644 --- a/src/vban_cli/comp.py +++ b/src/vban_cli/comp.py @@ -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 diff --git a/src/vban_cli/denoiser.py b/src/vban_cli/denoiser.py index 06b38bf..e7ea36d 100644 --- a/src/vban_cli/denoiser.py +++ b/src/vban_cli/denoiser.py @@ -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 diff --git a/src/vban_cli/eq.py b/src/vban_cli/eq.py index 972d5de..c95ecdc 100644 --- a/src/vban_cli/eq.py +++ b/src/vban_cli/eq.py @@ -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') diff --git a/src/vban_cli/gate.py b/src/vban_cli/gate.py index 2149eaa..2e96d5a 100644 --- a/src/vban_cli/gate.py +++ b/src/vban_cli/gate.py @@ -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 diff --git a/src/vban_cli/help.py b/src/vban_cli/help.py index 08b7e66..ebdf52f 100644 --- a/src/vban_cli/help.py +++ b/src/vban_cli/help.py @@ -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 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 \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 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 \2', + str(usage), + ) + if modified_usage == str(usage): + modified_usage = re.sub( + r'(\S+\s+strip)\s+(\w+)', r'\1 \2', str(usage) + ) + console.print(f'[bold]Usage:[/bold] {modified_usage}') + + +class StripSubcommandHelpFormatter(BaseHelpFormatter): + """Help formatter for strip subcommands that injects 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 \2 \3', str(usage) + ) + console.print(f'[bold]Usage:[/bold] {modified_usage}') + + +class BusHelpFormatter(BaseHelpFormatter): + """Help formatter for bus commands that injects 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 \2', + str(usage), + ) + if modified_usage == str(usage): + modified_usage = re.sub( + r'(\S+\s+bus)\s+(\w+)', r'\1 \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 after 'strip' or 'bus' and after 'cell'.""" + + def render_usage(self, console: Console, options: ConsoleOptions, usage) -> None: + """Render the usage line with proper placement for both strip and bus commands.""" + if usage: + modified_usage = re.sub( + r'(\S+\s+)(\w+)(\s+eq\s+)(COMMAND)', r'\1\2 \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 after 'strip' or 'bus' and after 'cell'.""" + + def render_usage(self, console: Console, options: ConsoleOptions, usage) -> None: + """Render the usage line with proper and placement.""" + if usage: + modified_usage = re.sub( + r'(\S+\s+)(\w+)(\s+eq\s+cell\s+)(COMMAND)', + r'\1\2 \3 \4', + str(usage), + ) + console.print(f'[bold]Usage:[/bold] {modified_usage}') diff --git a/src/vban_cli/strip.py b/src/vban_cli/strip.py index f605314..da9b7c3 100644 --- a/src/vban_cli/strip.py +++ b/src/vban_cli/strip.py @@ -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')