Replies: 1 comment
-
|
Short answer: there's no public flag on 1. Don't do the work eagerly (the idiomatic fix)Move config loading into class Config:
def __init__(self):
self._loaded = False
self.data = None
def load(self):
if not self._loaded:
self.data = read_config_file() # may raise
self._loaded = True
@click.group()
@click.pass_context
def cli(ctx):
ctx.obj = Config() # cheap; never fails
@cli.command()
@click.pass_obj
def run(config):
config.load() # only runs for real invocations, not --help
2. Peek at the staged args via a
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
In my
@groupcommand(s) I do some basic processing (read config file for mandatory option et al). The problem is that I don't want to do any of that when a subcommand is invoked with--help; I want to show the subcommand help to the user, not the complaint about a missing config file.Is there a way to do that, other than to dig through
sys.argv?Beta Was this translation helpful? Give feedback.
All reactions