Added validators (closes #59)
This commit is contained in:
25
src/cpl_cli/validators/__init__.py
Normal file
25
src/cpl_cli/validators/__init__.py
Normal 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')
|
18
src/cpl_cli/validators/project_validator.py
Normal file
18
src/cpl_cli/validators/project_validator.py
Normal 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
|
17
src/cpl_cli/validators/workspace_validator.py
Normal file
17
src/cpl_cli/validators/workspace_validator.py
Normal 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
|
Reference in New Issue
Block a user