From febbb4bb46e46b7d8c373013133bffb2cbb07d5a Mon Sep 17 00:00:00 2001 From: windymelt Date: Thu, 22 Dec 2022 20:36:18 +0900 Subject: [PATCH 01/11] split CLI options into CliOptions.scala --- .../com/github/windymelt/zmm/CliOptions.scala | 14 ++++++++++++++ src/main/scala/com/github/windymelt/zmm/Main.scala | 14 +++----------- 2 files changed, 17 insertions(+), 11 deletions(-) create mode 100644 src/main/scala/com/github/windymelt/zmm/CliOptions.scala diff --git a/src/main/scala/com/github/windymelt/zmm/CliOptions.scala b/src/main/scala/com/github/windymelt/zmm/CliOptions.scala new file mode 100644 index 0000000..99f85ea --- /dev/null +++ b/src/main/scala/com/github/windymelt/zmm/CliOptions.scala @@ -0,0 +1,14 @@ +package com.github.windymelt.zmm + +import com.monovore.decline._ +import com.monovore.decline.effect._ + +sealed trait ZmmOption +final case class ShowCommand(target: String) extends ZmmOption // 今のところvoicevoxしか入らない +final case class TargetFile(target: java.nio.file.Path) extends ZmmOption + +object CliOptions { + private val showCommand = Opts.subcommand(name = "show", help = "Prints information.")(Opts.argument[String]("voicevox").map(ShowCommand.apply)) + private val targetFile = Opts.argument[java.nio.file.Path](metavar = "XMLFile").map(TargetFile.apply) + val opts: Opts[ZmmOption] = targetFile orElse showCommand +} diff --git a/src/main/scala/com/github/windymelt/zmm/Main.scala b/src/main/scala/com/github/windymelt/zmm/Main.scala index 64839f1..fcfe0d4 100644 --- a/src/main/scala/com/github/windymelt/zmm/Main.scala +++ b/src/main/scala/com/github/windymelt/zmm/Main.scala @@ -5,23 +5,15 @@ import cats.effect.IOApp import cats.effect.ExitCode import java.io.OutputStream import org.http4s.syntax.header - -import com.monovore.decline._ -import com.monovore.decline.effect._ - -sealed trait ZmmOption -final case class ShowCommand(target: String) extends ZmmOption // 今のところvoicevoxしか入らない -final case class TargetFile(target: java.nio.file.Path) extends ZmmOption +import com.monovore.decline.Opts +import com.monovore.decline.effect.CommandIOApp object Main extends CommandIOApp( name = "zmm", header = "Zunda Movie Maker", version = BuildInfo.version, ) { - val showCommand = Opts.subcommand(name = "show", help = "Prints information.")(Opts.argument[String]("voicevox").map(ShowCommand.apply)) - val targetFile = Opts.argument[java.nio.file.Path](metavar = "XMLFile").map(TargetFile.apply) - val opts: Opts[ZmmOption] = targetFile orElse showCommand - override def main: Opts[IO[ExitCode]] = opts map { o => + override def main: Opts[IO[ExitCode]] = CliOptions.opts map { o => val cli = new Cli() o match { case ShowCommand(target) => target match { From 4ad29404e18db6e0b616e96cefb4817876421b14 Mon Sep 17 00:00:00 2001 From: windymelt Date: Thu, 22 Dec 2022 21:00:33 +0900 Subject: [PATCH 02/11] define "init" subcommand without extra arguments --- src/main/scala/com/github/windymelt/zmm/CliOptions.scala | 4 +++- src/main/scala/com/github/windymelt/zmm/Main.scala | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/scala/com/github/windymelt/zmm/CliOptions.scala b/src/main/scala/com/github/windymelt/zmm/CliOptions.scala index 99f85ea..6a26087 100644 --- a/src/main/scala/com/github/windymelt/zmm/CliOptions.scala +++ b/src/main/scala/com/github/windymelt/zmm/CliOptions.scala @@ -6,9 +6,11 @@ import com.monovore.decline.effect._ sealed trait ZmmOption final case class ShowCommand(target: String) extends ZmmOption // 今のところvoicevoxしか入らない final case class TargetFile(target: java.nio.file.Path) extends ZmmOption +final case class InitializeCommand() extends ZmmOption object CliOptions { private val showCommand = Opts.subcommand(name = "show", help = "Prints information.")(Opts.argument[String]("voicevox").map(ShowCommand.apply)) private val targetFile = Opts.argument[java.nio.file.Path](metavar = "XMLFile").map(TargetFile.apply) - val opts: Opts[ZmmOption] = targetFile orElse showCommand + private val initCommand = Opts.subcommand(name = "init", help = "Initializes current directory as ZMM project.")(Opts.unit.map(_ => InitializeCommand())) + val opts: Opts[ZmmOption] = targetFile orElse showCommand orElse initCommand } diff --git a/src/main/scala/com/github/windymelt/zmm/Main.scala b/src/main/scala/com/github/windymelt/zmm/Main.scala index fcfe0d4..086f95b 100644 --- a/src/main/scala/com/github/windymelt/zmm/Main.scala +++ b/src/main/scala/com/github/windymelt/zmm/Main.scala @@ -23,6 +23,7 @@ object Main extends CommandIOApp( case TargetFile(file) => cli.generate(file.toString) >> IO.pure(cats.effect.ExitCode.Success) + case InitializeCommand() => ??? // TODO: initialize cwd as ZMM project. } } } From d30acb5a7219e1b4ba77d5797622526ff6dc7f0e Mon Sep 17 00:00:00 2001 From: windymelt Date: Thu, 22 Dec 2022 21:02:16 +0900 Subject: [PATCH 03/11] implemented stub initializer --- src/main/scala/com/github/windymelt/zmm/Cli.scala | 2 ++ src/main/scala/com/github/windymelt/zmm/Main.scala | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/scala/com/github/windymelt/zmm/Cli.scala b/src/main/scala/com/github/windymelt/zmm/Cli.scala index f09bade..380988c 100644 --- a/src/main/scala/com/github/windymelt/zmm/Cli.scala +++ b/src/main/scala/com/github/windymelt/zmm/Cli.scala @@ -50,6 +50,8 @@ final class Cli } yield () } + def initializeProject(): IO[Unit] = IO.println("Initialized project!!") // stub + def generate(filePath: String): IO[Unit] = { val content = IO.delay(scala.xml.XML.loadFile(filePath)) diff --git a/src/main/scala/com/github/windymelt/zmm/Main.scala b/src/main/scala/com/github/windymelt/zmm/Main.scala index 086f95b..526234a 100644 --- a/src/main/scala/com/github/windymelt/zmm/Main.scala +++ b/src/main/scala/com/github/windymelt/zmm/Main.scala @@ -23,7 +23,7 @@ object Main extends CommandIOApp( case TargetFile(file) => cli.generate(file.toString) >> IO.pure(cats.effect.ExitCode.Success) - case InitializeCommand() => ??? // TODO: initialize cwd as ZMM project. + case InitializeCommand() => cli.initializeProject() >> IO.pure(cats.effect.ExitCode.Success) } } } From 471a3d673623725bc0b0937bc1229d02edda9de3 Mon Sep 17 00:00:00 2001 From: windymelt Date: Thu, 22 Dec 2022 21:05:40 +0900 Subject: [PATCH 04/11] abbr package --- src/main/scala/com/github/windymelt/zmm/Main.scala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/scala/com/github/windymelt/zmm/Main.scala b/src/main/scala/com/github/windymelt/zmm/Main.scala index 526234a..1f99635 100644 --- a/src/main/scala/com/github/windymelt/zmm/Main.scala +++ b/src/main/scala/com/github/windymelt/zmm/Main.scala @@ -17,13 +17,13 @@ object Main extends CommandIOApp( val cli = new Cli() o match { case ShowCommand(target) => target match { - case "voicevox" => cli.showVoiceVoxSpeakers() >> IO.pure(cats.effect.ExitCode.Success) - case _ => IO.println("subcommand [show] only accepts 'voicevox'. try `show voicevox`") >> IO.pure(cats.effect.ExitCode.Error) + case "voicevox" => cli.showVoiceVoxSpeakers() >> IO.pure(ExitCode.Success) + case _ => IO.println("subcommand [show] only accepts 'voicevox'. try `show voicevox`") >> IO.pure(ExitCode.Error) } case TargetFile(file) => cli.generate(file.toString) >> - IO.pure(cats.effect.ExitCode.Success) - case InitializeCommand() => cli.initializeProject() >> IO.pure(cats.effect.ExitCode.Success) + IO.pure(ExitCode.Success) + case InitializeCommand() => cli.initializeProject() >> IO.pure(ExitCode.Success) } } } From d6f08bdea07af4d9019c3189277791f8bdaa3138 Mon Sep 17 00:00:00 2001 From: windymelt Date: Thu, 22 Dec 2022 21:40:51 +0900 Subject: [PATCH 05/11] =?UTF-8?q?init=E3=82=B3=E3=83=9E=E3=83=B3=E3=83=89?= =?UTF-8?q?=E3=82=92=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scala/com/github/windymelt/zmm/Cli.scala | 48 ++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/src/main/scala/com/github/windymelt/zmm/Cli.scala b/src/main/scala/com/github/windymelt/zmm/Cli.scala index 380988c..b8c46be 100644 --- a/src/main/scala/com/github/windymelt/zmm/Cli.scala +++ b/src/main/scala/com/github/windymelt/zmm/Cli.scala @@ -50,7 +50,53 @@ final class Cli } yield () } - def initializeProject(): IO[Unit] = IO.println("Initialized project!!") // stub + def initializeProject(): IO[Unit] = { + val agreed = for { + cwd <- IO.pure(os.pwd.toString()) + _ <- IO.print(s"$cwd を ZMMプロジェクトとして初期化しますか? [y/N]?>") + ynString <- IO.readLine + } yield ynString == "y" + + val placeXml: IO[Unit] = IO { + os.exists(os.pwd / "script.xml") match { + case true => IO.println("script.xml は既に存在するのでスキップされました") + case false => IO(os.write(os.pwd / "script.xml", "")) + } + }.flatten + + val digArtifact: IO[Unit] = IO { + os.exists(os.pwd / "artifact") match { + case true => IO.println("artifact/ は既に存在するのでスキップされました") + case false => IO(os.makeDir(os.pwd / "artifact")) + } + }.flatten + + val digAssets: IO[Unit] = IO { + os.exists(os.pwd / "assets") match { + case true => IO.println("assets/ は既に存在するのでスキップされました") + case false => IO(os.makeDir(os.pwd / "assets")) + } + }.flatten + + val digAssetsHtml: IO[Unit] = IO { + os.exists(os.pwd / "assets" / "html") match { + case true => IO.println("assets/html/ は既に存在するのでスキップされました") + case false => IO(os.makeDir(os.pwd / "assets" / "html")) + } + }.flatten + + val init = for { + _ <- placeXml + _ <- digArtifact + _ <- digAssets + } yield () + + // ZMMプロジェクトを構成するいくつかのファイル/ディレクトリについて、存在しなかったらテンプレートをもとに作成する、を繰り返す + agreed flatMap { + case true => init + case false => IO.println("中断します") + } + } def generate(filePath: String): IO[Unit] = { val content = IO.delay(scala.xml.XML.loadFile(filePath)) From 3813237831a3927c32cacb924f2f2f6086344372 Mon Sep 17 00:00:00 2001 From: windymelt Date: Thu, 22 Dec 2022 21:50:57 +0900 Subject: [PATCH 06/11] =?UTF-8?q?init=E3=81=99=E3=82=8B=E3=81=A8=E3=82=B5?= =?UTF-8?q?=E3=83=B3=E3=83=97=E3=83=AB=E3=82=92=E3=83=AC=E3=83=B3=E3=83=80?= =?UTF-8?q?=E3=83=BC=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E3=81=97?= =?UTF-8?q?=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scala/com/github/windymelt/zmm/Cli.scala | 2 +- src/main/twirl/script.scala.xml | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/main/twirl/script.scala.xml diff --git a/src/main/scala/com/github/windymelt/zmm/Cli.scala b/src/main/scala/com/github/windymelt/zmm/Cli.scala index b8c46be..19d418b 100644 --- a/src/main/scala/com/github/windymelt/zmm/Cli.scala +++ b/src/main/scala/com/github/windymelt/zmm/Cli.scala @@ -60,7 +60,7 @@ final class Cli val placeXml: IO[Unit] = IO { os.exists(os.pwd / "script.xml") match { case true => IO.println("script.xml は既に存在するのでスキップされました") - case false => IO(os.write(os.pwd / "script.xml", "")) + case false => IO(os.write(os.pwd / "script.xml", xml.script().body)) } }.flatten diff --git a/src/main/twirl/script.scala.xml b/src/main/twirl/script.scala.xml new file mode 100644 index 0000000..23c0e0b --- /dev/null +++ b/src/main/twirl/script.scala.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + zmm + + + + + + こんにちは、四国めたんです + こんにちは、ずんだもんなのだ + + + From 26ce08ffb5bdbd597b52741032cf566358246e78 Mon Sep 17 00:00:00 2001 From: windymelt Date: Thu, 22 Dec 2022 21:53:29 +0900 Subject: [PATCH 07/11] =?UTF-8?q?=E5=85=AC=E5=BC=8F=E3=83=9A=E3=83=BC?= =?UTF-8?q?=E3=82=B8=E3=81=AB=E8=AA=98=E5=B0=8E=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/scala/com/github/windymelt/zmm/Main.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scala/com/github/windymelt/zmm/Main.scala b/src/main/scala/com/github/windymelt/zmm/Main.scala index 1f99635..19073c1 100644 --- a/src/main/scala/com/github/windymelt/zmm/Main.scala +++ b/src/main/scala/com/github/windymelt/zmm/Main.scala @@ -10,7 +10,7 @@ import com.monovore.decline.effect.CommandIOApp object Main extends CommandIOApp( name = "zmm", - header = "Zunda Movie Maker", + header = "Zunda Movie Maker -- see https://www.3qe.us/zmm/doc/ for more documentation", version = BuildInfo.version, ) { override def main: Opts[IO[ExitCode]] = CliOptions.opts map { o => From dc24f21e78f9ddce724e97e2ace2d2f92f9ad15a Mon Sep 17 00:00:00 2001 From: windymelt Date: Thu, 22 Dec 2022 22:07:26 +0900 Subject: [PATCH 08/11] =?UTF-8?q?=E3=82=AA=E3=83=BC=E3=83=9F=E3=82=B9?= =?UTF-8?q?=E3=83=86=E3=82=A4=E3=82=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scala/com/github/windymelt/zmm/Cli.scala | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/scala/com/github/windymelt/zmm/Cli.scala b/src/main/scala/com/github/windymelt/zmm/Cli.scala index 19d418b..b076e2a 100644 --- a/src/main/scala/com/github/windymelt/zmm/Cli.scala +++ b/src/main/scala/com/github/windymelt/zmm/Cli.scala @@ -65,9 +65,16 @@ final class Cli }.flatten val digArtifact: IO[Unit] = IO { - os.exists(os.pwd / "artifact") match { - case true => IO.println("artifact/ は既に存在するのでスキップされました") - case false => IO(os.makeDir(os.pwd / "artifact")) + os.exists(os.pwd / "artifacts") match { + case true => IO.println("artifacts/ は既に存在するのでスキップされました") + case false => IO(os.makeDir(os.pwd / "artifacts")) + } + }.flatten + + val digArtifactsHtml: IO[Unit] = IO { + os.exists(os.pwd / "artifacts" / "html") match { + case true => IO.println("artifacts/html/ は既に存在するのでスキップされました") + case false => IO(os.makeDir(os.pwd / "artifacts" / "html")) } }.flatten @@ -78,16 +85,9 @@ final class Cli } }.flatten - val digAssetsHtml: IO[Unit] = IO { - os.exists(os.pwd / "assets" / "html") match { - case true => IO.println("assets/html/ は既に存在するのでスキップされました") - case false => IO(os.makeDir(os.pwd / "assets" / "html")) - } - }.flatten - val init = for { _ <- placeXml - _ <- digArtifact + _ <- digArtifact >> digArtifactsHtml _ <- digAssets } yield () From feb75cc427adce0c582a470a5a81d18b154f15be Mon Sep 17 00:00:00 2001 From: windymelt Date: Thu, 22 Dec 2022 22:07:36 +0900 Subject: [PATCH 09/11] =?UTF-8?q?=E3=81=B2=E3=81=A8=E3=81=93=E3=81=A8?= =?UTF-8?q?=E5=A2=97=E3=82=84=E3=81=97=E3=81=A6=E3=81=8A=E3=81=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/twirl/script.scala.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/twirl/script.scala.xml b/src/main/twirl/script.scala.xml index 23c0e0b..af4e39f 100644 --- a/src/main/twirl/script.scala.xml +++ b/src/main/twirl/script.scala.xml @@ -19,6 +19,8 @@ こんにちは、四国めたんです こんにちは、ずんだもんなのだ + この原稿ファイルはzmmのサンプル原稿です + よろしくなのだ From aabdcb2033d8d462c4160f6a5e10b9bafe50afc1 Mon Sep 17 00:00:00 2001 From: windymelt Date: Thu, 22 Dec 2022 22:13:19 +0900 Subject: [PATCH 10/11] added comment --- src/main/scala/com/github/windymelt/zmm/Cli.scala | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/scala/com/github/windymelt/zmm/Cli.scala b/src/main/scala/com/github/windymelt/zmm/Cli.scala index b076e2a..cf8491c 100644 --- a/src/main/scala/com/github/windymelt/zmm/Cli.scala +++ b/src/main/scala/com/github/windymelt/zmm/Cli.scala @@ -50,6 +50,14 @@ final class Cli } yield () } + /** + * 現在のディレクトリをZMMプロジェクトとして初期化する。 + * + * 現在のディレクトリに原稿XMLファイルや生成物配置用のディレクトリを作成する。 + * 既にディレクトリやファイルが存在している場合は何もしない。 + * + * @return Unitを返す。 + */ def initializeProject(): IO[Unit] = { val agreed = for { cwd <- IO.pure(os.pwd.toString()) From fe81044e2360a8f8b5619d574ff333296bb85533 Mon Sep 17 00:00:00 2001 From: windymelt Date: Thu, 22 Dec 2022 22:14:18 +0900 Subject: [PATCH 11/11] fix name --- src/main/scala/com/github/windymelt/zmm/Cli.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/scala/com/github/windymelt/zmm/Cli.scala b/src/main/scala/com/github/windymelt/zmm/Cli.scala index cf8491c..d1fe023 100644 --- a/src/main/scala/com/github/windymelt/zmm/Cli.scala +++ b/src/main/scala/com/github/windymelt/zmm/Cli.scala @@ -72,7 +72,7 @@ final class Cli } }.flatten - val digArtifact: IO[Unit] = IO { + val digArtifacts: IO[Unit] = IO { os.exists(os.pwd / "artifacts") match { case true => IO.println("artifacts/ は既に存在するのでスキップされました") case false => IO(os.makeDir(os.pwd / "artifacts")) @@ -95,7 +95,7 @@ final class Cli val init = for { _ <- placeXml - _ <- digArtifact >> digArtifactsHtml + _ <- digArtifacts >> digArtifactsHtml _ <- digAssets } yield ()