@@ -39,7 +39,7 @@ class MatcherRegistry(SkipDefaultFieldsReprMixin):
39
39
_matchers : dict [str , Matcher ] = dataclasses .field (default_factory = dict )
40
40
41
41
def register (self , cls : Matcher ) -> None :
42
- """
42
+ r """
43
43
44
44
.. currentmodule:: libvcs.parse.git
45
45
@@ -76,11 +76,13 @@ def register(self, cls: Matcher) -> None:
76
76
>>> class GitHubPrefix(Matcher):
77
77
... label = 'gh-prefix'
78
78
... description ='Matches prefixes like github:org/repo'
79
- ... pattern = r'^github:(?P<path>) '
79
+ ... pattern = r'^github:(?P<path>.*)$ '
80
80
... pattern_defaults = {
81
81
... 'hostname': 'github.com',
82
82
... 'scheme': 'https'
83
83
... }
84
+ ... # We know it's git, not any other VCS
85
+ ... is_explicit = True
84
86
85
87
>>> @dataclasses.dataclass(repr=False)
86
88
... class GitHubLocation(GitURL):
@@ -91,6 +93,21 @@ def register(self, cls: Matcher) -> None:
91
93
>>> GitHubLocation.is_valid(url='github:vcs-python/libvcs')
92
94
True
93
95
96
+ >>> GitHubLocation.is_valid(url='github:vcs-python/libvcs', is_explicit=True)
97
+ True
98
+
99
+ Notice how ``pattern_defaults`` neatly fills the values for us.
100
+
101
+ >>> GitHubLocation(url='github:vcs-python/libvcs')
102
+ GitHubLocation(url=github:vcs-python/libvcs,
103
+ scheme=https,
104
+ hostname=github.com,
105
+ path=vcs-python/libvcs,
106
+ matcher=gh-prefix)
107
+
108
+ >>> GitHubLocation(url='github:vcs-python/libvcs').to_url()
109
+ 'https://github.com/vcs-python/libvcs'
110
+
94
111
>>> GitHubLocation.is_valid(url='gitlab:vcs-python/libvcs')
95
112
False
96
113
0 commit comments