Skip to content

Commit

Permalink
better help
Browse files Browse the repository at this point in the history
  • Loading branch information
ManApart committed Nov 4, 2023
1 parent 1b9be52 commit d5d0218
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 37 deletions.
2 changes: 1 addition & 1 deletion manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Command | Description | Aliases | Usage
add |Add a new mod | |add nexus nxm://starfield/mods/4183/files/12955?key=abc&expires=1697023374&user_id=111 <br/>add https://www.nexusmods.com/starfield/mods/4183?tab=files <br/>add 4183 <br/>add 4183 4182 4181 - Add multiple by id <br/>add <path-to-mod-zip> <name-of-mod>*
config |Edit Configuration | |config game-path <path-to-folder> - Sets the path to the folder under steam containing the starfield Data folder and exe <br/>config ini-path <path-to-folder> - Sets the path to the folder under your documents that contains StarfieldCustom.ini and eventually Plugins.txt. Needed for updating mod load order <br/>config api-key <key-from-nexus> <br/>config verbose <true/false> - get additional output (for debugging) <br/>config use-my-docs <true/false> - deploy mod files under Data to my documents instead of the game folder. (Defaults to false) <br/>config categories - download category names from nexus <br/>If your paths have spaces, make sure to quote them
enable |Enable Mod | |enable <mod index> <br/>disable <mod index> <br/>enable 1 2 4 <br/>enable 1-4 <br/>disable all
disable |Enable Mod | |enable <mod index> <br/>disable <mod index> <br/>enable 1 2 4 <br/>enable 1-4 <br/>disable all
disable |Disable Mod | |enable <mod index> <br/>disable <mod index> <br/>enable 1 2 4 <br/>enable 1-4 <br/>disable all
endorse |Endorse Mod | |endorse <mod index> - endorse a mod on nexus <br/>abstain <mod index> <br/>endorse 1 2 4 <br/>endorse 1-4
abstain |Abstain from endorsing Mod | |endorse <mod index> - endorse a mod on nexus <br/>abstain <mod index> <br/>endorse 1 2 4 <br/>endorse 1-4
deploy |Deploy enabled mods | |deploy - Applies all mods to the game folder by creating the appropriate symlinks <br/>deploy dryrun - Per your load order view how files will be deployed
Expand Down
7 changes: 5 additions & 2 deletions src/main/kotlin/TablePrinter.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import io.ktor.client.utils.EmptyContent.headers

fun String?.truncate(length: Int = 6): String {
return this?.substring(0, kotlin.math.min(this.length, length)) ?: ""
}

