Skip to content

Commit

Permalink
fix: Create options if it does not exist when updating them
Browse files Browse the repository at this point in the history
Previously, the file could not be read to be updated. If the file does not exist, simply serialize the options to the file.
  • Loading branch information
oSumAtrIX committed Sep 3, 2023
1 parent 5d50d1a commit ca809f0
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/main/kotlin/app/revanced/cli/command/OptionsCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal object OptionsCommand : Runnable {
@CommandLine.Option(
names = ["-p", "--path"], description = ["Path to patch options JSON file"], showDefaultValue = ALWAYS
)
private var path: File = File("options.json")
private var filePath: File = File("options.json")

@CommandLine.Option(
names = ["-o", "--overwrite"], description = ["Overwrite existing options file"], showDefaultValue = ALWAYS
Expand All @@ -37,10 +37,10 @@ internal object OptionsCommand : Runnable {
)
private var update: Boolean = false

override fun run() = if (!path.exists() || overwrite) with(PatchBundleLoader.Jar(*patchBundles)) {
if (update) setOptions(path)
override fun run() = if (!filePath.exists() || overwrite) with(PatchBundleLoader.Jar(*patchBundles)) {
if (update && filePath.exists()) setOptions(filePath)

Options.serialize(this, prettyPrint = true).let(path::writeText)
Options.serialize(this, prettyPrint = true).let(filePath::writeText)
}
else logger.severe("Options file already exists, use --override to override it")
}

0 comments on commit ca809f0

Please sign in to comment.