mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IJPL-250718 [platform]: refactoring command line arguments handling to avoid future regressions
(cherry picked from commit f0675d8f124d5ef4c868bb924aa1f2392109cd2e) IJ-CR-214513 GitOrigin-RevId: 26695ae659b3a492b2d1fe2b68fc35023fabc38d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
46de1f6ea2
commit
b2e5bb9586
@@ -9,6 +9,7 @@ import com.intellij.concurrency.IdeaForkJoinWorkerThreadFactory
|
||||
import com.intellij.diagnostic.CoroutineTracerShim
|
||||
import com.intellij.diagnostic.StartUpMeasurer
|
||||
import com.intellij.ide.BootstrapBundle
|
||||
import com.intellij.ide.CommandLineProcessor
|
||||
import com.intellij.ide.plugins.PluginManagerCore
|
||||
import com.intellij.ide.plugins.PluginModuleDescriptor
|
||||
import com.intellij.ide.startup.StartupActionScriptManager
|
||||
@@ -310,7 +311,7 @@ private fun preprocessArgs(rawArgs: Array<String>): List<String> {
|
||||
printVersion()
|
||||
exitProcess(0)
|
||||
}
|
||||
firstArg != null && firstArg.startsWith('-') && firstArg !in setOf("--temp-project", "--wait", "--line", "--column") -> {
|
||||
firstArg != null && firstArg.startsWith('-') && !CommandLineProcessor.isSupportedOption(firstArg) -> {
|
||||
println("unrecognized option: ${firstArg}")
|
||||
exitProcess(1)
|
||||
}
|
||||
|
||||
@@ -63,7 +63,13 @@ import java.util.concurrent.CancellationException
|
||||
|
||||
object CommandLineProcessor {
|
||||
private val LOG = logger<CommandLineProcessor>()
|
||||
|
||||
private const val OPTION_WAIT = "--wait"
|
||||
private const val OPTION_EDIT = "--edit"
|
||||
private const val OPTION_LINE = "--line"
|
||||
private const val OPTION_COLUMN = "--column"
|
||||
private const val OPTION_TEMP_PROJECT = "--temp-project"
|
||||
private const val OPTION_PROJECT = "--project"
|
||||
|
||||
@JvmField
|
||||
val OK_FUTURE: Deferred<CliResult> = CompletableDeferred(value = CliResult.OK)
|
||||
@@ -396,6 +402,12 @@ object CommandLineProcessor {
|
||||
return result ?: error("Parsing result shouldn't be null at this point; args are not empty")
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
fun isSupportedOption(option: String): Boolean = option in setOf(
|
||||
OPTION_WAIT, OPTION_LINE, "-l", OPTION_COLUMN, "-c", OPTION_TEMP_PROJECT, OPTION_EDIT, "-e", OPTION_PROJECT, "-p"
|
||||
)
|
||||
|
||||
// on any change, please update `isSupportedOption` accordingly
|
||||
private fun parseArgs(args: List<String>, currentDirectory: String?): Result<List<ParsingResult>> {
|
||||
val openProjectResults = mutableListOf<OpenProjectResult>()
|
||||
var line = -1
|
||||
@@ -410,31 +422,31 @@ object CommandLineProcessor {
|
||||
i++
|
||||
continue
|
||||
}
|
||||
if (arg == "-l" || arg == "--line") {
|
||||
if (arg == OPTION_LINE || arg == "-l") {
|
||||
i++
|
||||
if (i == args.size) break
|
||||
line = args[i].toIntOrNull() ?: -1
|
||||
i++
|
||||
continue
|
||||
}
|
||||
if (arg == "-c" || arg == "--column") {
|
||||
if (arg == OPTION_COLUMN || arg == "-c") {
|
||||
i++
|
||||
if (i == args.size) break
|
||||
column = args[i].toIntOrNull() ?: -1
|
||||
i++
|
||||
continue
|
||||
}
|
||||
if (arg == "--temp-project") {
|
||||
if (arg == OPTION_TEMP_PROJECT) {
|
||||
tempProject = true
|
||||
i++
|
||||
continue
|
||||
}
|
||||
if (arg == "-e" || arg == "--edit") {
|
||||
if (arg == OPTION_EDIT || arg == "-e") {
|
||||
lightEditMode = true
|
||||
i++
|
||||
continue
|
||||
}
|
||||
if (arg == "-p" || arg == "--project") {
|
||||
if (arg == OPTION_PROJECT || arg == "-p") {
|
||||
tempProject = false
|
||||
i++
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user