-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from alexarchambault/topic/annotations
Update things, and move annotations to a separate project
- Loading branch information
Showing
5 changed files
with
58 additions
and
41 deletions.
There are no files selected for viewing
33 changes: 2 additions & 31 deletions
33
.../src/main/scala/caseapp/Annotations.scala → .../src/main/scala/caseapp/Annotations.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package caseapp | ||
|
||
package object core { | ||
|
||
implicit class NameOps(name: Name) { | ||
|
||
private def isShort = name.name.length == 1 | ||
|
||
private def optionName = caseapp.core.util.pascalCaseSplit(name.name.toList).map(_.toLowerCase).mkString("-") | ||
private def optionEq = if (isShort) s"-${name.name}=" else s"--$optionName=" | ||
|
||
def option: String = if (isShort) s"-${name.name}" else s"--$optionName" | ||
|
||
def apply(args: List[String], isFlag: Boolean): Option[List[String]] = args match { | ||
case Nil => None | ||
case h :: t => | ||
if (h == option) | ||
Some(t) | ||
else if (!isFlag && h.startsWith(optionEq)) | ||
Some(h.drop(optionEq.length) :: t) | ||
else | ||
None | ||
} | ||
|
||
def apply(arg: String): Either[Unit, Option[String]] = | ||
if (arg == option) | ||
Right(None) | ||
else if (arg.startsWith(optionEq)) | ||
Right(Some(arg.drop(optionEq.length))) | ||
else | ||
Left(()) | ||
} | ||
|
||
implicit class ValueDescriptionOps(desc: ValueDescription) { | ||
|
||
def message: String = s"<${desc.description}>" | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters