Coverage for python/lsst/daf/butler/cli/opt/log_level.py : 100%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# This file is part of daf_butler.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (http://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <http://www.gnu.org/licenses/>.
22import click
23from functools import partial
25from ..utils import MWOption, split_kv
26from ...core.utils import iterable
29class log_level_option: # noqa: N801
30 """A decorator to add a log_level option to a click.Command.
32 Parameters
33 ----------
34 help : str, optional
35 The help text to use, by default defaultHelp
36 defaultValue : str, optional
37 The default value to use if this option is not required. By default
38 `log_level_option.defaultValue`.
39 required : bool, optional
40 If true then the caller must pass this option when calling the
41 command. By default False.
42 """
44 choices = ["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG"]
45 defaultHelp = "The Python log level to use."
46 defaultValue = "WARNING"
47 optionKey = "log_level"
49 def __init__(self, defaultValue=defaultValue, help=defaultHelp, required=False):
50 self.help = help
51 self.isEager = True
52 self.multiple = True
53 self.required = required
54 self.default = None if required else defaultValue
56 def __call__(self, f):
57 return click.option("--log-level", cls=MWOption,
58 callback=partial(split_kv,
59 choice=click.Choice(self.choices, case_sensitive=False),
60 normalize=True,
61 unseparated_okay=True),
62 default=iterable(self.default) if self.default is not None else None,
63 is_eager=self.isEager,
64 help=self.help,
65 multiple=self.multiple,
66 required=self.required)(f)