From 83d645d3e432353c610b26ea377d2ae752716ed4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Pra=C5=BCak?= Date: Thu, 16 May 2024 20:14:28 +0200 Subject: [PATCH] Add auto module --- .../besom/auto/{ => internal}/AutoError.scala | 2 +- .../scala/besom/auto/{ => internal}/Git.scala | 2 +- .../auto/{ => internal}/LocalWorkspace.scala | 7 +++-- .../besom/auto/{ => internal}/Stack.scala | 27 +++++++++---------- .../besom/auto/{ => internal}/Workspace.scala | 6 +---- .../besom/auto/{ => internal}/auto.scala | 2 +- .../besom/auto/{ => internal}/shell.scala | 2 +- .../{ => internal}/LocalWorkspaceTest.scala | 4 +-- .../besom/auto/{ => internal}/ShellTest.scala | 4 +-- .../besom/auto/{ => internal}/StackTest.scala | 2 +- auto/src/test/scala/besom/test/Naming.scala | 6 ++--- 11 files changed, 29 insertions(+), 35 deletions(-) rename auto/src/main/scala/besom/auto/{ => internal}/AutoError.scala (99%) rename auto/src/main/scala/besom/auto/{ => internal}/Git.scala (99%) rename auto/src/main/scala/besom/auto/{ => internal}/LocalWorkspace.scala (99%) rename auto/src/main/scala/besom/auto/{ => internal}/Stack.scala (98%) rename auto/src/main/scala/besom/auto/{ => internal}/Workspace.scala (99%) rename auto/src/main/scala/besom/auto/{ => internal}/auto.scala (99%) rename auto/src/main/scala/besom/auto/{ => internal}/shell.scala (99%) rename auto/src/test/scala/besom/auto/{ => internal}/LocalWorkspaceTest.scala (95%) rename auto/src/test/scala/besom/auto/{ => internal}/ShellTest.scala (94%) rename auto/src/test/scala/besom/auto/{ => internal}/StackTest.scala (96%) diff --git a/auto/src/main/scala/besom/auto/AutoError.scala b/auto/src/main/scala/besom/auto/internal/AutoError.scala similarity index 99% rename from auto/src/main/scala/besom/auto/AutoError.scala rename to auto/src/main/scala/besom/auto/internal/AutoError.scala index befe61b2..44b19c35 100644 --- a/auto/src/main/scala/besom/auto/AutoError.scala +++ b/auto/src/main/scala/besom/auto/internal/AutoError.scala @@ -1,4 +1,4 @@ -package besom.auto +package besom.auto.internal import scala.util.matching.Regex diff --git a/auto/src/main/scala/besom/auto/Git.scala b/auto/src/main/scala/besom/auto/internal/Git.scala similarity index 99% rename from auto/src/main/scala/besom/auto/Git.scala rename to auto/src/main/scala/besom/auto/internal/Git.scala index de6c9ae6..c907db86 100644 --- a/auto/src/main/scala/besom/auto/Git.scala +++ b/auto/src/main/scala/besom/auto/internal/Git.scala @@ -1,4 +1,4 @@ -package besom.auto +package besom.auto.internal import besom.util.* import com.jcraft.jsch.JSch diff --git a/auto/src/main/scala/besom/auto/LocalWorkspace.scala b/auto/src/main/scala/besom/auto/internal/LocalWorkspace.scala similarity index 99% rename from auto/src/main/scala/besom/auto/LocalWorkspace.scala rename to auto/src/main/scala/besom/auto/internal/LocalWorkspace.scala index 9074dab6..755fb4d1 100644 --- a/auto/src/main/scala/besom/auto/LocalWorkspace.scala +++ b/auto/src/main/scala/besom/auto/internal/LocalWorkspace.scala @@ -1,7 +1,6 @@ -package besom.auto +package besom.auto.internal import besom.json.* -import besom.json.DefaultJsonProtocol.* import besom.model.{PackageName, SemanticVersion, FullyQualifiedStackName, StackName} import besom.util.* import besom.model @@ -949,11 +948,11 @@ object LocalWorkspaceOption: /** The project settings for the workspace. */ - case class Project(project: besom.auto.Project) extends LocalWorkspaceOption + case class Project(project: besom.auto.internal.Project) extends LocalWorkspaceOption /** A map of `[stackName -> stack settings objects]` to seed the workspace. */ - case class Stacks(stacks: Map[String, besom.auto.ProjectStack]) extends LocalWorkspaceOption + case class Stacks(stacks: Map[String, besom.auto.internal.ProjectStack]) extends LocalWorkspaceOption /** A git repo with a Pulumi Project to clone into the `workDir`. */ diff --git a/auto/src/main/scala/besom/auto/Stack.scala b/auto/src/main/scala/besom/auto/internal/Stack.scala similarity index 98% rename from auto/src/main/scala/besom/auto/Stack.scala rename to auto/src/main/scala/besom/auto/internal/Stack.scala index 80a50588..293eefbf 100644 --- a/auto/src/main/scala/besom/auto/Stack.scala +++ b/auto/src/main/scala/besom/auto/internal/Stack.scala @@ -1,8 +1,7 @@ -package besom.auto +package besom.auto.internal import besom.internal.{LanguageRuntimeServer, LanguageRuntimeService} import besom.json.* -import besom.json.DefaultJsonProtocol.* import besom.util.* import scala.util.Try @@ -17,7 +16,7 @@ import scala.util.Try * the underlying [[Workspace]] backing the [[Stack]] */ case class Stack(name: String, workspace: Workspace): - import besom.auto.Stack.* + import besom.auto.internal.Stack.* protected[auto] def pulumi(additional: os.Shellable*)(opts: shell.ShellOption*): Either[ShellAutoError | AutoError, shell.Result] = for @@ -686,10 +685,10 @@ object PreviewOption: */ case class UserAgent(agent: String) extends PreviewOption - /** Colorize output. Choices are: [[besom.auto.Color.Always]], [[besom.auto.Color.Never]], [[besom.auto.Color.Raw]], - * [[besom.auto.Color.Auto]] (default "Auto") + /** Colorize output. Choices are: [[besom.auto.internal.Color.Always]], [[besom.auto.internal.Color.Never]], [[besom.auto.internal.Color.Raw]], + * [[besom.auto.internal.Color.Auto]] (default "Auto") */ - case class Color(color: besom.auto.Color) extends PreviewOption + case class Color(color: besom.auto.internal.Color) extends PreviewOption /** Saves an update plan to the given path. */ @@ -844,9 +843,9 @@ object UpOption: */ case class UserAgent(agent: String) extends UpOption - /** Colorize output. Choices are: [[besom.auto.Color.Always]], [[besom.auto.Color.Never]], [[besom.auto.Color.Raw]], + /** Colorize output. Choices are: [[besom.auto.internal.Color.Always]], [[besom.auto.internal.Color.Never]], [[besom.auto.internal.Color.Raw]], */ - case class Color(color: besom.auto.Color) extends UpOption + case class Color(color: besom.auto.internal.Color) extends UpOption /** Use the update plan at the given path. */ @@ -992,9 +991,9 @@ object RefreshOption: */ case class UserAgent(agent: String) extends RefreshOption - /** Colorize output. Choices are: [[besom.auto.Color.Always]], [[besom.auto.Color.Never]], [[besom.auto.Color.Raw]], + /** Colorize output. Choices are: [[besom.auto.internal.Color.Always]], [[besom.auto.internal.Color.Never]], [[besom.auto.internal.Color.Raw]], */ - case class Color(color: besom.auto.Color) extends RefreshOption + case class Color(color: besom.auto.internal.Color) extends RefreshOption /** Show config secrets when they appear. */ @@ -1105,9 +1104,9 @@ object DestroyOption: */ case class UserAgent(agent: String) extends DestroyOption - /** Colorize output. Choices are: [[besom.auto.Color.Always]], [[besom.auto.Color.Never]], [[besom.auto.Color.Raw]], + /** Colorize output. Choices are: [[besom.auto.internal.Color.Always]], [[besom.auto.internal.Color.Never]], [[besom.auto.internal.Color.Raw]], */ - case class Color(color: besom.auto.Color) extends DestroyOption + case class Color(color: besom.auto.internal.Color) extends DestroyOption /** Show config secrets when they appear. */ @@ -1243,8 +1242,8 @@ case class LoggingOptions( Option.when(debug)("--debug") ).flatten -/** Colorize output. Choices are: [[besom.auto.Color.Always]], [[besom.auto.Color.Never]], [[besom.auto.Color.Raw]], - * [[besom.auto.Color.Auto]] (default "Auto") +/** Colorize output. Choices are: [[besom.auto.internal.Color.Always]], [[besom.auto.internal.Color.Never]], [[besom.auto.internal.Color.Raw]], + * [[besom.auto.internal.Color.Auto]] (default "Auto") */ enum Color(val value: String): override def toString: String = value diff --git a/auto/src/main/scala/besom/auto/Workspace.scala b/auto/src/main/scala/besom/auto/internal/Workspace.scala similarity index 99% rename from auto/src/main/scala/besom/auto/Workspace.scala rename to auto/src/main/scala/besom/auto/internal/Workspace.scala index 6c0ed333..b90ed0f2 100644 --- a/auto/src/main/scala/besom/auto/Workspace.scala +++ b/auto/src/main/scala/besom/auto/internal/Workspace.scala @@ -1,7 +1,6 @@ -package besom.auto +package besom.auto.internal import besom.json.* -import besom.json.DefaultJsonProtocol.* import besom.model import besom.util.* import org.virtuslab.yaml.* @@ -14,15 +13,12 @@ import scala.util.Try object yamlHack: import org.virtuslab.yaml.internal.dump.present.PresenterImpl - import besom.auto.internal.HackedSerializerImpl def asYaml(node: Node): String = val events = HackedSerializerImpl.toEvents(node) PresenterImpl.asString(events) end yamlHack -given JsonProtocol = DefaultJsonProtocol - given JsonFormat[Any] = new JsonFormat[Any]: override def write(obj: Any): JsValue = obj match diff --git a/auto/src/main/scala/besom/auto/auto.scala b/auto/src/main/scala/besom/auto/internal/auto.scala similarity index 99% rename from auto/src/main/scala/besom/auto/auto.scala rename to auto/src/main/scala/besom/auto/internal/auto.scala index 55f27925..7131432a 100644 --- a/auto/src/main/scala/besom/auto/auto.scala +++ b/auto/src/main/scala/besom/auto/internal/auto.scala @@ -1,4 +1,4 @@ -package besom.auto +package besom.auto.internal import LocalWorkspaceOption.* import LocalWorkspace.* diff --git a/auto/src/main/scala/besom/auto/shell.scala b/auto/src/main/scala/besom/auto/internal/shell.scala similarity index 99% rename from auto/src/main/scala/besom/auto/shell.scala rename to auto/src/main/scala/besom/auto/internal/shell.scala index 7c210fe5..3c910550 100644 --- a/auto/src/main/scala/besom/auto/shell.scala +++ b/auto/src/main/scala/besom/auto/internal/shell.scala @@ -1,4 +1,4 @@ -package besom.auto +package besom.auto.internal import besom.util.* import os.CommandResult diff --git a/auto/src/test/scala/besom/auto/LocalWorkspaceTest.scala b/auto/src/test/scala/besom/auto/internal/LocalWorkspaceTest.scala similarity index 95% rename from auto/src/test/scala/besom/auto/LocalWorkspaceTest.scala rename to auto/src/test/scala/besom/auto/internal/LocalWorkspaceTest.scala index 8ac44938..328bdeaa 100644 --- a/auto/src/test/scala/besom/auto/LocalWorkspaceTest.scala +++ b/auto/src/test/scala/besom/auto/internal/LocalWorkspaceTest.scala @@ -1,6 +1,6 @@ -package besom.auto +package besom.auto.internal -import besom.FullyQualifiedStackName +import besom.model.FullyQualifiedStackName import besom.test.* import besom.util.eitherOps diff --git a/auto/src/test/scala/besom/auto/ShellTest.scala b/auto/src/test/scala/besom/auto/internal/ShellTest.scala similarity index 94% rename from auto/src/test/scala/besom/auto/ShellTest.scala rename to auto/src/test/scala/besom/auto/internal/ShellTest.scala index 311bc904..24a0dc59 100644 --- a/auto/src/test/scala/besom/auto/ShellTest.scala +++ b/auto/src/test/scala/besom/auto/internal/ShellTest.scala @@ -1,6 +1,6 @@ -package besom.auto +package besom.auto.internal -import besom.auto.shell.* +import besom.auto.internal.shell.* class ShellTest extends munit.FunSuite: test("ShellOptions.from") { diff --git a/auto/src/test/scala/besom/auto/StackTest.scala b/auto/src/test/scala/besom/auto/internal/StackTest.scala similarity index 96% rename from auto/src/test/scala/besom/auto/StackTest.scala rename to auto/src/test/scala/besom/auto/internal/StackTest.scala index 03837ea5..7c6091cc 100644 --- a/auto/src/test/scala/besom/auto/StackTest.scala +++ b/auto/src/test/scala/besom/auto/internal/StackTest.scala @@ -1,4 +1,4 @@ -package besom.auto +package besom.auto.internal import besom.util.eitherOps diff --git a/auto/src/test/scala/besom/test/Naming.scala b/auto/src/test/scala/besom/test/Naming.scala index efad8bf3..0f052680 100644 --- a/auto/src/test/scala/besom/test/Naming.scala +++ b/auto/src/test/scala/besom/test/Naming.scala @@ -1,6 +1,6 @@ package besom.test -import besom.FullyQualifiedStackName +import besom.model.FullyQualifiedStackName /** SHA1 hash of a string * @@ -15,8 +15,8 @@ def sha1(s: String): String = { String.format("%x", new java.math.BigInteger(1, bytes)) } -def sanitizeName(name: String, replacement: String = "-", limit: Int = 40): String = - name.replaceAll("[^a-zA-Z0-9]+", replacement).toLowerCase().take(limit).stripSuffix(replacement) def stackName(name: String): String = "tests-" + sanitizeName(name) def fqsn(`class`: Class[_], test: munit.TestOptions): FullyQualifiedStackName = FullyQualifiedStackName(sanitizeName(`class`.getSimpleName, limit = 20), stackName(test.name)) +def sanitizeName(name: String, replacement: String = "-", limit: Int = 40): String = + name.replaceAll("[^a-zA-Z0-9]+", replacement).toLowerCase().take(limit).stripSuffix(replacement)