Permalink
Browse files

http cli commands render to console

  • Loading branch information...
1 parent a65fb05 commit b7a3a693f014b22d38d908821a94170481a067e7 @ornicar committed Dec 28, 2012
View
@@ -6,11 +6,11 @@ import scalaz.effects._
private[cli] case class Forum(env: ForumEnv) {
- def denormalize: IO[Unit] = env.denormalize
+ def denormalize: IO[String] = env.denormalize inject "Forum denormalized"
- def typecheck: IO[Unit] = for {
+ def typecheck: IO[String] = for {
_ env.categRepo.all
_ env.topicRepo.all
_ env.postRepo.all
- } yield ()
+ } yield "Forum type checked"
}
View
@@ -6,8 +6,7 @@ import scalaz.effects._
private[cli] case class Games(env: CoreEnv) {
- def perDay(days: Int): IO[Unit] = for {
+ def perDay(days: Int): IO[String] = for {
nbs env.game.gameRepo.nbPerDay(days)
- _ putStrLn(nbs mkString " ")
- } yield ()
+ } yield nbs mkString " "
}
View
@@ -9,19 +9,16 @@ import scalaz.effects._
private[cli] case class I18n(i18n: I18nEnv) {
- def jsDump: IO[Unit] = for {
- _ putStrLn("Dumping JavaScript translations")
+ def jsDump: IO[String] = for {
_ i18n.jsDump.apply
- } yield ()
+ } yield "Dumped JavaScript translations"
- def fileFix: IO[Unit] = for {
- _ putStrLn("Fixing translation files")
+ def fileFix: IO[String] = for {
_ i18n.fileFix.apply
- } yield ()
+ } yield "Fixed translation files"
- def fetch(from: String): IO[Unit] = for {
- _ putStrLn("Fetch translations from upstream")
+ def fetch(from: String): IO[String] = for {
translations i18n.upstreamFetch apply parseIntOption(from).err("bad from arg")
_ i18n.gitWrite apply translations
- } yield ()
+ } yield "Fetched translations from upstream"
}
View
@@ -6,8 +6,7 @@ import scalaz.effects._
private[cli] case class Infos(env: CoreEnv) {
- def averageElo: IO[Unit] = for {
+ def averageElo: IO[String] = for {
avg env.user.userRepo.averageElo
- _ putStrLn("Average elo is %f" format avg)
- } yield ()
+ } yield "Average elo is %f"
}
View
@@ -8,7 +8,7 @@ import lila.core.{ Global, CoreEnv }
object Main {
- def main(env: CoreEnv)(args: Array[String]): IO[Unit] = {
+ def main(env: CoreEnv)(args: Array[String]): IO[String] = {
def users = Users(env.user.userRepo, env.security.store)
def games = Games(env)
@@ -31,9 +31,9 @@ object Main {
case "user-track" :: uid :: Nil users track uid
case "forum-denormalize" :: Nil forum.denormalize
case "forum-typecheck" :: Nil forum.typecheck
- case "game-cleanup-next" :: Nil titivate.cleanupNext
- case "game-cleanup-unplayed" :: Nil titivate.cleanupUnplayed
- case "game-finish" :: Nil titivate.finishByClock
+ case "game-cleanup-next" :: Nil titivate.cleanupNext inject "Done"
+ case "game-cleanup-unplayed" :: Nil titivate.cleanupUnplayed inject "Done"
+ case "game-finish" :: Nil titivate.finishByClock inject "Done"
case "game-per-day" :: Nil games.perDay(30)
case "game-per-day" :: days :: Nil games.perDay(parseIntOption(days) err "days: Int")
case "wiki-fetch" :: Nil wiki.fetch
@@ -43,7 +43,7 @@ object Main {
case "team-enable" :: uid :: Nil teams enable uid
case "team-disable" :: uid :: Nil teams disable uid
case "team-delete" :: uid :: Nil teams delete uid
- case _ putStrLn("Unknown command: " + args.mkString(" "))
+ case _ io("Unknown command: " + args.mkString(" "))
}
}
}
View
@@ -7,8 +7,5 @@ import scalaz.effects._
private[cli] case class Search(env: SearchEnv) {
- def reset: IO[Unit] = env.indexer.rebuildAll
-
- private def showGame(game: lila.game.DbGame) =
- game.id + " " + game.turns //+ " " + game
+ def reset: IO[String] = env.indexer.rebuildAll inject "Search index reset"
}
View
@@ -10,34 +10,34 @@ private[cli] case class Teams(
userRepo: UserRepo,
api: TeamApi) {
- def join(teamId: String, userIds: List[String]): IO[Unit] =
+ def join(teamId: String, userIds: List[String]): IO[String] =
perform2(teamId, userIds)(api.doJoin _)
- def quit(teamId: String, userIds: List[String]): IO[Unit] =
+ def quit(teamId: String, userIds: List[String]): IO[String] =
perform2(teamId, userIds)(api.doQuit _)
- def enable(teamId: String): IO[Unit] = perform(teamId)(teamRepo.enable _)
+ def enable(teamId: String): IO[String] = perform(teamId)(teamRepo.enable _)
- def disable(teamId: String): IO[Unit] = perform(teamId)(teamRepo.disable _)
+ def disable(teamId: String): IO[String] = perform(teamId)(teamRepo.disable _)
- def delete(teamId: String): IO[Unit] = perform(teamId)(api.delete _)
+ def delete(teamId: String): IO[String] = perform(teamId)(api.delete _)
private def perform(teamId: String)(op: Team IO[Unit]) = for {
teamOption teamRepo byId teamId.pp
- _ teamOption.fold(
- u op(u) flatMap { _ putStrLn("Success") },
- putStrLn("Team not found")
+ res teamOption.fold(
+ u op(u) inject "Success",
+ io("Team not found")
)
- } yield ()
+ } yield res
private def perform2(teamId: String, userIds: List[String])(op: (Team, String) IO[Unit]) = for {
teamOption teamRepo byId teamId
- _ teamOption.fold(
+ res teamOption.fold(
team for {
users userRepo byIds userIds
_ users.map(user putStrLn(user.username) >> op(team, user.id)).sequence
- } yield (),
- putStrLn("Team not found")
+ } yield "Success",
+ io("Team not found")
)
- } yield ()
+ } yield res
}
View
@@ -7,10 +7,10 @@ import scalaz.effects._
private[cli] case class Users(userRepo: UserRepo, securityStore: Store) {
- def enable(username: String): IO[Unit] =
+ def enable(username: String): IO[String] =
perform(username, userRepo.enable)
- def disable(username: String): IO[Unit] =
+ def disable(username: String): IO[String] =
perform(username, user
userRepo disable user map { _
securityStore deleteUsername username
@@ -26,17 +26,14 @@ private[cli] case class Users(userRepo: UserRepo, securityStore: Store) {
})
def track(username: String) = io {
- println("%s = %s".format(
- username,
- securityStore explore username mkString ", "
- ))
+ "%s = %s".format(username, securityStore explore username mkString ", ")
}
- private def perform(username: String, op: User IO[Unit]) = for {
+ private def perform(username: String, op: User IO[Unit]): IO[String] = for {
userOption userRepo byId username
- _ userOption.fold(
- u op(u) flatMap { _ putStrLn("Success") },
- putStrLn("Not found")
+ res userOption.fold(
+ u op(u) inject "Success",
+ io("User not found")
)
- } yield ()
+ } yield res
}
View
@@ -6,8 +6,5 @@ import scalaz.effects._
private[cli] case class Wiki(env: WikiEnv) {
- def fetch: IO[Unit] = for {
- _ putStrLn("Fetching wiki from github")
- _ env.fetch.apply
- } yield ()
+ def fetch = env.fetch.apply inject "Fetched wiki from github"
}
View
@@ -11,7 +11,7 @@ import play.api.libs.json._
import play.api.libs.iteratee._
import play.api.libs.concurrent.Akka
-import scalaz.effects.io
+import scalaz.effects._
object Main extends LilaController {
@@ -32,13 +32,17 @@ object Main extends LilaController {
Form(single(
"c" -> nonEmptyText
)).bindFromRequest.fold(
- err io(BadRequest()),
- command runCommand(command.split(" ")) map { res Ok(res) }
+ err putStrLn("bad command") inject BadRequest(),
+ command for {
+ _ putStrLn(command)
+ res runCommand(command.split(" "))
+ _ putStrLn(res)
+ } yield Ok(res)
)
}
}
def captchaCheck(id: String) = Open { implicit ctx
- Ok(env.site.captcha get id valid ~get("solution") fold(1, 0))
+ Ok(env.site.captcha get id valid ~get("solution") fold (1, 0))
}
}
View
@@ -17,7 +17,7 @@ trait Resolvers {
trait Dependencies {
val scalaz = "org.scalaz" %% "scalaz-core" % "6.0.4"
val salat = "com.novus" %% "salat-core" % "1.9.1"
- val scalalib = "com.github.ornicar" %% "scalalib" % "2.9"
+ val scalalib = "com.github.ornicar" %% "scalalib" % "2.10"
val config = "com.typesafe" % "config" % "0.4.1"
val guava = "com.google.guava" % "guava" % "13.0"
val apache = "org.apache.commons" % "commons-lang3" % "3.1"
View
1 todo
@@ -49,4 +49,3 @@ more requirements to become member
URGENT: lobby filter http://en.lichess.org/forum/lichess-feedback/suggestion-filter-on-main-page#1
clock color (or end of time indication)
allow people to request computer analysis even if one has failed
-http cli render to console

0 comments on commit b7a3a69

Please sign in to comment.