Skip to content

Commit 4685d61

Browse files
author
Johannes Düsing
committed
Better progress output while downloading
1 parent 0a7b5c7 commit 4685d61

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import org.joda.time.DateTime
2424
import org.joda.time.format.DateTimeFormat
2525
import spray.json._
2626

27-
import de.upb.cs.swt.delphi.cli.artifacts.SearchResultJson.searchResultFormat
2827
import de.upb.cs.swt.delphi.cli.artifacts.StorageMetadataJson.queryStorageMetadataFormat
2928

3029
class FileOutput (serverVersion: String = "UNKNOWN")(implicit config:Config, backend: SttpBackend[Id, Nothing]){
@@ -41,22 +40,29 @@ class FileOutput (serverVersion: String = "UNKNOWN")(implicit config:Config, ba
4140
writer.close()
4241

4342
val outputMode = config.outputMode.getOrElse(OutputMode.PomOnly)
43+
var progressCnt = 0f
4444

4545
info()
4646
info(f"Output Mode is ${outputMode.toString}, destination is ${folderPath.toString}")
47+
info()
48+
print("Downloading files: 00 %")
4749

4850
results
4951
.map(r => r.toMavenRelativeUrl() + s"/${r.metadata.artifactId}-${r.metadata.version}")
5052
.map(relUrl => "https://repo1.maven.org/maven2/" + relUrl).foreach( urlWithoutExtension => {
5153

54+
print("\b\b\b\b")
55+
val progressValue = (100f * progressCnt ).toInt / results.size
56+
print(s"${if (progressValue < 10) f"0$progressValue" else progressValue} %")
57+
progressCnt += 1
58+
5259
var artifactsToRetrieve = Seq[String]()
5360
if (outputMode == OutputMode.PomOnly || outputMode == OutputMode.All){
5461
artifactsToRetrieve = artifactsToRetrieve ++ Seq(s"$urlWithoutExtension.pom")
5562
}
5663
if(outputMode == OutputMode.JarOnly || outputMode == OutputMode.All){
5764
artifactsToRetrieve = artifactsToRetrieve ++ Seq(s"$urlWithoutExtension.jar")
5865
}
59-
6066
artifactsToRetrieve.foreach( url => {
6167
sttp.get(uri"$url").response(asByteArray).send().body match {
6268
case Right(value) =>
@@ -66,9 +72,10 @@ class FileOutput (serverVersion: String = "UNKNOWN")(implicit config:Config, ba
6672
error(f"Failed to download artifact from $url, got: $value")
6773
}
6874
})
69-
7075
})
71-
76+
print("\b\b\b\b100 %")
77+
info()
78+
info()
7279
info(f"Successfully wrote results to $folderPath.")
7380
}
7481

0 commit comments

Comments
 (0)