Added validators (closes #59)

This commit is contained in:
2022-05-20 10:27:55 +02:00
parent ccca904cb8
commit dac3d9c6bb
9 changed files with 119 additions and 25 deletions

View File

@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
"""
cpl-cli sh-edraft Common Python library CLI
~~~~~~~~~~~~~~~~~~~
sh-edraft Common Python library Command Line Interface
:copyright: (c) 2020 - 2022 sh-edraft.de
:license: MIT, see LICENSE for more details.
"""
__title__ = 'cpl_cli.validators'
__author__ = 'Sven Heidemann'
__license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
__version__ = '2022.6.3.dev6'
from collections import namedtuple
# imports:
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2022', minor='6', micro='3.dev6')

View File

@@ -0,0 +1,18 @@
from cpl_cli import Error
from cpl_cli.configuration import WorkspaceSettings, ProjectSettings
from cpl_core.configuration.validator_abc import ValidatorABC
class ProjectValidator(ValidatorABC):
def __init__(self, workspace: WorkspaceSettings, project: ProjectSettings):
self._workspace = workspace
self._project = project
ValidatorABC.__init__(self)
def validate(self) -> bool:
result = self._project is not None or self._workspace is not None
if not result:
Error.error('The command requires to be run in an CPL project, but a project could not be found.')
return result

View File

@@ -0,0 +1,17 @@
from cpl_cli import Error
from cpl_cli.configuration import WorkspaceSettings
from cpl_core.configuration.validator_abc import ValidatorABC
class WorkspaceValidator(ValidatorABC):
def __init__(self, workspace: WorkspaceSettings):
self._workspace = workspace
ValidatorABC.__init__(self)
def validate(self) -> bool:
result = self._workspace is not None
if not result:
Error.error('The command requires to be run in an CPL workspace, but a workspace could not be found.')
return result