Fix inquiring flags
This commit is contained in:
parent
7816212190
commit
1bc51d2de5
2 changed files with 19 additions and 5 deletions
|
@ -48,7 +48,7 @@ def load_templates():
|
||||||
@clickquiry.option("-l", "--license", validator=SPDXValidator, default="AGPL-3.0-or-later",
|
@clickquiry.option("-l", "--license", validator=SPDXValidator, default="AGPL-3.0-or-later",
|
||||||
help="The license for the project (SPDX identifier)", required=False)
|
help="The license for the project (SPDX identifier)", required=False)
|
||||||
@clickquiry.option("-c", "--config", message="Should the plugin include a config?",
|
@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:
|
def init(name: str, id: str, version: Version, license: str, config: bool) -> None:
|
||||||
load_templates()
|
load_templates()
|
||||||
main_class = name[0].upper() + name[1:]
|
main_class = name[0].upper() + name[1:]
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
from typing import Any, Callable, Union
|
from typing import Any, Callable, Union, Optional
|
||||||
import functools
|
import functools
|
||||||
|
|
||||||
from prompt_toolkit.validation import Validator
|
from prompt_toolkit.validation import Validator
|
||||||
|
@ -21,7 +21,7 @@ from PyInquirer import prompt
|
||||||
import click
|
import click
|
||||||
|
|
||||||
from ..base import app
|
from ..base import app
|
||||||
from .validators import Required
|
from .validators import Required, ClickValidator
|
||||||
|
|
||||||
|
|
||||||
def command(help: str) -> Callable[[Callable], Callable]:
|
def command(help: str) -> Callable[[Callable], Callable]:
|
||||||
|
@ -46,16 +46,30 @@ def command(help: str) -> Callable[[Callable], Callable]:
|
||||||
return decorator
|
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,
|
def option(short: str, long: str, message: str = None, help: str = None,
|
||||||
click_type: Union[str, Callable[[str], Any]] = None, inq_type: str = None,
|
click_type: Union[str, Callable[[str], Any]] = None, inq_type: str = None,
|
||||||
validator: Validator = None, required: bool = False, default: str = None,
|
validator: Validator = None, required: bool = False, default: str = None,
|
||||||
is_flag: bool = False) -> Callable[[Callable], Callable]:
|
is_flag: bool = False) -> Callable[[Callable], Callable]:
|
||||||
if not message:
|
if not message:
|
||||||
message = long[2].upper() + long[3:]
|
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:
|
def decorator(func) -> Callable:
|
||||||
click.option(short, long, help=help, type=validator.click_type if validator else click_type,
|
click.option(short, long, help=help, type=click_type)(func)
|
||||||
is_flag=is_flag)(func)
|
|
||||||
if not hasattr(func, "__inquirer_questions__"):
|
if not hasattr(func, "__inquirer_questions__"):
|
||||||
func.__inquirer_questions__ = {}
|
func.__inquirer_questions__ = {}
|
||||||
q = {
|
q = {
|
||||||
|
|
Loading…
Reference in a new issue