lockss-pybasic 0.1.0.dev5__tar.gz → 0.1.0.dev7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: lockss-pybasic
3
- Version: 0.1.0.dev5
3
+ Version: 0.1.0.dev7
4
4
  Summary: Basic Python utilities
5
5
  License: BSD-3-Clause
6
6
  Author: Thib Guicherd-Callin
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "lockss-pybasic"
3
- version = "0.1.0-dev5"
3
+ version = "0.1.0-dev7"
4
4
  description = "Basic Python utilities"
5
5
  authors = [
6
6
  { name = "Thib Guicherd-Callin", email = "thib@cs.stanford.edu" }
@@ -32,4 +32,4 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
32
  POSSIBILITY OF SUCH DAMAGE.
33
33
  '''.strip()
34
34
 
35
- __version__ = '0.1.0-dev5'
35
+ __version__ = '0.1.0-dev7'
@@ -28,17 +28,63 @@
28
28
  # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
29
  # POSSIBILITY OF SUCH DAMAGE.
30
30
 
31
+ '''
32
+ Utilities for command line processing.
33
+ '''
34
+
35
+ from abc import ABC, abstractmethod
31
36
  import sys
32
37
 
33
- from pydantic.v1.fields import FieldInfo
38
+ from pydantic.v1 import BaseModel, Field
39
+
40
+
41
+ class Printable(ABC):
42
+
43
+ def print(self, file=sys.stdout):
44
+ print(self.get_display(), file=file)
45
+
46
+ @abstractmethod
47
+ def get_display(self):
48
+ pass
49
+
50
+
51
+ class CopyrightCommand:
52
+
53
+ @staticmethod
54
+ def make(copyright):
55
+ class CopyrightModel(Printable, BaseModel):
56
+ def get_display(self):
57
+ return copyright
58
+ return CopyrightModel
59
+
60
+ @staticmethod
61
+ def field():
62
+ return Field(description='print the copyright and exit')
63
+
64
+
65
+ class LicenseCommand:
66
+
67
+ @staticmethod
68
+ def make(license):
69
+ class LicenseModel(Printable, BaseModel):
70
+ def get_display(self):
71
+ return license
72
+ return LicenseModel
73
+
74
+ @staticmethod
75
+ def field():
76
+ return Field(description='print the software license and exit')
77
+
34
78
 
35
- class VersionCommand(FieldInfo):
79
+ class VersionCommand:
36
80
 
37
- def __init__(self, version: str, *args, **kwargs):
38
- kwargs.setdefault('description', 'print the version number and exit')
39
- super().__init__(*args, **kwargs)
40
- self._version = version
41
- self._validate() # Same as the Field(...) function
81
+ @staticmethod
82
+ def make(version):
83
+ class VersionModel(Printable, BaseModel):
84
+ def get_display(self):
85
+ return version
86
+ return VersionModel
42
87
 
43
- def print_version(self, file=sys.stdout):
44
- print(self._version, file=file)
88
+ @staticmethod
89
+ def field():
90
+ return Field(description='print the version number and exit')