Skip to content

Commit

Permalink
Scalafmt
Browse files Browse the repository at this point in the history
  • Loading branch information
mpilquist committed Aug 13, 2023
1 parent 60000f9 commit a03c3ad
Show file tree
Hide file tree
Showing 38 changed files with 731 additions and 580 deletions.
16 changes: 10 additions & 6 deletions src/main/scala/cjmx/App.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ object App {
val reader: Parser[_] => LineReader = if (args.isEmpty) {
consoleReader
} else {
val firstArgAsConnect = Try(args.head.toInt).toOption.map { pid => "connect -q " + pid }
val firstArgAsConnect = Try(args.head.toInt).toOption.map(pid => "connect -q " + pid)
firstArgAsConnect match {
case None =>
val r = constReader(args :+ "exit")
Expand All @@ -72,11 +72,15 @@ object App {
}
}

private def prefixedReader(first: Array[String], next: Parser[_] => LineReader): Parser[_] => LineReader = {
private def prefixedReader(
first: Array[String],
next: Parser[_] => LineReader
): Parser[_] => LineReader = {
val firstReader = constReader(first)
p => new LineReader {
override def readLine(prompt: String, mask: Option[Char]) =
firstReader.readLine(prompt, mask) orElse (next(p).readLine(prompt, mask))
}
p =>
new LineReader {
override def readLine(prompt: String, mask: Option[Char]) =
firstReader.readLine(prompt, mask).orElse(next(p).readLine(prompt, mask))
}
}
}
3 changes: 1 addition & 2 deletions src/main/scala/cjmx/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
package cjmx

object Main {
def main(args: Array[String]) = {
def main(args: Array[String]) =
System.exit(App.run(args))
}
}
38 changes: 27 additions & 11 deletions src/main/scala/cjmx/cli/ActionContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,16 @@ trait ActionContext {

object ActionContext {
private case class DefaultActionContext(
runState: RunState,
connectionState: ConnectionState,
formatter: MessageFormatter,
lastStatusCode: Int,
lineReader: (String, Option[Char]) => Option[String]
runState: RunState,
connectionState: ConnectionState,
formatter: MessageFormatter,
lastStatusCode: Int,
lineReader: (String, Option[Char]) => Option[String]
) extends ActionContext {
override def withRunState(rs: RunState) = copy(runState = rs)
override def exit(statusCode: Int) = withRunState(RunState.Exit(statusCode))
override def connected(connection: JMXConnection) = copy(connectionState = ConnectionState.Connected(connection))
override def connected(connection: JMXConnection) =
copy(connectionState = ConnectionState.Connected(connection))
override def disconnected = copy(connectionState = ConnectionState.Disconnected)
override def withFormatter(fmt: MessageFormatter) = copy(formatter = fmt)
override def withStatusCode(statusCode: Int) = copy(lastStatusCode = statusCode)
Expand All @@ -82,14 +83,29 @@ object ActionContext {

val noOpLineReader: (String, Option[Char]) => Option[String] = (x, y) => None

/** Provides an instance of `ActionContext` that does not require input from the console. **/
def embedded(runState: RunState = RunState.Running, connectionState: ConnectionState = ConnectionState.Disconnected, formatter: MessageFormatter = TextMessageFormatter, statusCode: Int = 0): ActionContext =
/** Provides an instance of `ActionContext` that does not require input from the console. * */
def embedded(
runState: RunState = RunState.Running,
connectionState: ConnectionState = ConnectionState.Disconnected,
formatter: MessageFormatter = TextMessageFormatter,
statusCode: Int = 0
): ActionContext =
withLineReader(runState, connectionState, formatter, statusCode, lineReader = noOpLineReader)

def apply(runState: RunState = RunState.Running, connectionState: ConnectionState = ConnectionState.Disconnected, formatter: MessageFormatter = TextMessageFormatter, statusCode: Int = 0): ActionContext =
def apply(
runState: RunState = RunState.Running,
connectionState: ConnectionState = ConnectionState.Disconnected,
formatter: MessageFormatter = TextMessageFormatter,
statusCode: Int = 0
): ActionContext =
embedded(runState, connectionState, formatter, statusCode)

def withLineReader(runState: RunState = RunState.Running, connectionState: ConnectionState = ConnectionState.Disconnected, formatter: MessageFormatter = TextMessageFormatter, statusCode: Int = 0, lineReader: (String, Option[Char]) => Option[String]): ActionContext =
def withLineReader(
runState: RunState = RunState.Running,
connectionState: ConnectionState = ConnectionState.Disconnected,
formatter: MessageFormatter = TextMessageFormatter,
statusCode: Int = 0,
lineReader: (String, Option[Char]) => Option[String]
): ActionContext =
DefaultActionContext(runState, connectionState, formatter, statusCode, lineReader)
}

5 changes: 3 additions & 2 deletions src/main/scala/cjmx/cli/InvocationResult.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ object InvocationResult {
final case object NoSuchOperation extends InvocationResult {
override def toString = "no such operation"
}
final case class NoOperationWithSignature(signature: Seq[Class[_]], validSignatures: Seq[String]) extends InvocationResult {
final case class NoOperationWithSignature(signature: Seq[Class[_]], validSignatures: Seq[String])
extends InvocationResult {
override def toString = "no operation with signature (%s) - valid signatures:%n %s".format(
signature.map { _.getSimpleName },
signature.map(_.getSimpleName),
validSignatures.mkString("%n ".format())
)
}
Expand Down
Loading

0 comments on commit a03c3ad

Please sign in to comment.