Skip to content

Commit

Permalink
remove printlns that would be confusing to a user
Browse files Browse the repository at this point in the history
  • Loading branch information
alterationx10 committed Dec 16, 2024
1 parent 26562f3 commit 03c7b47
Showing 1 changed file with 14 additions and 28 deletions.
42 changes: 14 additions & 28 deletions branch/src/main/scala/dev/wishingtree/branch/ursula/UrsulaApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import scala.util.*

trait UrsulaApp {

/** This setting determines whether the built in HelpCommand is the default
/** This setting determines whether the built-in HelpCommand is the default
* command. Defaults true, override to false if you want to use a different
* Command as default.
*/
Expand All @@ -30,12 +30,6 @@ trait UrsulaApp {
/** A map of trigger -> Command for quick lookup */
private lazy val commandMap: Map[String, Command] =
_allCommands.groupBy(_.trigger).map { case (k, v) =>
if v.size > 1 then {
println(
s"Multiple commands injected with the same trigger - using first found:"
)
v.foreach(c => println(c.getClass.getSimpleName))
}
k -> v.head
}

Expand All @@ -46,33 +40,25 @@ trait UrsulaApp {
/** The default command to run if no trigger is found */
private lazy val findDefaultCommand: Option[Command] = {
val default = _allCommands.filter(_.isDefaultCommand)
if default.size > 1 then {
println(
"Multiple commands injected with isDefaultCommand=true - using the first:"
)
default.foreach(c => println(c.getClass.getSimpleName))
}
default.headOption
}

@volatile
private var dropOne = true
private var dropOne = true

final def main(args: Array[String]): Unit = {
val lzyApp = for {
cmd <- Lazy
.fromOption(args.headOption)
.map(commandMap.get)
.recover { case _: NoSuchElementException =>
dropOne = false
Lazy.fn(findDefaultCommand)
}
.someOrFail(
new IllegalArgumentException(
"Could not find command from argument, and no default command provided"
)
)

cmd <- Lazy
.fromOption(args.headOption)
.map(commandMap.get)
.recover { case _: NoSuchElementException =>
dropOne = false
Lazy.fn(findDefaultCommand)
}
.someOrFail(
new IllegalArgumentException(
"Could not find command from argument, and no default command provided"
)
)
result <- cmd.lazyAction(if dropOne then args.drop(1) else args)
} yield result

Expand Down

0 comments on commit 03c7b47

Please sign in to comment.