Skip to content

Commit

Permalink
lots more aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
ManApart committed Jun 30, 2024
1 parent df2e7ca commit dffc1e3
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 38 deletions.
66 changes: 33 additions & 33 deletions src/main/kotlin/commands/CommandType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,48 @@ enum class CommandType(
val apply: (List<String>) -> Unit,
vararg val aliases: String = arrayOf(),
) {
ADD("Add a new mod", Category.ADD, addModDescription, addModUsage, ::addMod),
CONFIG("Edit Configuration", Category.CONFIG, configDescription, configUsage, ::config),
CREATION("Manage Creation", Category.ADD, creationDescription, creationUsage, ::creation, "creations"),
EXTERNAL("Manage External Plugins", Category.ADD, externalModDescription, externalModUsage, ::externalMod),
ENABLE("Enable Mod", Category.DEPLOY, enableDescription, enableUsage, ::enable),
DISABLE("Disable Mod", Category.DEPLOY, enableDescription, disableUsage, ::disable),
ENDORSE("Endorse Mod", Category.EDIT, endorseDescription, endorseUsage, ::endorse),
ADD("Add a new mod", Category.ADD, addModDescription, addModUsage, ::addMod, "a"),
CONFIG("Edit Configuration", Category.CONFIG, configDescription, configUsage, ::config, "c"),
CREATION("Manage Creation", Category.ADD, creationDescription, creationUsage, ::creation, "creations", "cr"),
EXTERNAL("Manage External Plugins", Category.ADD, externalModDescription, externalModUsage, ::externalMod, "ex"),
ENABLE("Enable Mod", Category.DEPLOY, enableDescription, enableUsage, ::enable, "e"),
DISABLE("Disable Mod", Category.DEPLOY, enableDescription, disableUsage, ::disable, "x"),
ENDORSE("Endorse Mod", Category.EDIT, endorseDescription, endorseUsage, ::endorse, "en"),
ABSTAIN("Abstain from endorsing Mod", Category.EDIT, endorseDescription, "abstain <index>", ::abstain),
DEPLOY("Deploy enabled mods", Category.DEPLOY, deployDescription, deployUsage, ::deploy),
HELP("Explain commands", Category.CONFIG, helpDescription, helpUsage, ::help),
FETCH("Fetch Mod Data", Category.ADD, fetchDescription, fetchUsage, ::fetchMod),
DEPLOY("Deploy enabled mods", Category.DEPLOY, deployDescription, deployUsage, ::deploy, "d"),
HELP("Explain commands", Category.CONFIG, helpDescription, helpUsage, ::help, "h"),
FETCH("Fetch Mod Data", Category.ADD, fetchDescription, fetchUsage, ::fetchMod, "f"),
LIST("List Mods", Category.VIEW, listDescription, listUsage, ::listMods, "ls"),
DETAIL("View all details of mod", Category.VIEW, detailDescription, detailUsage, ::detailMod),
ORDER("Change Load Order", Category.DEPLOY, orderDescription, orderUsage, ::order),
DETAIL("View all details of mod", Category.VIEW, detailDescription, detailUsage, ::detailMod, "dd"),
ORDER("Change Load Order", Category.DEPLOY, orderDescription, orderUsage, ::order, "or"),
ESP("Change Load Order for plugins", Category.DEPLOY, espDescription, espUsage, ::esp, "esps"),
OPEN("Open mod on web", Category.OPEN, openDescription, "open <index>", ::open),
LOCAL("Open local mod folder", Category.OPEN, openDescription, "local <index> *<cli>", ::local),
CLI("Open local mod folder in terminal", Category.OPEN, openDescription, "cli <index>", ::cli),
GAME_PATH("Open game folder", Category.OPEN, openDescription, "", ::openGamePath, "gamepath"),
APPDATA_PATH("Open ini path folder", Category.OPEN, openDescription, "", ::openAppDataPath, "appdatapath"),
INI_PATH("Open ini path folder", Category.OPEN, openDescription, "", ::openIniPath, "inipath"),
OPEN("Open mod on web", Category.OPEN, openDescription, "open <index>", ::open, "o"),
LOCAL("Open local mod folder", Category.OPEN, openDescription, "local <index> *<cli>", ::local, "l"),
CLI("Open local mod folder in terminal", Category.OPEN, openDescription, "cli <index>", ::cli, "terminal", "term"),
GAME_PATH("Open game folder", Category.OPEN, openDescription, "", ::openGamePath, "gamepath", "gg"),
APPDATA_PATH("Open ini path folder", Category.OPEN, openDescription, "", ::openAppDataPath, "appdatapath", "app"),
INI_PATH("Open ini path folder", Category.OPEN, openDescription, "", ::openIniPath, "inipath", "ini"),
PLUGINS("Open plugins file", Category.OPEN, openDescription, "", ::openPluginsTxt, "plugin"),
JAR_PATH("Open jar path folder", Category.OPEN, openDescription, "", ::openJarPath, "jarpath"),
MANUAL("Open website manual", Category.OPEN, openDescription, "", ::openManual),
JAR_PATH("Open jar path folder", Category.OPEN, openDescription, "", ::openJarPath, "jarpath", "jar"),
MANUAL("Open website manual", Category.OPEN, openDescription, "", ::openManual, "man"),
SITE("Open website", Category.OPEN, openDescription, "", ::openSite),
SOURCE("Open app source", Category.OPEN, openDescription, "", ::openSource),
SOURCE("Open app source", Category.OPEN, openDescription, "", ::openSource, "git", "github"),
NEXUS("Open app nexus page", Category.OPEN, openDescription, "", ::openNexus),
PURGE("Purge all sym links", Category.DEPLOY, purgeDescription, purgeUsage, ::purge),
MOD("Update a mod", Category.EDIT, changeDescription, changeUsage, ::changeMod),
TAG("Edit tags on a mod", Category.EDIT, tagDescription, tagUsage, ::tag),
PROFILE("Create and use local mod lists", Category.DEPLOY, profileDescription, profileUsage, ::profile),
MOD("Update a mod", Category.EDIT, changeDescription, changeUsage, ::changeMod, "m"),
TAG("Edit tags on a mod", Category.EDIT, tagDescription, tagUsage, ::tag, "t"),
PROFILE("Create and use local mod lists", Category.DEPLOY, profileDescription, profileUsage, ::profile, "p", "prof"),
RENAME("Rename a mod", Category.EDIT, renameHelp, "rename <index> <new name>", ::moveMod, "mv"),
REFRESH("Refresh mods by id", Category.UPDATE, refreshDescription, refreshUsage, ::refresh),
UPDATE("Check for newer versions", Category.UPDATE, updateDescription, updateUsage, ::update),
VERSION("See current and new version for mod", Category.UPDATE, versionDescription, versionUsage, ::version),
UPGRADE("Upgrade to newer versions", Category.UPDATE, upgradeDescription, upgradeUsage, ::upgrade),
REFRESH("Refresh mods by id", Category.UPDATE, refreshDescription, refreshUsage, ::refresh, "rr"),
UPDATE("Check for newer versions", Category.UPDATE, updateDescription, updateUsage, ::update, "up"),
VERSION("See current and new version for mod", Category.UPDATE, versionDescription, versionUsage, ::version, "vv"),
UPGRADE("Upgrade to newer versions", Category.UPDATE, upgradeDescription, upgradeUsage, ::upgrade, "ug"),
REMOVE("Delete a mod", Category.ADD, removeHelp, removeDescription, ::remove, "rm"),
SEARCH("Search Mods", Category.VIEW, searchDescription, searchModsUsage, ::searchMods, "grep", "awk"),
FIND("Find file", Category.VIEW, findDescription, findUsage, ::find),
FILTER("Apply a filter to Mods", Category.VIEW, filterDescription, filterUsage, ::filterMods),
SORT("Sort Mods", Category.VIEW, sortDescription, sortUsage, ::sortMods),
VALIDATE("List issues with mods", Category.DEPLOY, validateDescription, validateUsage, ::validateMods),
FIND("Find file", Category.VIEW, findDescription, findUsage, ::find, "ff"),
FILTER("Apply a filter to Mods", Category.VIEW, filterDescription, filterUsage, ::filterMods, "fl"),
SORT("Sort Mods", Category.VIEW, sortDescription, sortUsage, ::sortMods, "s"),
VALIDATE("List issues with mods", Category.DEPLOY, validateDescription, validateUsage, ::validateMods, "v"),
START("Launch Starfield", Category.CONFIG, startGameDescription, startGameUsage, ::startGame, "game"),
EXIT(
"Exit Program", Category.CONFIG,
Expand All @@ -67,4 +67,4 @@ enum class CommandType(
fun getCommand(commandString: String) =
CommandType.entries.firstOrNull {
commandString == it.cleanName || it.aliases.contains(commandString)
}
}
14 changes: 9 additions & 5 deletions src/main/kotlin/commands/Help.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ fun help(args: List<String> = listOf()) {
args.isEmpty() -> printGeneralHelp()
args.first() == "all" -> printDetailedHelp()
helpCommand != null -> {
println(helpCommand.description)
println("Aliases: " + helpCommand.aliases.joinToString(", ") + "\n")
println(helpCommand.description + "\n")
println(helpCommand.usage)
}

else -> printGeneralHelp()
}
}
Expand All @@ -30,12 +32,14 @@ private fun printGeneralHelp() {
.forEach { (category, commands) ->
println(cyan(category.name.lowercase().capitalize()))
val columns = listOf(
Column("Command", 10),
Column("Command", 15),
Column("Aliases", 20),
Column("Summary", 30),
)
val data = commands.map {
mapOf(
"Command" to it.cleanName,
"Aliases" to it.aliases.joinToString(", "),
"Summary" to it.summary,
)
}
Expand All @@ -45,9 +49,9 @@ private fun printGeneralHelp() {
}

private fun printDetailedHelp() {
println(CommandType.entries.filterNot { it == CommandType.HELP }.joinToString("\n") {
println(CommandType.entries.filterNot { it == CommandType.HELP }.joinToString("\n\n") {
val descriptionString = it.description.replace("\n", "\n\t")
val usageString = it.usage.replace("\n", "\n\t")
"${cyan(it.cleanName)}: ${it.summary}\n\t$descriptionString\n\t$usageString"
"${cyan(it.cleanName)}: ${it.summary}\n\t$descriptionString\n\n\t$usageString"
})
}
}
14 changes: 14 additions & 0 deletions src/test/kotlin/CommandTypeTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import commands.CommandType
import kotlin.test.Test
import kotlin.test.fail

class CommandTypeTest {

@Test
fun uniqueAliases() {
val commands = (CommandType.entries.flatMap { it.aliases.toList() } + CommandType.entries.map { it.cleanName }).groupBy { it }.filter { it.value.size > 1 }
if (commands.isNotEmpty()) {
fail("The following commands or aliases are duplicated: ${commands.keys}")
}
}
}

0 comments on commit dffc1e3

Please sign in to comment.