Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MRG] No need to monkey-patch Click.HelpFormatter #5

Merged
merged 1 commit into from
Jul 4, 2019

Conversation

dimitern
Copy link
Contributor

@dimitern dimitern commented Jul 4, 2019

While working on adding tests for Excalibur (camelot-dev/excalibur#49), I've noticed this code:

def _write_usage(self, prog, args='', prefix='Usage: '):
    return self._write_usage('camelot', args, prefix=prefix)


# monkey patch click.HelpFormatter
HelpFormatter._write_usage = HelpFormatter.write_usage
HelpFormatter.write_usage = _write_usage

This monkey patching causes Excalibur's (or any other click-based) CLI to return camelot for the program name in the help output, which is a bit confusing, so I decided to propose this PR to fix it.

In order not to show camelot as the program name in the help output (passing --help), it's enough to set @group(name='camelot') on the main Click group for the CLI. The existing approach which monkey patches click.HelpFormatter.write_usage(), will affect any other Click CLI tool that uses camelot as its dependency, e.g. Excalibur.

Added a test to verify it works as expected in the help output.

@dimitern dimitern changed the title No need to monkey-patch Click.HelpFormatter [MRG] No need to monkey-patch Click.HelpFormatter Jul 4, 2019
@codecov-io
Copy link

codecov-io commented Jul 4, 2019

Codecov Report

Merging #5 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master       #5   +/-   ##
=======================================
  Coverage   87.64%   87.64%           
=======================================
  Files          13       13           
  Lines        1505     1505           
  Branches      348      348           
=======================================
  Hits         1319     1319           
  Misses        129      129           
  Partials       57       57
Impacted Files Coverage Δ
camelot/cli.py 86.32% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d5df936...13616c2. Read the comment docs.

@dimitern dimitern merged commit 0f8cda4 into master Jul 4, 2019
@dimitern dimitern deleted the fix-cli-group-name branch July 4, 2019 15:26
tomprogrammer pushed a commit to tomprogrammer/camelot that referenced this pull request May 10, 2023
phoewass pushed a commit to phoewass/camelot that referenced this pull request Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants