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

CliOptions: expose workingDirectory only in outer #2932

Merged
merged 1 commit into from
Nov 27, 2021
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
4 changes: 1 addition & 3 deletions scalafmt-cli/src/main/scala/org/scalafmt/cli/Cli.scala
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,7 @@ object Cli {
if (options.writeMode == WriteMode.Test)
"Looking for unformatted files..."
else "Reformatting..."
options.common.debug.println(
"Working directory: " + options.common.workingDirectory
)
options.common.debug.println("Working directory: " + options.cwd)

val exit = runner.run(options, termDisplayMessage)

Expand Down
9 changes: 5 additions & 4 deletions scalafmt-cli/src/main/scala/org/scalafmt/cli/CliOptions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ case class CommonOptions(
debug: PrintStream = NoopOutputStream.printStream,
info: PrintStream = NoopOutputStream.printStream
) {
lazy val workingDirectory: AbsoluteFile =
private[cli] lazy val workingDirectory: AbsoluteFile =
cwd.getOrElse(AbsoluteFile.userDir)
}

Expand Down Expand Up @@ -103,6 +103,8 @@ case class CliOptions(
) {
val writeMode: WriteMode = writeModeOpt.getOrElse(WriteMode.Override)

def cwd: AbsoluteFile = common.workingDirectory

/** Create a temporary file that contains configuration string specified by
* `--config-str`. This temporary file will be passed to `scalafmt-dynamic`.
* See https://github.com/scalameta/scalafmt/pull/1367#issuecomment-464744077
Expand Down Expand Up @@ -154,10 +156,9 @@ case class CliOptions(
mode.getOrElse(if (isGit) GitFiles else RecursiveSearch)

lazy val customFilesOpt =
if (customFiles.isEmpty) None
else Some(common.workingDirectory.join(customFiles))
if (customFiles.isEmpty) None else Some(cwd.join(customFiles))

lazy val gitOps: GitOps = gitOpsConstructor(common.workingDirectory)
lazy val gitOps: GitOps = gitOpsConstructor(cwd)

def addFile(file: Path): CliOptions = withFiles(customFiles :+ file)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ object InputMethod {
file.writeFile(text)(options.encoding)

override protected def list(options: CliOptions): Unit = {
val cwd = options.common.workingDirectory.toUri
val cwd = options.cwd.toUri
options.common.out.println(cwd.relativize(file.toUri))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ trait ScalafmtRunner {
)
if (options.writeMode != WriteMode.Stdout && inputMethods.length > 5) {
termDisplay.init()
termDisplay.startTask(msg, options.common.workingDirectory.jfile)
termDisplay.startTask(msg, options.cwd.jfile)
termDisplay.taskLength(msg, inputMethods.length, 0)
}
termDisplay
Expand Down