Skip to content

Commit

Permalink
Format everything (#340)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexarchambault authored Nov 14, 2021
1 parent 4c714af commit 44b600f
Show file tree
Hide file tree
Showing 91 changed files with 1,709 additions and 1,248 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ jobs:
- name: Test
run: sbt +mimaReportBinaryIssues

format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
submodules: true
- uses: coursier/[email protected]
- uses: coursier/setup-action@v1
with:
jvm: 8
apps: scalafmt:3.0.8
- run: scalafmt --check

publish:
needs: [test, bin-compat]
if: github.event_name == 'push'
Expand Down
36 changes: 36 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version = "3.0.8"

align.preset = more
maxColumn = 100
assumeStandardLibraryStripMargin = true
indent.defnSite = 2
indentOperator.topLevelOnly = false
align.preset = more
align.openParenCallSite = false
newlines.source = keep
newlines.beforeMultiline = keep
newlines.afterCurlyLambdaParams = keep
newlines.alwaysBeforeElseAfterCurlyIf = true

runner.dialect = scala213

rewrite.rules = [
RedundantBraces
RedundantParens
SortModifiers
]

rewrite.redundantBraces {
ifElseExpressions = true
includeUnitMethods = false
stringInterpolation = true
}

rewrite.sortModifiers.order = [
"private", "final", "override", "protected",
"implicit", "sealed", "abstract", "lazy"
]
project.excludeFilters = [
".metals"
"target"
]
33 changes: 10 additions & 23 deletions annotations/shared/src/main/scala/caseapp/Annotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ package caseapp

import scala.annotation.StaticAnnotation

/**
* Extra name for the annotated argument
/** Extra name for the annotated argument
*/
final case class Name(name: String) extends StaticAnnotation

/**
* Description of the value of the annotated argument
/** Description of the value of the annotated argument
*/
final case class ValueDescription(description: String) extends StaticAnnotation {
def message: String = s"<$description>"
Expand All @@ -18,46 +16,35 @@ object ValueDescription {
val default = ValueDescription("value")
}

/**
* Help message for the annotated argument
/** Help message for the annotated argument
*/
final case class HelpMessage(message: String) extends StaticAnnotation

/**
* Name for the annotated case class of arguments
* E.g. MyApp
/** Name for the annotated case class of arguments E.g. MyApp
*/
final case class AppName(appName: String) extends StaticAnnotation

/**
* Program name for the annotated case class of arguments
* E.g. my-app
/** Program name for the annotated case class of arguments E.g. my-app
*/
final case class ProgName(progName: String) extends StaticAnnotation

/**
* Set the command name of the annotated case class of arguments
* E.g. my-app
/** Set the command name of the annotated case class of arguments E.g. my-app
*/
final case class CommandName(commandName: String) extends StaticAnnotation

/**
* App version for the annotated case class of arguments
/** App version for the annotated case class of arguments
*/
final case class AppVersion(appVersion: String) extends StaticAnnotation

/**
* Name for the extra arguments of the annotated case class of arguments
/** Name for the extra arguments of the annotated case class of arguments
*/
final case class ArgsName(argsName: String) extends StaticAnnotation

/**
* Don't parse the annotated field as a single argument. Recurse on its fields instead.
/** Don't parse the annotated field as a single argument. Recurse on its fields instead.
*/
final class Recurse extends StaticAnnotation

/**
* Do not include this field / argument in the help message
/** Do not include this field / argument in the help message
*/
final class Hidden extends StaticAnnotation

Expand Down
35 changes: 17 additions & 18 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@

import sbtcrossproject.crossProject

import Settings._

inThisBuild(List(
organization := "com.github.alexarchambault",
homepage := Some(url("https://github.com/alexarchambault/case-app")),
licenses := Seq("Apache 2.0" -> url("http://opensource.org/licenses/Apache-2.0")),
homepage := Some(url("https://github.com/alexarchambault/case-app")),
licenses := Seq("Apache 2.0" -> url("http://opensource.org/licenses/Apache-2.0")),
developers := List(
Developer(
"alexarchambault",
Expand All @@ -26,8 +25,8 @@ lazy val annotations = crossProject(JSPlatform, JVMPlatform, NativePlatform)
caseAppPrefix
)

lazy val annotationsJVM = annotations.jvm
lazy val annotationsJS = annotations.js
lazy val annotationsJVM = annotations.jvm
lazy val annotationsJS = annotations.js
lazy val annotationsNative = annotations.native

lazy val util = crossProject(JSPlatform, JVMPlatform, NativePlatform)
Expand All @@ -40,12 +39,12 @@ lazy val util = crossProject(JSPlatform, JVMPlatform, NativePlatform)
libraryDependencies ++= Seq(
Deps.shapeless.value,
Deps.scalaCompiler.value % "provided",
Deps.scalaReflect.value % "provided"
Deps.scalaReflect.value % "provided"
)
)

lazy val utilJVM = util.jvm
lazy val utilJS = util.js
lazy val utilJVM = util.jvm
lazy val utilJS = util.js
lazy val utilNative = util.native

lazy val cats = crossProject(JSPlatform, JVMPlatform)
Expand All @@ -63,15 +62,15 @@ lazy val cats = crossProject(JSPlatform, JVMPlatform)
)

lazy val catsJVM = cats.jvm
lazy val catsJS = cats.js
lazy val catsJS = cats.js

lazy val cats2 = crossProject(JSPlatform, JVMPlatform)
.dependsOn(core)
.jvmSettings(Mima.settings)
.jsSettings(Mima.settings)
.settings(
shared,
name := "case-app-cats-effect-2",
name := "case-app-cats-effect-2",
Compile / sources := (catsJVM / Compile / sources).value,
libraryDependencies ++= Seq(
Deps.catsEffect2.value
Expand All @@ -81,7 +80,7 @@ lazy val cats2 = crossProject(JSPlatform, JVMPlatform)
)

lazy val cats2JVM = cats2.jvm
lazy val cats2JS = cats2.js
lazy val cats2JS = cats2.js

lazy val core = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.nativeConfigure(_.disablePlugins(MimaPlugin))
Expand All @@ -97,8 +96,8 @@ lazy val core = crossProject(JSPlatform, JVMPlatform, NativePlatform)
)
)

lazy val coreJVM = core.jvm
lazy val coreJS = core.js
lazy val coreJVM = core.jvm
lazy val coreJS = core.js
lazy val coreNative = core.native

lazy val tests = crossProject(JSPlatform, JVMPlatform, NativePlatform)
Expand All @@ -107,13 +106,13 @@ lazy val tests = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.settings(
shared,
caseAppPrefix,
skip.in(publish) := true,
skip.in(publish) := true,
libraryDependencies += Deps.utest.value % Test,
testFrameworks += new TestFramework("utest.runner.Framework")
)

lazy val testsJVM = tests.jvm
lazy val testsJS = tests.js
lazy val testsJVM = tests.jvm
lazy val testsJS = tests.js
lazy val testsNative = tests.native

lazy val refined = crossProject(JSPlatform, JVMPlatform)
Expand All @@ -130,8 +129,8 @@ lazy val refined = crossProject(JSPlatform, JVMPlatform)
)

lazy val refinedJVM = refined.jvm
lazy val refinedJS = refined.js
lazy val refinedJS = refined.js

disablePlugins(MimaPlugin)
skip.in(publish) := true
skip.in(publish) := true
crossScalaVersions := Nil
38 changes: 19 additions & 19 deletions cats/shared/src/main/scala/caseapp/cats/IOCaseApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,13 @@ abstract class IOCaseApp[T](implicit val parser0: Parser[T], val messages: Help[
def println(x: String): IO[Unit] =
IO(Console.println(x))

/**
* Arguments are expanded then parsed. By default, argument expansion is the identity function.
/** Arguments are expanded then parsed. By default, argument expansion is the identity function.
* Overriding this method allows plugging in an arbitrary argument expansion logic.
*
* One such expansion logic involves replacing each argument of the form '@<file>' with the
* contents of that file where each line in the file becomes a distinct argument.
* To enable this behavior, override this method as shown below.
* contents of that file where each line in the file becomes a distinct argument. To enable this
* behavior, override this method as shown below.
*
* @example
* {{{
* import caseapp.core.parser.PlatformArgsExpander
Expand All @@ -57,21 +56,18 @@ abstract class IOCaseApp[T](implicit val parser0: Parser[T], val messages: Help[
*/
def expandArgs(args: List[String]): List[String] = args

/**
* Whether to stop parsing at the first unrecognized argument.
/** Whether to stop parsing at the first unrecognized argument.
*
* That is, stop parsing at the first non option (not starting with "-"), or
* the first unrecognized option. The unparsed arguments are put in the `args`
* argument of `run`.
* That is, stop parsing at the first non option (not starting with "-"), or the first
* unrecognized option. The unparsed arguments are put in the `args` argument of `run`.
*/
def stopAtFirstUnrecognized: Boolean =
false

/**
* Whether to ignore unrecognized arguments.
/** Whether to ignore unrecognized arguments.
*
* That is, if there are unrecognized arguments, the parsing still succeeds.
* The unparsed arguments are put in the `args` argument of `run`.
* That is, if there are unrecognized arguments, the parsing still succeeds. The unparsed
* arguments are put in the `args` argument of `run`.
*/
def ignoreUnrecognized: Boolean =
false
Expand All @@ -80,11 +76,15 @@ abstract class IOCaseApp[T](implicit val parser0: Parser[T], val messages: Help[
Formatter.DefaultNameFormatter

override def run(args: List[String]): IO[ExitCode] =
parser.withHelp.detailedParse(expandArgs(args), stopAtFirstUnrecognized, ignoreUnrecognized) match {
case Left(err) => error(err)
case Right((WithHelp(_, true, _), _)) => helpAsked
case Right((WithHelp(true, _, _), _)) => usageAsked
case Right((WithHelp(_, _, Left(err)), _)) => error(err)
parser.withHelp.detailedParse(
expandArgs(args),
stopAtFirstUnrecognized,
ignoreUnrecognized
) match {
case Left(err) => error(err)
case Right((WithHelp(_, true, _), _)) => helpAsked
case Right((WithHelp(true, _, _), _)) => usageAsked
case Right((WithHelp(_, _, Left(err)), _)) => error(err)
case Right((WithHelp(_, _, Right(t)), remainingArgs)) => run(t, remainingArgs)
}
}
9 changes: 4 additions & 5 deletions cats/shared/src/main/scala/caseapp/cats/IOCommandApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ import cats.effect.{ExitCode, IO}
abstract class IOCommandApp[T](implicit
commandParser: CommandParser[T],
commandsMessages: CommandsHelp[T]
) extends IOCommandAppWithPreCommand[None.type , T] {
) extends IOCommandAppWithPreCommand[None.type, T] {

override def beforeCommand(options: None.type, remainingArgs: Seq[String]): IO[Option[ExitCode]] = {
if (remainingArgs.nonEmpty) {
override def beforeCommand(options: None.type, remainingArgs: Seq[String]): IO[Option[ExitCode]] =
if (remainingArgs.nonEmpty)
error(Error.Other(s"Found extra arguments: ${remainingArgs.mkString(" ")}"))
.map(Some(_))
} else IO.none
}
else IO.none
}
Loading

0 comments on commit 44b600f

Please sign in to comment.