data class Table(val columns: List<Column>, val data: List<Map<String, Any>>) {
fun print() {
fun print(highlightHeaders: Boolean = true) {
val colFormat = columns.joinToString("") { "%-${it.size}s" }
val rowFormat = columns.joinToString("") {
val type = if (it.isNumber) "d" else "s"
"%-${it.size}$type"
}

val headerValues = columns.map { it.header }.toTypedArray()
System.out.printf(cyan("$colFormat\n"), *headerValues)
val headers = if (highlightHeaders) cyan("$colFormat\n") else "$colFormat\n"
System.out.printf(headers, *headerValues)
data.forEach { row ->
val dataValues = columns.map { row[it.header] ?: "" }.toTypedArray()
System.out.printf("$rowFormat\n", *dataValues)
Expand Down
65 changes: 34 additions & 31 deletions src/main/kotlin/commands/CommandType.kt
Original file line number Diff line number Diff line change
@@ -1,43 +1,46 @@
package commands

enum class Category { ADD, DEPLOY, VIEW, EDIT, OPEN, UPDATE, CONFIG }

enum class CommandType(
val description: String,
val category: Category,
val help: () -> String,
val apply: (List<String>) -> Unit,
vararg val aliases: String = arrayOf(),
) {
ADD("Add a new mod", ::addModHelp, ::addMod),
CONFIG("Edit Configuration", ::configHelp, ::config),
ENABLE("Enable Mod", ::enableHelp, ::enable),
DISABLE("Enable Mod", ::enableHelp, ::disable),
ENDORSE("Endorse Mod", ::endorseHelp, ::endorse),
ABSTAIN("Abstain from endorsing Mod", ::endorseHelp, ::abstain),
DEPLOY("Deploy enabled mods", ::deployHelp, ::deploy),
HELP("Explain commands", ::helpHelp, ::help),
FETCH("Fetch Mod Data", ::fetchHelp, ::fetchMod),
LIST("List Mods", ::listHelp, ::listMods, "ls"),
DETAIL("View all details of mod", ::detailHelp, ::detailMod),
ORDER("Change Load Order", ::orderHelp, ::order),
OPEN("Open mod on web", ::openHelp, ::open),
LOCAL("Open local mod folder", ::openHelp, ::local),
GAME_PATH("Open game folder", ::openHelp, ::openGamePath, "gamepath"),
INI_PATH("Open ini path folder", ::openHelp, ::openIniPath, "inipath"),
JAR_PATH("Open jar path folder", ::openHelp, ::openJarPath, "jarpath"),
PURGE("Purge all sym links", ::purgeHelp, ::purge),
MOD("Update a mod", ::changeHelp, ::changeMod),
PROFILE("Create and use local mod lists", ::profileHelp, ::profile),
RENAME("Rename a mod", ::changeHelp, ::moveMod, "mv"),
REFRESH("Refresh mods by id", ::refreshHelp, ::refresh),
UPDATE("Check for newer versions", ::updateHelp, ::update),
UPGRADE("Upgrade to newer versions", ::upgradeHelp, ::upgrade),
REMOVE("Delete a mod", ::removeHelp, ::remove, "rm"),
SEARCH("Search Mods", ::searchHelp, ::searchMods, "grep", "awk"),
FILTER("Apply a filter to Mods", ::filterHelp, ::filterMods),
SORT("Sort Mods", ::sortHelp, ::sortMods),
VALIDATE("List issues with mods", ::validateHelp, ::validateMods),
START("Launch Starfield", ::startGameHelp, ::startGame, "game"),
ADD("Add a new mod", Category.ADD, ::addModHelp, ::addMod),
CONFIG("Edit Configuration", Category.CONFIG, ::configHelp, ::config),
ENABLE("Enable Mod", Category.DEPLOY, ::enableHelp, ::enable),
DISABLE("Disable Mod", Category.DEPLOY, ::enableHelp, ::disable),
ENDORSE("Endorse Mod", Category.EDIT, ::endorseHelp, ::endorse),
ABSTAIN("Abstain from endorsing Mod", Category.EDIT, ::endorseHelp, ::abstain),
DEPLOY("Deploy enabled mods", Category.DEPLOY, ::deployHelp, ::deploy),
HELP("Explain commands", Category.CONFIG, ::helpHelp, ::help),
FETCH("Fetch Mod Data", Category.ADD, ::fetchHelp, ::fetchMod),
LIST("List Mods", Category.VIEW, ::listHelp, ::listMods, "ls"),
DETAIL("View all details of mod", Category.VIEW, ::detailHelp, ::detailMod),
ORDER("Change Load Order", Category.DEPLOY, ::orderHelp, ::order),
OPEN("Open mod on web", Category.OPEN, ::openHelp, ::open),
LOCAL("Open local mod folder", Category.OPEN, ::openHelp, ::local),
GAME_PATH("Open game folder", Category.OPEN, ::openHelp, ::openGamePath, "gamepath"),
INI_PATH("Open ini path folder", Category.OPEN, ::openHelp, ::openIniPath, "inipath"),
JAR_PATH("Open jar path folder", Category.OPEN, ::openHelp, ::openJarPath, "jarpath"),
PURGE("Purge all sym links", Category.DEPLOY, ::purgeHelp, ::purge),
MOD("Update a mod", Category.EDIT, ::changeHelp, ::changeMod),
PROFILE("Create and use local mod lists", Category.DEPLOY, ::profileHelp, ::profile),
RENAME("Rename a mod", Category.EDIT, ::changeHelp, ::moveMod, "mv"),
REFRESH("Refresh mods by id", Category.UPDATE, ::refreshHelp, ::refresh),
UPDATE("Check for newer versions", Category.UPDATE, ::updateHelp, ::update),
UPGRADE("Upgrade to newer versions", Category.UPDATE, ::upgradeHelp, ::upgrade),
REMOVE("Delete a mod", Category.ADD, ::removeHelp, ::remove, "rm"),
SEARCH("Search Mods", Category.VIEW, ::searchHelp, ::searchMods, "grep", "awk"),
FILTER("Apply a filter to Mods", Category.VIEW, ::filterHelp, ::filterMods),
SORT("Sort Mods", Category.VIEW, ::sortHelp, ::sortMods),
VALIDATE("List issues with mods", Category.DEPLOY, ::validateHelp, ::validateMods),
START("Launch Starfield", Category.CONFIG, ::startGameHelp, ::startGame, "game"),
EXIT(
"Exit Program",
"Exit Program", Category.CONFIG,
{ "Exit the process" },
{ kotlin.system.exitProcess(0) }
),
Expand Down
25 changes: 22 additions & 3 deletions src/main/kotlin/commands/Help.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package commands

import Column
import Table
import cyan

fun helpHelp() = ""
fun help(args: List<String> = listOf()) {
val helpCommand = args.firstOrNull()?.let { getCommand(it) }
Expand All @@ -12,9 +16,24 @@ fun help(args: List<String> = listOf()) {
}

private fun printGeneralHelp() {
println(CommandType.entries.filterNot { it == CommandType.HELP }.joinToString("\n") {
"${it.cleanName}\n\t${it.description}"
})
CommandType.entries
.filterNot { it == CommandType.HELP }
.groupBy { it.category }.entries
.forEach { (category, commands) ->
println(cyan(category.name.lowercase().capitalize()))
val columns = listOf(
Column("Command", 10),
Column("Summary", 30),
)
val data = commands.map {
mapOf(
"Command" to it.cleanName,
"Summary" to it.description,
)
}
Table(columns, data).print(false)
println()
}
}

private fun printDetailedHelp() {
Expand Down

0 comments on commit d5d0218

Please sign in to comment.