@@ -8,9 +8,12 @@ enum SocialLinks(val url: String, val className: String):
88 case Custom (cUrl : String , lightIcon : String , darkIcon : String ) extends SocialLinks (cUrl, " custom" )
99
1010object SocialLinks :
11+ val LowercaseNamePattern = " ^[a-z]+$" .r
12+
1113 def parse (s : String ): Either [String , SocialLinks ] =
1214 val errorPrefix = s " Social links arg $s is invalid: "
1315 val splitted = s.split(" ::" )
16+
1417 splitted.head match {
1518 case " github" if splitted.size == 2 => Right (Github (splitted(1 )))
1619 case " github" => Left (errorPrefix + " For 'github' arg expected one argument: url" )
@@ -20,8 +23,8 @@ object SocialLinks:
2023 case " gitter" => Left (errorPrefix + " For 'gitter' arg expected one argument: url" )
2124 case " discord" if splitted.size == 2 => Right (Discord (splitted(1 )))
2225 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] " )
2629 case _ => Left (errorPrefix)
2730 }
0 commit comments