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

Mark command #42

Draft
wants to merge 16 commits into
base: development
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions src/cmd/add.nim
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ proc addDependencies(manifest: var Manifest, file: ManifestFile,
metadata = initManifestMetadata(
name = cfMod.name,
explicit = false,
installOn = "both",
dependencies = cfModFile.dependencies
)

Expand Down Expand Up @@ -118,6 +119,7 @@ proc paxAdd*(input: string, noDepends: bool, strategy: string): void =
metadata = initManifestMetadata(
name = cfMod.name,
explicit = true,
installOn = "both",
dependencies = cfModFile.dependencies
)
)
Expand Down
67 changes: 67 additions & 0 deletions src/cmd/mark.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import asyncdispatch, asyncfutures, strutils, terminal, options, os
import common
import ../api/cf
import ../cli/term, ../cli/prompt
import ../modpack/files, ../modpack/install
import ../util/flow

proc paxMark*(name: string, mark: string): void =
const possibleMarks = @["server","client","both","explicit","implicit"]
if not possibleMarks.contains(mark):
echoError "mark must be one of:"
for possible in possibleMarks:
echo possible
quit(1)


## mark a mod
requirePaxProject()

var manifest = readManifestFromDisk()

let cfMods = waitFor(fetchModsByQuery(name))

echoDebug "Locating mod.."
let cfModOption = manifest.promptModChoice(cfMods, selectInstalled = true)
if cfModOption.isNone:
echoError "No installed mods found for your search."
quit(1)
let cfMod = cfModOption.get()

echo ""
echoRoot "SELECTED MOD".dim
echoMod(cfMod, moreInfo = false)
echo ""

returnIfNot promptYN(("Are you sure you want to mark this mod as " & mark), default = true)

var createdMetadata: ManifestMetadata
let currentFileData = manifest.getFile(cfMod.projectId)

if @["explicit","implicit"].contains(mark):
createdMetadata = initManifestMetadata(
name = cfMod.name,
explicit = (mark == "explicit"),
installOn = currentFileData.metadata.installOn,
dependencies = currentFileData.metadata.dependencies
)
else:
createdMetadata = initManifestMetadata(
name = cfMod.name,
explicit = currentFileData.metadata.explicit,
installOn = mark,
dependencies = currentFileData.metadata.dependencies
)

let modToInstall = initManifestFile(
projectId = cfMod.projectId,
fileId = currentFileData.fileId,
metadata = createdMetadata
)
discard manifest.removeMod(cfMod.projectId)
manifest.installMod(modToInstall)

echoInfo "Marked ", cfMod.name.cyanFg, " as ", mark
# manifest.updateMod(cfMod.projectId, cfModFile.get().fileId)

manifest.writeToDisk()
7 changes: 6 additions & 1 deletion src/modpack/files.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type
## Metadata for a given project in a manifest.json
name*: string
explicit*: bool
installOn*: string
dependencies*: seq[int]

ManifestFile* = object
Expand Down Expand Up @@ -45,10 +46,11 @@ const
manifestFile* = joinPath(packFolder, "manifest.json")
outputFolder* = joinPath(projectFolder, ".out/")

proc initManifestMetadata*(name: string, explicit: bool, dependencies: seq[int]): ManifestMetadata =
proc initManifestMetadata*(name: string, explicit: bool, installOn: string, dependencies: seq[int]): ManifestMetadata =
## create a new manifest metadata object.
result.name = name
result.explicit = explicit
result.installOn = installOn
result.dependencies = dependencies

proc initManifestFile*(projectId: int, fileId: int, metadata: ManifestMetadata): ManifestFile =
Expand All @@ -66,9 +68,11 @@ converter toManifestFile(json: JsonNode): ManifestFile =
let cfModFile = waitFor(fetchModFile(json["projectID"].getInt(), json["fileID"].getInt()))
result.metadata.name = cfMod.name
result.metadata.explicit = true
result.metadata.installOn = "both"
result.metadata.dependencies = cfModFile.dependencies
else:
result.metadata.name = json["__meta"]["name"].getStr()
result.metadata.installOn = json["__meta"]["installOn"].getStr()
result.metadata.explicit = json["__meta"]["explicit"].getBool()
result.metadata.dependencies = json["__meta"]["dependencies"].getElems().map((x) => x.getInt())

Expand All @@ -81,6 +85,7 @@ converter toJson(file: ManifestFile): JsonNode {.used.} =
"__meta": {
"name": file.metadata.name,
"explicit": file.metadata.explicit,
"installOn": file.metadata.installOn,
"dependencies": file.metadata.dependencies
}
}
Expand Down
14 changes: 13 additions & 1 deletion src/pax.nim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import therapist
import cli/clr, cli/prompt
import cmd/add, cmd/expo, cmd/impo, cmd/init, cmd/list, cmd/remove, cmd/update,
cmd/upgrade, cmd/version
cmd/upgrade, cmd/version, cmd/mark

let commonArgs = (
strategy: newStringArg(@["-s", "--strategy"], choices = @["recommended",
Expand Down Expand Up @@ -49,6 +49,15 @@ let removeCmd = (
help: newHelpArg()
)

let markCmd = (
name: newStringArg(@["<name>"], help = "name of the mod to mark"),
mark: newStringArg(@["<mark>"], help = "marking"),
strategy: commonArgs.strategy,
yes: commonArgs.yes,
noColor: commonArgs.noColor,
help: newHelpArg()
)

let updateCmd = (
name: newStringArg(@["<name>"], help = "name of the mod to update"),
strategy: commonArgs.strategy,
Expand Down Expand Up @@ -96,6 +105,7 @@ let spec = (
add: newCommandArg(@["add"], addCmd, help = "add a new mod to the modpack"),
remove: newCommandArg(@["remove"], removeCmd,
help = "remove a mod from the modpack"),
mark: newCommandArg(@["mark"], markCmd, help = "mark a specific mod"),
update: newCommandArg(@["update"], updateCmd, help = "update a specific mod"),
upgrade: newCommandArg(@["upgrade"], upgradeCmd, help = "upgrade ALL mods"),
version: newCommandArg(@["version"], versionCmd,
Expand Down Expand Up @@ -126,6 +136,8 @@ elif spec.add.seen:
strategy = addCmd.strategy.value)
elif spec.remove.seen:
paxRemove(name = removeCmd.name.value, strategy = removeCmd.strategy.value)
elif spec.mark.seen:
paxMark(name = markCmd.name.value, mark = markCmd.mark.value)
elif spec.update.seen:
paxUpdate(name = updateCmd.name.value, strategy = updateCmd.strategy.value)
elif spec.upgrade.seen:
Expand Down
1 change: 1 addition & 0 deletions tests/modpack/tfiles.nim
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ block: # manifest mods
initManifestMetadata(
name = "test",
explicit = true,
installOn = "both",
dependencies = @[]
)
)
Expand Down