diff --git a/maubot/cli/commands/init.py b/maubot/cli/commands/init.py index 4d82825..d9e3368 100644 --- a/maubot/cli/commands/init.py +++ b/maubot/cli/commands/init.py @@ -48,7 +48,7 @@ def load_templates(): @clickquiry.option("-l", "--license", validator=SPDXValidator, default="AGPL-3.0-or-later", help="The license for the project (SPDX identifier)", required=False) @clickquiry.option("-c", "--config", message="Should the plugin include a config?", - help="Include a config in the plugin stub", is_flag=True, default="null") + help="Include a config in the plugin stub", default=False, is_flag=True) def init(name: str, id: str, version: Version, license: str, config: bool) -> None: load_templates() main_class = name[0].upper() + name[1:] diff --git a/maubot/cli/util/clickquiry.py b/maubot/cli/util/clickquiry.py index c0a4bc3..69cf716 100644 --- a/maubot/cli/util/clickquiry.py +++ b/maubot/cli/util/clickquiry.py @@ -13,7 +13,7 @@ # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from typing import Any, Callable, Union +from typing import Any, Callable, Union, Optional import functools from prompt_toolkit.validation import Validator @@ -21,7 +21,7 @@ from PyInquirer import prompt import click from ..base import app -from .validators import Required +from .validators import Required, ClickValidator def command(help: str) -> Callable[[Callable], Callable]: @@ -46,16 +46,30 @@ def command(help: str) -> Callable[[Callable], Callable]: return decorator +def yesno(val: str) -> Optional[bool]: + if not val: + return None + elif val.lower() in ("true", "t", "yes", "y"): + return True + elif val.lower() in ("false", "f", "no", "n"): + return False + + +yesno.__name__ = "yes/no" + + def option(short: str, long: str, message: str = None, help: str = None, click_type: Union[str, Callable[[str], Any]] = None, inq_type: str = None, validator: Validator = None, required: bool = False, default: str = None, is_flag: bool = False) -> Callable[[Callable], Callable]: if not message: message = long[2].upper() + long[3:] + click_type = validator.click_type if isinstance(validator, ClickValidator) else click_type + if is_flag: + click_type = yesno def decorator(func) -> Callable: - click.option(short, long, help=help, type=validator.click_type if validator else click_type, - is_flag=is_flag)(func) + click.option(short, long, help=help, type=click_type)(func) if not hasattr(func, "__inquirer_questions__"): func.__inquirer_questions__ = {} q = {