Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prompt user for a new default archive when deleting the default #66

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -480,4 +480,7 @@ class Archive(val name: String) {
suspend fun getGameVersion(): MinecraftVersion {
return realm.findArchive().readGameVersion()
}

val isDefault: Boolean
get() = getDefault() == name
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.github.ajalt.clikt.parameters.options.required
import com.github.ajalt.colormath.model.RGBInt
import com.github.ajalt.mordant.rendering.TextColors
import com.github.ajalt.mordant.rendering.TextStyles
import io.ktor.http.content.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
Expand Down Expand Up @@ -187,6 +188,14 @@ class ArchiveCommand : CliktCommand(
}
terminal.println()

if (archive.isDefault) {
terminal.println(TextColors.yellow("You are trying to delete the default archive. To avoid issues, you have to set a new default archive"))
val newDefaultArchive = terminal.choose(
"Please provide a new default archive",
Archive.getArchivesList().filter { it.name != archive.name }.map { it to TextColors.color(RGBInt(it.color.toUInt())).invoke(it.displayName) }
) ?: return@launchJob
Archive.setDefault(newDefaultArchive.name)
}
archive.delete(keepFiles)

terminal.println("${TextColors.brightRed("Removed")} archive '$archiveName'")
Expand Down