Skip to content

Commit

Permalink
Fix test compile issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jzbrooks committed Oct 5, 2024
1 parent 50668b4 commit 7994c1b
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 77 deletions.
2 changes: 1 addition & 1 deletion vgo-cli/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ tasks {
jar {
dependsOn(configurations.runtimeClasspath)
manifest {
attributes["Main-Class"] = "com.jzbrooks.vgo.cli.ApplicationKt"
attributes["Main-Class"] = "com.jzbrooks.vgo.cli.CommandLineInterface"
attributes["Bundle-Version"] = project.properties["VERSION_NAME"]
}

Expand Down
2 changes: 1 addition & 1 deletion vgo-cli/optimize.pro
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
-mergeinterfacesaggressively
-verbose

-keep class com.jzbrooks.vgo.cli.ApplicationKt {
-keep class com.jzbrooks.vgo.cli.CommandLineInterface {
public static void main(java.lang.String[]);
}
41 changes: 0 additions & 41 deletions vgo-cli/src/main/kotlin/com/jzbrooks/vgo/cli/Application.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.jzbrooks.vgo.cli

import com.jzbrooks.vgo.Vgo
import kotlin.system.exitProcess

class CommandLineInterface {
fun run(args: Array<String>): Int {
val argReader = ArgReader(args.toMutableList())

val printHelp = argReader.readFlag("help|h")
if (printHelp) {
println(HELP_MESSAGE)
return 0
}

val printVersion = argReader.readFlag("version|v")
val printStats = argReader.readFlag("stats|s")
val indent = argReader.readOption("indent")?.toIntOrNull()

val outputs =
run {
val outputPaths = mutableListOf<String>()
var output = argReader.readOption("output|o")
while (output != null) {
outputPaths.add(output)
output = argReader.readOption("output|o")
}
outputPaths.toList()
}

var format = argReader.readOption("format")

var inputs = argReader.readArguments()

val options =
Vgo.Options(
printVersion = printVersion,
printStats = printStats,
indent = indent,
output = outputs,
format = format,
input = inputs,
)

return Vgo(options).run()
}

companion object {
private val HELP_MESSAGE =
"""
> vgo [options] [file/directory]
Options:
-h --help print this message
-o --output file or directory, if not provided the input will be overwritten
-s --stats print statistics on processed files to standard out
-v --version print the version number
--indent value write files with value columns of indentation
--format value output format (svg, vd, etc)
""".trimIndent()

@JvmStatic
fun main(args: Array<String>): Unit = exitProcess(CommandLineInterface().run(args))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import assertk.assertions.doesNotContain
import assertk.assertions.isEqualTo
import assertk.assertions.matches
import assertk.assertions.startsWith
import com.jzbrooks.vgo.Vgo
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.BeforeEach
Expand Down Expand Up @@ -36,7 +35,7 @@ class CommandLineInterfaceTests {
fun testLongVersionFlag() {
val arguments = arrayOf("--version")

val exitCode = Vgo().run(arguments)
val exitCode = CommandLineInterface().run(arguments)

assertThat(exitCode).isEqualTo(0)
assertThat(systemOutput.toString()).matches(Regex("\\d+.\\d+.\\d+\r?\n"))
Expand All @@ -46,7 +45,7 @@ class CommandLineInterfaceTests {
fun testShortVersionFlag() {
val arguments = arrayOf("-v")

val exitCode = Vgo().run(arguments)
val exitCode = CommandLineInterface().run(arguments)

assertThat(exitCode).isEqualTo(0)
assertThat(systemOutput.toString()).matches(Regex("\\d+.\\d+.\\d+\r?\n"))
Expand All @@ -56,7 +55,7 @@ class CommandLineInterfaceTests {
fun testLongHelpFlag() {
val arguments = arrayOf("--help")

val exitCode = Vgo().run(arguments)
val exitCode = CommandLineInterface().run(arguments)

assertThat(exitCode).isEqualTo(0)
val output = systemOutput.toString()
Expand All @@ -68,7 +67,7 @@ class CommandLineInterfaceTests {
fun testShortHelpFlag() {
val arguments = arrayOf("-h")

val exitCode = Vgo().run(arguments)
val exitCode = CommandLineInterface().run(arguments)

assertThat(exitCode).isEqualTo(0)
val output = systemOutput.toString()
Expand All @@ -79,7 +78,7 @@ class CommandLineInterfaceTests {
@Test
fun testLongStatsFlag() {
val arguments = arrayOf(avocadoExampleRelativePath, "-o", "build/integrationTest/stats-test.xml", "--stats")
val exitCode = Vgo().run(arguments)
val exitCode = CommandLineInterface().run(arguments)
assertThat(exitCode).isEqualTo(0)
assertThat(systemOutput.toString()).contains("Percent saved:")
}
Expand All @@ -94,7 +93,7 @@ class CommandLineInterfaceTests {
"build/integrationTest/unmodified-stats-omitted.xml",
"--stats",
)
val exitCode = Vgo().run(arguments)
val exitCode = CommandLineInterface().run(arguments)
assertThat(exitCode).isEqualTo(0)
val report = systemOutput.toString()
assertThat(report).doesNotContain(input)
Expand All @@ -109,7 +108,7 @@ class CommandLineInterfaceTests {
"build/integrationTest/multi-stats-test-directory",
"--stats",
)
val exitCode = Vgo().run(arguments)
val exitCode = CommandLineInterface().run(arguments)
assertThat(exitCode).isEqualTo(0)
val report = systemOutput.toString()
assertThat(report).contains(Paths.get("src/test/resources/in-place-modify/avocado_example.xml").toString())
Expand All @@ -127,7 +126,7 @@ class CommandLineInterfaceTests {
"build/integrationTest/multi-stats-test-two.xml",
"--stats",
)
val exitCode = Vgo().run(arguments)
val exitCode = CommandLineInterface().run(arguments)
assertThat(exitCode).isEqualTo(0)
val report = systemOutput.toString()
assertThat(report).contains(avocadoExampleRelativePath)
Expand All @@ -137,7 +136,7 @@ class CommandLineInterfaceTests {
@Test
fun testShortStatsFlag() {
val arguments = arrayOf(avocadoExampleRelativePath, "-o", "build/integrationTest/stats-test.xml", "-s")
val exitCode = Vgo().run(arguments)
val exitCode = CommandLineInterface().run(arguments)
assertThat(exitCode).isEqualTo(0)
assertThat(systemOutput.toString()).contains("Percent saved:")
}
Expand All @@ -148,7 +147,7 @@ class CommandLineInterfaceTests {
File(avocadoExampleRelativePath).copyTo(overwritePath.toFile(), overwrite = true)

val arguments = arrayOf(overwritePath.toString(), "-s")
val exitCode = Vgo().run(arguments)
val exitCode = CommandLineInterface().run(arguments)

assertThat(exitCode).isEqualTo(0)
assertThat(systemOutput.toString()).contains("Percent saved:")
Expand All @@ -158,7 +157,7 @@ class CommandLineInterfaceTests {
@Test
fun testIndentOption() {
val arguments = arrayOf(avocadoExampleRelativePath, "-o", "build/integrationTest/indent-test.xml", "--indent", "4")
val exitCode = Vgo().run(arguments)
val exitCode = CommandLineInterface().run(arguments)
assertThat(exitCode).isEqualTo(0)
val output = File("build/integrationTest/indent-test.xml").readText()
assertThat(output).contains(" <path")
Expand All @@ -167,7 +166,7 @@ class CommandLineInterfaceTests {
@Test
fun testFormatOption() {
val arguments = arrayOf(avocadoExampleRelativePath, "-o", "build/integrationTest/format-test.svg", "--format", "svg")
val exitCode = Vgo().run(arguments)
val exitCode = CommandLineInterface().run(arguments)
assertThat(exitCode).isEqualTo(0)
val output = File("build/integrationTest/format-test.svg").readText()
assertThat(output).startsWith("<svg")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ open class ShrinkVectorArtwork : DefaultTask() {
fun shrink() {
val options =
Vgo.Options(
printHelp = false,
printVersion = false,
printStats = showStatistics,
indent = indent.takeIf { it > 0 }?.toInt(),
Expand Down
20 changes: 0 additions & 20 deletions vgo/src/main/kotlin/com/jzbrooks/vgo/Vgo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ class Vgo(
private var totalBytesAfter = 0.0

fun run(): Int {
if (options.printHelp) {
println(HELP_MESSAGE)
return 0
}

if (options.printVersion) {
println(BuildConstants.VERSION_NAME)
return 0
Expand Down Expand Up @@ -278,26 +273,11 @@ class Vgo(
get() = key.isDirectory && (value.isDirectory || !value.exists())

data class Options(
val printHelp: Boolean = false,
val printVersion: Boolean = false,
val printStats: Boolean = false,
val output: List<String> = emptyList(),
val input: List<String> = emptyList(),
val indent: Int? = null,
val format: String? = null,
)

companion object {
private const val HELP_MESSAGE = """
> vgo [options] [file/directory]
Options:
-h --help print this message
-o --output file or directory, if not provided the input will be overwritten
-s --stats print statistics on processed files to standard out
-v --version print the version number
--indent value write files with value columns of indentation
--format value output format (svg, vd, etc)
"""
}
}

0 comments on commit 7994c1b

Please sign in to comment.