Created
December 1, 2014 16:52
-
-
Save erikkaplun/26d2699b41c40ff6e775 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
object Manage { | |
sealed trait SubCmd | |
case class DeployCmd(deployUser: String, deployDir: String, noPack: Boolean) extends SubCmd | |
case class RestartCmd(restartUser: String) extends SubCmd | |
case object LogCmd extends SubCmd | |
case object ConsoleCmd extends SubCmd | |
case class ManageCmd( | |
verbose: Boolean = false, | |
quiet: Boolean = false, | |
tunnel: Option[String], | |
subcmd: NonEmptyList[SubCmd] | |
) | |
val deployCmd: Parser[SubCmd] = subparser(command("deploy", info( | |
( | |
strOption( | |
short('d'), long("deploy-user"), value("webapp"), metavar("DEPLOY-USER"), | |
help("username to deploy under (defaults to 'webapp')") | |
) |@| | |
strOption( | |
short('f'), long("deploy-dir"), value("profile"), metavar("DEPLOY-DIR"), | |
help("the directory under the deploy user home directory to deploy to") | |
) |@| | |
switch( | |
long("no-pack"), value(false), metavar("NO-PACK"), | |
help("don't run sbt pack prior to deploying") | |
) | |
)(DeployCmd) | |
))) | |
val restartCmd: Parser[SubCmd] = subparser(command("restart", info( | |
strOption( | |
short('r'), long("restart-user"), metavar("RESTART-USER"), | |
help("username for restarting the service") | |
).map(RestartCmd) | |
))) | |
val logCmd: Parser[SubCmd] = subparser(command("log", info(pure(LogCmd)))) | |
val consoleCmd: Parser[SubCmd] = subparser(command("console", info(pure(ConsoleCmd)))) | |
val manageCmdParser = ( | |
switch(short('v'), long("verbose"), value(false), help("Whether to be verbose")) |@| | |
switch(short('q'), long("quiet"), value(false), help("Whether to be quiet")) |@| | |
optional( | |
strOption(short('t'), long("tunnel"), metavar("TUNNEL"), help("username@host pair to a public machine to tunnel through")) | |
) |@| | |
some(deployCmd <+> restartCmd <+> logCmd <+> consoleCmd) | |
)(ManageCmd.apply) | |
val manageCmd = execParser(args, ProgName, info(manageCmdParser <*> helper)) | |
... | |
manageCmd.subcmd.foreach { | |
case DeployCmd(user, dir, noPack) => | |
println(s"deploying as $user to $dir...") | |
case RestartCmd(user) => | |
println(s"restarting as $user") | |
case LogCmd => | |
println(s"showing log output") | |
case ConsoleCmd => | |
println(s"opening console...") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment