-
-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Set patch options via CLI (#336)
BREAKING CHANGE: This commit changes various CLI options and removes the `options.json` file. Instead, patch options can now be passed via CLI options
- Loading branch information
Showing
10 changed files
with
419 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
src/main/kotlin/app/revanced/cli/command/CommandUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package app.revanced.cli.command | ||
|
||
import picocli.CommandLine | ||
|
||
class OptionKeyConverter : CommandLine.ITypeConverter<String> { | ||
override fun convert(value: String): String = value | ||
} | ||
|
||
class OptionValueConverter : CommandLine.ITypeConverter<Any?> { | ||
override fun convert(value: String?): Any? { | ||
value ?: return null | ||
|
||
return when { | ||
value.startsWith("[") && value.endsWith("]") -> { | ||
val innerValue = value.substring(1, value.length - 1) | ||
|
||
buildList { | ||
var nestLevel = 0 | ||
var insideQuote = false | ||
var escaped = false | ||
|
||
val item = buildString { | ||
for (char in innerValue) { | ||
when (char) { | ||
'\\' -> { | ||
if (escaped || nestLevel != 0) { | ||
append(char) | ||
} | ||
|
||
escaped = !escaped | ||
} | ||
|
||
'"', '\'' -> { | ||
if (!escaped) { | ||
insideQuote = !insideQuote | ||
} else { | ||
escaped = false | ||
} | ||
|
||
append(char) | ||
} | ||
|
||
'[' -> { | ||
if (!insideQuote) { | ||
nestLevel++ | ||
} | ||
|
||
append(char) | ||
} | ||
|
||
']' -> { | ||
if (!insideQuote) { | ||
nestLevel-- | ||
|
||
if (nestLevel == -1) { | ||
return value | ||
} | ||
} | ||
|
||
append(char) | ||
} | ||
|
||
',' -> if (nestLevel == 0) { | ||
if (insideQuote) { | ||
append(char) | ||
} else { | ||
add(convert(toString())) | ||
setLength(0) | ||
} | ||
} else { | ||
append(char) | ||
} | ||
|
||
else -> append(char) | ||
} | ||
} | ||
} | ||
|
||
if (item.isNotEmpty()) { | ||
add(convert(item)) | ||
} | ||
} | ||
} | ||
|
||
value.startsWith("\"") && value.endsWith("\"") -> value.substring(1, value.length - 1) | ||
value.startsWith("'") && value.endsWith("'") -> value.substring(1, value.length - 1) | ||
value.endsWith("f") -> value.dropLast(1).toFloat() | ||
value.endsWith("L") -> value.dropLast(1).toLong() | ||
value.equals("true", ignoreCase = true) -> true | ||
value.equals("false", ignoreCase = true) -> false | ||
value.toIntOrNull() != null -> value.toInt() | ||
value.toLongOrNull() != null -> value.toLong() | ||
value.toDoubleOrNull() != null -> value.toDouble() | ||
value.toFloatOrNull() != null -> value.toFloat() | ||
value == "null" -> null | ||
value == "int[]" -> emptyList<Int>() | ||
value == "long[]" -> emptyList<Long>() | ||
value == "double[]" -> emptyList<Double>() | ||
value == "float[]" -> emptyList<Float>() | ||
value == "boolean[]" -> emptyList<Boolean>() | ||
value == "string[]" -> emptyList<String>() | ||
else -> value | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 0 additions & 62 deletions
62
src/main/kotlin/app/revanced/cli/command/OptionsCommand.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.