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

issue #59, added search limit option for search #69

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -54,20 +54,21 @@ object RepositoryApi {
private val curseforgeApi = CurseforgeApi(ktorClient, ktorClientJson, cache)
private val launcherMetaApi = LauncherMetaApi(ktorClient, ktorClientJson, cache)

suspend fun RequestContext.search(searchTerm: String, repository: Repository?): List<CommonProjectResult> {
suspend fun RequestContext.search(searchTerm: String,
repository: Repository?, limit: Int): List<CommonProjectResult> {
Comment on lines +57 to +58
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put this on one line

val results = mutableListOf<CommonProjectResult>()

coroutineScope {
val modrinthRequest = async {
if (repository == null || repository == Repository.MODRINTH) {
with(modrinthApi) { searchProjects(searchTerm, limit = 8) }?.hits.orEmpty()
with(modrinthApi) { searchProjects(searchTerm, limit = limit) }?.hits.orEmpty()
.map(CommonProjectResult.Companion::fromModrinthProjectResult)
} else emptyList()
}

val curseforgeRequest = async {
if (repository == null || repository == Repository.CURSEFORGE) {
with(curseforgeApi) { searchProjects(searchTerm, pageSize = 8) }.orEmpty()
with(curseforgeApi) { searchProjects(searchTerm, pageSize = limit) }.orEmpty()
.map(CommonProjectResult.Companion::fromCurseforgeMod)
} else emptyList()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package net.axay.pacmc.cli.commands

import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.parameters.arguments.argument
import com.github.ajalt.clikt.parameters.options.option
import com.github.ajalt.clikt.parameters.options.default
import com.github.ajalt.clikt.parameters.types.int
import net.axay.pacmc.app.repoapi.repoApiContext
import net.axay.pacmc.cli.launchJob
import net.axay.pacmc.cli.terminal
Expand All @@ -13,11 +16,13 @@ class SearchCommand : CliktCommand(
help = "Search for mods",
) {
private val query by argument()
private val searchLimit by option(
"-l", "--limit", help = "Number of results to limit search to").int().default(8)
Comment on lines +19 to +20
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put this on one line


override fun run() = launchJob {
terminal.println("Searching with the given query '$query'")

val searchResults = repoApiContext(CachePolicy.ONLY_FRESH) { it.search(query, null) }
val searchResults = repoApiContext(CachePolicy.ONLY_FRESH) { it.search(query, null, searchLimit) }
terminal.println()

if (searchResults.isEmpty()) {
Expand Down