Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate the --source command line option for the package sub-command #3257

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package scala.cli.commands
import caseapp.Name
import caseapp.core.app.Command
import caseapp.core.parser.Parser
import caseapp.core.util.Formatter
import caseapp.core.util.{CaseUtil, Formatter}
import caseapp.core.{Arg, Error}

import scala.build.Logger
import scala.build.input.ScalaCliInvokeData
import scala.build.internal.util.WarningMessages
import scala.build.internals.FeatureType
import scala.build.internals.{ConsoleUtils, FeatureType}
import scala.cli.ScalaCli
import scala.cli.util.ArgHelpers.*

Expand Down Expand Up @@ -57,6 +57,16 @@ object RestrictedCommandsParser {
if arg.isExperimental && !shouldSuppressExperimentalWarnings =>
logger.experimentalWarning(passedOption, FeatureType.Option)
r
case (r @ Right(Some(_, arg: Arg, _)), passedOption :: _)
if arg.isDeprecated =>
// TODO implement proper deprecation logic: https://github.com/VirtusLab/scala-cli/issues/3258
arg.deprecatedOptionAliases.find(_ == passedOption)
.foreach { deprecatedAlias =>
logger.message(
s"""[${Console.YELLOW}warn${Console.RESET}] The $deprecatedAlias option alias has been deprecated and may be removed in a future version."""
)
}
r
case (other, _) =>
other
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@ final case class PackageOptions(
library: Boolean = false,
@Group(HelpGroup.Package.toString)
@HelpMessage("Generate a source JAR rather than an executable JAR")
@Name("sourcesJar")
@Name("jarSources")
@Name("sources")
@Name("src")
@Name("source")
@Tag(tags.deprecated("source")) // alias to be removed in 1.6.x
@Tag(tags.restricted)
@Tag(tags.inShortHelp)
source: Boolean = false,
src: Boolean = false,
Gedochao marked this conversation as resolved.
Show resolved Hide resolved
@Group(HelpGroup.Package.toString)
@HelpMessage("Generate a scaladoc JAR rather than an executable JAR")
@ExtraName("scaladoc")
Expand Down Expand Up @@ -144,7 +147,7 @@ final case class PackageOptions(
def packageTypeOpt: Option[PackageType] =
forcedPackageTypeOpt.orElse {
if (library) Some(PackageType.LibraryJar)
else if (source) Some(PackageType.SourceJar)
else if (src) Some(PackageType.SourceJar)
else if (assembly) Some(
PackageType.Assembly(
addPreamble = preamble,
Expand Down
21 changes: 19 additions & 2 deletions modules/cli/src/main/scala/scala/cli/util/ArgHelpers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package scala.cli.util

import caseapp.core.Arg
import caseapp.core.help.HelpFormat
import caseapp.core.util.CaseUtil

import scala.build.input.ScalaCliInvokeData
import scala.build.internal.util.WarningMessages
Expand All @@ -12,8 +13,24 @@ import scala.cli.commands.{SpecificationLevel, tags}
object ArgHelpers {
extension (arg: Arg) {
private def hasTag(tag: String): Boolean = arg.tags.exists(_.name == tag)
def isExperimental: Boolean = arg.hasTag(tags.experimental)
def isRestricted: Boolean = arg.hasTag(tags.restricted)
private def hasTagPrefix(tagPrefix: String): Boolean =
arg.tags.exists(_.name.startsWith(tagPrefix))
def isExperimental: Boolean = arg.hasTag(tags.experimental)
def isRestricted: Boolean = arg.hasTag(tags.restricted)
def isDeprecated: Boolean = arg.hasTagPrefix(tags.deprecatedPrefix)

def deprecatedNames: List[String] = arg.tags
.filter(_.name.startsWith(tags.deprecatedPrefix))
.map(_.name.stripPrefix(s"${tags.deprecatedPrefix}${tags.valueSeparator}"))
.toList

def deprecatedOptionAliases: List[String] = arg.deprecatedNames.map {
case name if name.startsWith("-") => name
case name if name.length == 1 => "-" + name
case name => "--" + CaseUtil.pascalCaseSplit(name.toCharArray.toList).map(
_.toLowerCase
).mkString("-")
}

def isExperimentalOrRestricted: Boolean = arg.isRestricted || arg.isExperimental

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,11 @@ object GenerateReferenceDoc extends CaseApp[InternalDocOptions] {
names
.tail
.sortBy(_.dropWhile(_ == '-'))
.map(n => s"`$n`")
.map {
case name if arg.deprecatedOptionAliases.contains(name) =>
s"[deprecated] `$name`"
case name => s"`$name`"
}
.mkString("Aliases: ", ", ", "\n\n")
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -859,11 +859,16 @@ abstract class PackageTestDefinitions extends ScalaCliSuite with TestScalaVersio
test("source JAR") {
val dest = os.rel / "sources.jar"
simpleInputWithScalaAndSc.fromRoot { root =>
os.proc(TestUtil.cli, "--power", "package", extraOptions, ".", "-o", dest, "--source").call(
cwd = root,
stdin = os.Inherit,
stdout = os.Inherit
)
val r =
os.proc(TestUtil.cli, "--power", "package", extraOptions, ".", "-o", dest, "--source").call(
cwd = root,
stdin = os.Inherit,
stdout = os.Inherit,
stderr = os.Pipe
)
expect(r.err.trim().contains(
"The --source option alias has been deprecated and may be removed in a future version"
))

expect(os.isFile(root / dest))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ object SpecificationLevel {
}

object tags {
val valueSeparator: String = ":" // separates values in a tag

// specification level tags
val experimental: String = SpecificationLevel.EXPERIMENTAL.toString
val restricted: String = SpecificationLevel.RESTRICTED.toString
Expand All @@ -68,7 +70,10 @@ object tags {
// other tags
// the `inShortHelp` tag whitelists options to be included in --help
// this is in contrast to blacklisting options in --help with the @Hidden annotation
val inShortHelp: String = "inShortHelp" // included in --help by default
val inShortHelp: String = "inShortHelp" // included in --help by default
val deprecatedPrefix: String = "deprecated"
def deprecated(name: String): String =
s"$deprecatedPrefix$valueSeparator$name" // produces a deprecated warning for the given name

def levelFor(name: String): Option[SpecificationLevel] = name match {
case `experimental` => Some(SpecificationLevel.EXPERIMENTAL)
Expand Down
4 changes: 2 additions & 2 deletions website/docs/reference/cli-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -749,9 +749,9 @@ Overwrite the destination file, if it exists

Generate a library JAR rather than an executable JAR

### `--source`
### `--src`

Aliases: `--sources`, `--src`
Aliases: `--jar-sources`, [deprecated] `--source`, `--sources`, `--sources-jar`

Generate a source JAR rather than an executable JAR

Expand Down
Loading