Skip to content

Commit

Permalink
Merge pull request #1297 from romanowski/sip-docs
Browse files Browse the repository at this point in the history
Add mechanism to restrict options based on description and generate reference docs for SIP
  • Loading branch information
romanowski authored Sep 12, 2022
2 parents 932c942 + 52aca4d commit c8fc935
Show file tree
Hide file tree
Showing 71 changed files with 2,724 additions and 1,786 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ object CrossSources {
elem,
logger,
maybeRecoverOnError,
inputs.withRestrictedFeatures
inputs.allowRestrictedFeatures
).iterator
)
.take(1)
Expand Down
16 changes: 8 additions & 8 deletions modules/build/src/main/scala/scala/build/Inputs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final case class Inputs(
mayAppendHash: Boolean,
workspaceOrigin: Option[WorkspaceOrigin],
enableMarkdown: Boolean,
withRestrictedFeatures: Boolean
allowRestrictedFeatures: Boolean
) {

def isEmpty: Boolean =
Expand Down Expand Up @@ -303,7 +303,7 @@ object Inputs {
directories: Directories,
forcedWorkspace: Option[os.Path],
enableMarkdown: Boolean,
withRestrictedFeatures: Boolean
allowRestrictedFeatures: Boolean
): Inputs = {

assert(validElems.nonEmpty)
Expand Down Expand Up @@ -364,7 +364,7 @@ object Inputs {
mayAppendHash = needsHash,
workspaceOrigin = Some(workspaceOrigin0),
enableMarkdown = enableMarkdown,
withRestrictedFeatures = withRestrictedFeatures
allowRestrictedFeatures = allowRestrictedFeatures
)
}

Expand Down Expand Up @@ -491,7 +491,7 @@ object Inputs {
acceptFds: Boolean,
forcedWorkspace: Option[os.Path],
enableMarkdown: Boolean,
withRestrictedFeatures: Boolean
allowRestrictedFeatures: Boolean
): Either[BuildException, Inputs] = {
val validatedArgs: Seq[Either[String, Seq[Element]]] =
validateArgs(args, cwd, download, stdinOpt, acceptFds)
Expand All @@ -513,7 +513,7 @@ object Inputs {
directories,
forcedWorkspace,
enableMarkdown,
withRestrictedFeatures
allowRestrictedFeatures
))
}
else
Expand All @@ -534,7 +534,7 @@ object Inputs {
acceptFds: Boolean = false,
forcedWorkspace: Option[os.Path] = None,
enableMarkdown: Boolean = false,
withRestrictedFeatures: Boolean
allowRestrictedFeatures: Boolean
): Either[BuildException, Inputs] =
if (
args.isEmpty && scriptSnippetList.isEmpty && scalaSnippetList.isEmpty && javaSnippetList.isEmpty
Expand All @@ -556,7 +556,7 @@ object Inputs {
acceptFds,
forcedWorkspace,
enableMarkdown,
withRestrictedFeatures
allowRestrictedFeatures
)

def default(): Option[Inputs] =
Expand All @@ -571,7 +571,7 @@ object Inputs {
mayAppendHash = true,
workspaceOrigin = None,
enableMarkdown = enableMarkdown,
withRestrictedFeatures = false
allowRestrictedFeatures = false
)

def empty(projectName: String): Inputs =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ case object DataPreprocessor extends Preprocessor {
input: Inputs.SingleElement,
logger: Logger,
maybeRecoverOnError: BuildException => Option[BuildException] = e => Some(e),
withRestrictedFeatures: Boolean
allowRestrictedFeatures: Boolean
): Option[Either[BuildException, Seq[PreprocessedSource]]] =
input match {
case file: Inputs.VirtualData =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ object DirectivesProcessor {
path: Either[String, os.Path],
cwd: ScopePath,
logger: Logger,
withRestrictedFeatures: Boolean
allowRestrictedFeatures: Boolean
): Either[BuildException, DirectivesProcessorOutput[T]] = {
val configMonoidInstance = implicitly[ConfigMonoid[T]]

def handleValues(handler: DirectiveHandler[T])(
scopedDirective: ScopedDirective,
logger: Logger
) =
if (withRestrictedFeatures && handler.isRestricted)
if (!allowRestrictedFeatures && handler.isRestricted)
val msg =
"This directive is not supported with 'scala' command. Please run it with `scala-cli` command or with `--power` flag."
Left(DirectiveErrors(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ final case class JavaPreprocessor(
input: Inputs.SingleElement,
logger: Logger,
maybeRecoverOnError: BuildException => Option[BuildException] = e => Some(e),
withRestrictedFeatures: Boolean
allowRestrictedFeatures: Boolean
): Option[Either[BuildException, Seq[PreprocessedSource]]] =
input match {
case j: Inputs.JavaFile => Some(either {
Expand All @@ -56,7 +56,7 @@ final case class JavaPreprocessor(
Right(j.path),
scopePath,
logger,
withRestrictedFeatures
allowRestrictedFeatures
))
Seq(PreprocessedSource.OnDisk(
j.path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ case object MarkdownPreprocessor extends Preprocessor {
input: Inputs.SingleElement,
logger: Logger,
maybeRecoverOnError: BuildException => Option[BuildException],
withRestrictedFeatures: Boolean
allowRestrictedFeatures: Boolean
): Option[Either[BuildException, Seq[PreprocessedSource]]] =
input match {
case markdown: Inputs.MarkdownFile =>
Expand All @@ -28,7 +28,7 @@ case object MarkdownPreprocessor extends Preprocessor {
ScopePath.fromPath(markdown.path),
logger,
maybeRecoverOnError,
withRestrictedFeatures
allowRestrictedFeatures
)
}
preprocessed
Expand All @@ -46,7 +46,7 @@ case object MarkdownPreprocessor extends Preprocessor {
scopePath: ScopePath,
logger: Logger,
maybeRecoverOnError: BuildException => Option[BuildException],
withRestrictedFeatures: Boolean
allowRestrictedFeatures: Boolean
): Either[BuildException, List[PreprocessedSource.InMemory]] = either {
def preprocessSnippets(
maybeCode: Option[String],
Expand All @@ -63,7 +63,7 @@ case object MarkdownPreprocessor extends Preprocessor {
scopeRoot = scopePath / os.up,
logger = logger,
maybeRecoverOnError = maybeRecoverOnError,
withRestrictedFeatures = withRestrictedFeatures
allowRestrictedFeatures = allowRestrictedFeatures
)
}.getOrElse(ProcessingOutput(BuildRequirements(), Nil, BuildOptions(), None))
val processedCode = processingOutput.updatedContent.getOrElse(code)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ trait Preprocessor {
input: Inputs.SingleElement,
logger: Logger,
maybeRecoverOnError: BuildException => Option[BuildException] = e => Some(e),
withRestrictedFeatures: Boolean
allowRestrictedFeatures: Boolean
): Option[Either[BuildException, Seq[PreprocessedSource]]]
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ case object ScalaPreprocessor extends Preprocessor {
input: Inputs.SingleElement,
logger: Logger,
maybeRecoverOnError: BuildException => Option[BuildException] = e => Some(e),
withRestrictedFeatures: Boolean
allowRestrictedFeatures: Boolean
): Option[Either[BuildException, Seq[PreprocessedSource]]] =
input match {
case f: Inputs.ScalaFile =>
Expand All @@ -87,7 +87,7 @@ case object ScalaPreprocessor extends Preprocessor {
scopePath / os.up,
logger,
maybeRecoverOnError,
withRestrictedFeatures
allowRestrictedFeatures
)
) match {
case None =>
Expand Down Expand Up @@ -137,7 +137,7 @@ case object ScalaPreprocessor extends Preprocessor {
v.scopePath / os.up,
logger,
maybeRecoverOnError,
withRestrictedFeatures
allowRestrictedFeatures
)
).map {
case ProcessingOutput(reqs, scopedReqs, opts, updatedContent) =>
Expand Down Expand Up @@ -168,7 +168,7 @@ case object ScalaPreprocessor extends Preprocessor {
scopeRoot: ScopePath,
logger: Logger,
maybeRecoverOnError: BuildException => Option[BuildException],
withRestrictedFeatures: Boolean
allowRestrictedFeatures: Boolean
): Either[BuildException, Option[ProcessingOutput]] = either {
val (content0, isSheBang) = SheBang.ignoreSheBangLines(content)
val afterStrictUsing: StrictDirectivesProcessingOutput =
Expand All @@ -178,7 +178,7 @@ case object ScalaPreprocessor extends Preprocessor {
scopeRoot,
logger,
maybeRecoverOnError,
withRestrictedFeatures
allowRestrictedFeatures
))

val afterProcessImports: Option[SpecialImportsProcessingOutput] = value {
Expand Down Expand Up @@ -297,7 +297,7 @@ case object ScalaPreprocessor extends Preprocessor {
cwd: ScopePath,
logger: Logger,
maybeRecoverOnError: BuildException => Option[BuildException] = e => Some(e),
withRestrictedFeatures: Boolean
allowRestrictedFeatures: Boolean
): Either[BuildException, StrictDirectivesProcessingOutput] = either {
val contentChars = content.toCharArray
val ExtractedDirectives(codeOffset, directives0) =
Expand All @@ -317,7 +317,7 @@ case object ScalaPreprocessor extends Preprocessor {
path,
cwd,
logger,
withRestrictedFeatures
allowRestrictedFeatures
)
}

Expand All @@ -330,7 +330,7 @@ case object ScalaPreprocessor extends Preprocessor {
path,
cwd,
logger,
withRestrictedFeatures
allowRestrictedFeatures
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final case class ScriptPreprocessor(codeWrapper: CodeWrapper) extends Preprocess
input: Inputs.SingleElement,
logger: Logger,
maybeRecoverOnError: BuildException => Option[BuildException] = e => Some(e),
withRestrictedFeatures: Boolean
allowRestrictedFeatures: Boolean
): Option[Either[BuildException, Seq[PreprocessedSource]]] =
input match {
case script: Inputs.Script =>
Expand All @@ -29,7 +29,7 @@ final case class ScriptPreprocessor(codeWrapper: CodeWrapper) extends Preprocess
ScopePath.fromPath(script.path),
logger,
maybeRecoverOnError,
withRestrictedFeatures
allowRestrictedFeatures
)
}
preprocessed
Expand All @@ -49,7 +49,7 @@ final case class ScriptPreprocessor(codeWrapper: CodeWrapper) extends Preprocess
script.scopePath,
logger,
maybeRecoverOnError,
withRestrictedFeatures
allowRestrictedFeatures
)
}
preprocessed
Expand All @@ -71,7 +71,7 @@ object ScriptPreprocessor {
scopePath: ScopePath,
logger: Logger,
maybeRecoverOnError: BuildException => Option[BuildException],
withRestrictedFeatures: Boolean
allowRestrictedFeatures: Boolean
): Either[BuildException, List[PreprocessedSource.InMemory]] = either {

val (contentIgnoredSheBangLines, _) = SheBang.ignoreSheBangLines(content)
Expand All @@ -85,7 +85,7 @@ object ScriptPreprocessor {
scopePath / os.up,
logger,
maybeRecoverOnError,
withRestrictedFeatures
allowRestrictedFeatures
))
.getOrElse(ProcessingOutput(BuildRequirements(), Nil, BuildOptions(), None))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class PreprocessingTests extends munit.FunSuite {
val logger = TestLogger()
val scalaFile = Inputs.SourceScalaFile(os.temp.dir(), os.SubPath("NotExists.scala"))

val res = ScalaPreprocessor.preprocess(scalaFile, logger, withRestrictedFeatures = false)
val res = ScalaPreprocessor.preprocess(scalaFile, logger, allowRestrictedFeatures = false)
val expectedMessage = s"File not found: ${scalaFile.path}"

assert(res.nonEmpty)
Expand All @@ -27,7 +27,7 @@ class PreprocessingTests extends munit.FunSuite {
val res = ScriptPreprocessor(CustomCodeWrapper).preprocess(
scalaScript,
logger,
withRestrictedFeatures = false
allowRestrictedFeatures = false
)
val expectedMessage = s"File not found: ${scalaScript.path}"

Expand All @@ -40,7 +40,7 @@ class PreprocessingTests extends munit.FunSuite {
val logger = TestLogger()
val markdownFile = Inputs.MarkdownFile(os.temp.dir(), os.SubPath("NotExists.md"))

val res = MarkdownPreprocessor.preprocess(markdownFile, logger, withRestrictedFeatures = false)
val res = MarkdownPreprocessor.preprocess(markdownFile, logger, allowRestrictedFeatures = false)
val expectedMessage = s"File not found: ${markdownFile.path}"

assert(res.nonEmpty)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ final case class TestInputs(
tmpDir,
Directories.under(tmpDir / ".data"),
forcedWorkspace = forcedWorkspaceOpt.map(_.resolveFrom(tmpDir)),
withRestrictedFeatures = false
allowRestrictedFeatures = true
)
res match {
case Left(err) => throw new Exception(err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ final case class AboutOptions(
@Recurse
verbosity: VerbosityOptions = VerbosityOptions(),
@Hidden
@HelpMessage(HelpMessages.passwordOption)
ghToken: Option[PasswordOption] = None
)
// format: on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import caseapp._
// format: off
final case class BenchmarkingOptions(
@Group("Benchmarking")
@HelpMessage("Run JMH benchmarks")
@HelpMessage("[experimental] Run JMH benchmarks")
jmh: Option[Boolean] = None,
@Group("Benchmarking")
@HelpMessage("Set JMH version")
@HelpMessage("[experimental] Set JMH version")
@ValueDescription("version")
jmhVersion: Option[String] = None
)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import caseapp._

// format: off
final case class CrossOptions(
@HelpMessage("[experimental] Run given command against all provided Scala versions and/or platforms")
cross: Option[Boolean] = None
)
// format: on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ final case class DependencyUpdateOptions(
@Recurse
shared: SharedOptions = SharedOptions(),
@Group("DependencyUpdate")
@HelpMessage("Update all dependency")
@HelpMessage("Update all dependencies if newer version was released")
all: Boolean = false,
)
// format: on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import caseapp._
import caseapp.core.help.Help

// format: off
@HelpMessage("Generate Scaladoc documentation")
@HelpMessage("Generate Scaladoc documentation", "By default, Scala CLI sets common scaladoc options and this mechanism can be disabled by using `--default-scaladoc-opts:false`.")
final case class DocOptions(
@Recurse
shared: SharedOptions = SharedOptions(),
Expand All @@ -17,7 +17,7 @@ final case class DocOptions(
@Name("f")
force: Boolean = false,
@Group("Doc")
@HelpMessage("Use default scaladoc options")
@HelpMessage("Control if scala CLI should use default options for scaladoc, true by default. Use `--default-scaladoc-opts:false` to not include default options.")
@ExtraName("defaultScaladocOpts")
defaultScaladocOptions: Option[Boolean] = None,
)
Expand Down
Loading

0 comments on commit c8fc935

Please sign in to comment.