Skip to content

Commit 08363b2

Browse files
committed
Added support for query limit
1 parent 6fe10a8 commit 08363b2

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

src/main/scala/de/upb/cs/swt/delphi/cli/Config.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package de.upb.cs.swt.delphi.cli
1818

19-
import spray.json.JsObject
20-
2119
/**
2220
* Represents a configuration for the Delphi CLI
2321
*
@@ -31,6 +29,7 @@ case class Config(server: String = sys.env.getOrElse("DELPHI_SERVER", "https://d
3129
silent: Boolean = false,
3230
mode: String = "",
3331
query : String = "",
32+
limit : Option[Int] = None,
3433
id : String = "",
3534
args: List[String] = List(),
3635
opts: List[String] = List()) {

src/main/scala/de/upb/cs/swt/delphi/cli/DelphiCLI.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ object DelphiCLI extends App {
6161
cmd("search").action((s, c) => c.copy(mode = "search"))
6262
.text("Search artifact using a query.")
6363
.children(
64-
arg[String]("query").action((x,c) => c.copy(query = x)).text("The query to be used")
64+
arg[String]("query").action((x,c) => c.copy(query = x)).text("The query to be used."),
65+
opt[Int]("limit").action((x, c) => c.copy(limit = Some(x))).text("The maximal number of results returned.")
6566
)
6667
}
6768
}

src/main/scala/de/upb/cs/swt/delphi/cli/commands/SearchCommand.scala

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ object SearchCommand extends Command with SprayJsonSupport with DefaultJsonProto
5656
val baseUri = Uri(config.server)
5757
val prettyParam = Map("pretty" -> "")
5858
val searchUri = baseUri.withPath(baseUri.path + "/search").withQuery(akka.http.scaladsl.model.Uri.Query(prettyParam))
59-
val responseFuture = Marshal(Query(query)).to[RequestEntity] flatMap { entity =>
59+
val responseFuture = Marshal(Query(query, config.limit)).to[RequestEntity] flatMap { entity =>
6060
Http().singleRequest(HttpRequest(uri = searchUri, method = HttpMethods.POST, entity = entity))
6161
}
6262

@@ -66,7 +66,7 @@ object SearchCommand extends Command with SprayJsonSupport with DefaultJsonProto
6666
entity.dataBytes.runFold(ByteString(""))(_ ++ _).map { body =>
6767
body.utf8String
6868
}
69-
case resp @ HttpResponse(code, _, _, _) => {
69+
case resp@HttpResponse(code, _, _, _) => {
7070
error(config)("Request failed, response code: " + code)
7171
resp.discardEntityBytes()
7272
Future("")
@@ -91,11 +91,25 @@ object SearchCommand extends Command with SprayJsonSupport with DefaultJsonProto
9191
}
9292

9393
val unmarshalled = Await.result(unmarshalledFuture, Duration.Inf)
94-
information(config)(s"Found ${unmarshalled.size} item(s).")
94+
val capMessage = {
95+
config.limit match {
96+
case Some(limit) if (limit <= unmarshalled.size)
97+
=> s"Results may be capped by result limit set to $limit."
98+
case None if (unmarshalled.size >= 50)
99+
=> "Results may be capped by default limit of 50 returned results. Use --limit to extend the result set."
100+
case _
101+
=> ""
102+
}
103+
}
104+
information(config)(s"Found ${unmarshalled.size} item(s). $capMessage")
95105
reportResult(config)(unmarshalled)
106+
107+
96108
information(config)(f"Query took $took%.2fs.")
97109
}
98110
}
99111

100-
case class Query(query : String, pretty : Option[Boolean] = Some(true))
112+
case class Query(query: String,
113+
limit: Option[Int] = None)
114+
101115
}

0 commit comments

Comments
 (0)