Skip to content

Commit

Permalink
Overhaul the command line help output.
Browse files Browse the repository at this point in the history
Use the new rich-click package for nicer formatting.
  • Loading branch information
ewels committed Feb 19, 2022
1 parent d586656 commit fc65e7f
Show file tree
Hide file tree
Showing 7 changed files with 203 additions and 228 deletions.
39 changes: 7 additions & 32 deletions multiqc/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,20 @@
"""

from __future__ import print_function
import click
import pkg_resources
from . import multiqc
from .utils import config


def modify_usage_error(main_command):
"""Function to modify the default click error handling.
Used here to tell the user about how to find additional help.
With thanks to this Stack Overflow answer: http://stackoverflow.com/a/43922088/713980
:param main_command: top-level group or command object constructed by click wrapper
:return: None
"""

def show(self, file=None):
if file is None:
file = click._compat.get_text_stderr()
color = None
if self.ctx is not None:
color = self.ctx.color
click.utils.echo(self.ctx.get_usage() + "\n", file=file, color=color)
click.utils.echo(
"Error: %s\n\nThis is MultiQC v{}\n\nFor more help, run 'multiqc --help' or visit http://multiqc.info\n".format(
config.version
)
% self.format_message(),
file=file,
color=color,
)

click.exceptions.UsageError.show = show


if __name__ == "__main__" or __name__ == "multiqc.__main__":
def run_multiqc():
# Add any extra plugin command line options
for entry_point in pkg_resources.iter_entry_points("multiqc.cli_options.v1"):
opt_func = entry_point.load()
multiqc.run_cli = opt_func(multiqc.run_cli)
# Modify the default click error handling
modify_usage_error(multiqc.run_cli)
# Call the main function
multiqc.run_cli(prog_name="multiqc")


# Script is run directly
# NB: Usually runs with setup.py console_scripts: 'multiqc=multiqc.__main__:run_multiqc'
if __name__ == "__main__":
run_multiqc()

0 comments on commit fc65e7f

Please sign in to comment.