@@ -8,9 +8,12 @@ enum SocialLinks(val url: String, val className: String):
8
8
case Custom (cUrl : String , lightIcon : String , darkIcon : String ) extends SocialLinks (cUrl, " custom" )
9
9
10
10
object SocialLinks :
11
+ val LowercaseNamePattern = " ^[a-z]+$" .r
12
+
11
13
def parse (s : String ): Either [String , SocialLinks ] =
12
14
val errorPrefix = s " Social links arg $s is invalid: "
13
15
val splitted = s.split(" ::" )
16
+
14
17
splitted.head match {
15
18
case " github" if splitted.size == 2 => Right (Github (splitted(1 )))
16
19
case " github" => Left (errorPrefix + " For 'github' arg expected one argument: url" )
@@ -20,8 +23,8 @@ object SocialLinks:
20
23
case " gitter" => Left (errorPrefix + " For 'gitter' arg expected one argument: url" )
21
24
case " discord" if splitted.size == 2 => Right (Discord (splitted(1 )))
22
25
case " discord" => Left (errorPrefix + " For 'discord' arg expected one argument: url" )
23
- case " custom " if splitted.size == 4 => Right (Custom (splitted(1 ), splitted(2 ), splitted(3 )))
24
- case " custom " if splitted.size == 3 => Right (Custom (splitted(1 ), splitted(2 ), splitted(2 )))
25
- case " custom " => Left (errorPrefix + " For 'custom' arg expected three arguments: url, white icon name, black icon name" )
26
+ case LowercaseNamePattern () if splitted.size == 4 => Right (Custom (splitted(1 ), splitted(2 ), splitted(3 )))
27
+ case LowercaseNamePattern () if splitted.size == 3 => Right (Custom (splitted(1 ), splitted(2 ), splitted(2 )))
28
+ case LowercaseNamePattern () => Left (errorPrefix + " For 'custom' two minimum arguments are expected : url, white icon name, [dark icon name] " )
26
29
case _ => Left (errorPrefix)
27
30
}
0 commit comments