-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from delphi-hub/develop
Alpha Release
- Loading branch information
Showing
13 changed files
with
590 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
scalaVersion := "2.12.4" | ||
|
||
name := "delphi-cli" | ||
name := "delphi" | ||
version := "1.0.0-SNAPSHOT" | ||
maintainer := "Ben Hermann <[email protected]>" | ||
|
||
|
@@ -13,11 +13,21 @@ wixProductUpgradeId := "4552fb0e-e257-4dbd-9ecb-dba9dbacf424" | |
|
||
scalastyleConfig := baseDirectory.value / "project" / "scalastyle_config.xml" | ||
|
||
libraryDependencies += "com.github.scopt" %% "scopt" % "3.7.0" | ||
val akkaVersion = "2.5.14" | ||
val akkaHttpVersion = "10.1.5" | ||
|
||
libraryDependencies ++= Seq( | ||
"com.typesafe.akka" %% "akka-http-core" % "10.0.11" | ||
"com.typesafe.akka" %% "akka-http-core" % akkaHttpVersion, | ||
"com.typesafe.akka" %% "akka-http-spray-json" % akkaHttpVersion, | ||
"com.typesafe.akka" %% "akka-stream" % akkaVersion | ||
) | ||
|
||
libraryDependencies += "com.github.scopt" %% "scopt" % "3.7.0" | ||
libraryDependencies += "io.spray" %% "spray-json" % "1.3.3" | ||
libraryDependencies += "de.vandermeer" % "asciitable" % "0.3.2" | ||
libraryDependencies += "com.lihaoyi" %% "fansi" % "0.2.5" | ||
libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value | ||
|
||
debianPackageDependencies := Seq("java8-runtime-headless") | ||
|
||
lazy val cli = (project in file(".")). | ||
|
@@ -34,3 +44,4 @@ lazy val cli = (project in file(".")). | |
) | ||
scalastyleConfig := baseDirectory.value / "project" / "scalastyle-config.xml" | ||
|
||
trapExit := false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 0 additions & 41 deletions
41
src/main/scala/de/upb/cs/swt/delphi/cli/BlockingHttpClient.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,40 @@ | ||
// Copyright (C) 2018 The Delphi Team. | ||
// See the LICENCE file distributed with this work for additional | ||
// information regarding copyright ownership. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package de.upb.cs.swt.delphi.cli | ||
|
||
/** | ||
* Represents a configuration for the Delphi CLI | ||
* @param server A server base uri (Defaults to env variable DELPHI_SERVER) | ||
* | ||
* @param server A server base uri (Defaults to env variable DELPHI_SERVER) | ||
* @param verbose Marker if logging should be verbose | ||
* @param mode The command to be run | ||
* @param mode The command to be run | ||
*/ | ||
case class Config (server : String = sys.env.getOrElse("DELPHI_SERVER", "https://delphi.cs.uni-paderborn.de/api/"), | ||
verbose: Boolean = false, mode : String = "", args : List[String] = List(), opts : List[String] = List()) | ||
case class Config(server: String = sys.env.getOrElse("DELPHI_SERVER", "https://delphi.cs.uni-paderborn.de/api/"), | ||
verbose: Boolean = false, | ||
raw: Boolean = false, | ||
silent: Boolean = false, | ||
list : Boolean = false, | ||
mode: String = "", | ||
query : String = "", | ||
limit : Option[Int] = None, | ||
id : String = "", | ||
args: List[String] = List(), | ||
opts: List[String] = List()) { | ||
|
||
lazy val consoleOutput = new ConsoleOutput(this) | ||
|
||
} |
59 changes: 59 additions & 0 deletions
59
src/main/scala/de/upb/cs/swt/delphi/cli/ConsoleOutput.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright (C) 2018 The Delphi Team. | ||
// See the LICENCE file distributed with this work for additional | ||
// information regarding copyright ownership. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package de.upb.cs.swt.delphi.cli | ||
|
||
import de.upb.cs.swt.delphi.cli.artifacts.{RetrieveResult, SearchResult} | ||
|
||
class ConsoleOutput(config: Config) { | ||
|
||
def outputInformation(value: String): Unit = { | ||
//noinspection ScalaStyle | ||
if (!config.silent) println(value) | ||
} | ||
|
||
def outputSuccess(value : String) : Unit = { | ||
//noinspection ScalaStyle | ||
if(!config.silent) println(fansi.Color.Green(value)) | ||
} | ||
|
||
def outputResult(value: Any): Unit = { | ||
//noinspection ScalaStyle | ||
println( | ||
config.raw match { | ||
case true => value.toString | ||
case false => { | ||
value match { | ||
case Seq() => "" | ||
case searchResults : Seq[SearchResult] if searchResults.head.isInstanceOf[SearchResult] => { | ||
config.list match { | ||
case true => searchResults.map(_.toMavenIdentifier()).mkString(System.lineSeparator()) | ||
case false => ResultBeautifier.beautifySearchResults(searchResults) | ||
} | ||
} | ||
case retrieveResults : Seq[RetrieveResult] if retrieveResults.head.isInstanceOf[RetrieveResult] => ResultBeautifier.beautifyRetrieveResults(retrieveResults) | ||
case _ => value.toString | ||
} | ||
} | ||
} | ||
) | ||
} | ||
|
||
def outputError(value : String) : Unit = { | ||
//noinspection ScalaStyle | ||
println(fansi.Color.Red(value)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,95 @@ | ||
// Copyright (C) 2018 The Delphi Team. | ||
// See the LICENCE file distributed with this work for additional | ||
// information regarding copyright ownership. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package de.upb.cs.swt.delphi.cli | ||
|
||
import de.upb.cs.swt.delphi.cli.commands.{RetrieveCommand, TestCommand} | ||
import akka.actor.ActorSystem | ||
import akka.http.scaladsl.Http | ||
import akka.stream.ActorMaterializer | ||
import de.upb.cs.swt.delphi.cli.commands.{RetrieveCommand, SearchCommand, TestCommand} | ||
|
||
import scala.concurrent.duration.Duration | ||
import scala.concurrent.{Await, ExecutionContext} | ||
|
||
|
||
/** | ||
* The application class for the Delphi command line interface | ||
*/ | ||
object DelphiCLI extends App { | ||
|
||
implicit val system = ActorSystem() | ||
|
||
|
||
val cliParser = { | ||
new scopt.OptionParser[Config]("delphi-cli") { | ||
head("Delphi Command Line Tool", s"(${BuildInfo.version})") | ||
|
||
|
||
version("version").text("Prints the version of the command line tool.") | ||
|
||
help("help").text("Prints this help text.") | ||
override def showUsageOnError = true | ||
|
||
opt[String]("server").action( (x,c) => c.copy(server = x)).text("The url to the Delphi server") | ||
opt[Unit] (name = "raw").action((_,c) => c.copy(raw = true)).text("Output the raw results") | ||
opt[Unit] (name = "silent").action((_,c) => c.copy(silent = true)).text("Suppress non-result output") | ||
|
||
checkConfig(c => if (c.server.isEmpty()) failure("Option server is required.") else success) | ||
|
||
cmd("test").action((_,c) => c.copy(mode = "test")) | ||
|
||
cmd("retrieve").action((s,c) => c.copy(mode = "retrieve")) | ||
.text("Retrieve a project's description, specified by ID.") | ||
.children( | ||
arg[String]("ID").action((x, c) => c.copy(args = List(x))).text("The ID of the project to retrieve"), | ||
arg[String]("id").action((x, c) => c.copy(id = x)).text("The ID of the project to retrieve"), | ||
opt[Unit]('f', "file").action((_, c) => c.copy(opts = List("file"))).text("Use to load the ID from file, " + | ||
"with the filepath given in place of the ID") | ||
) | ||
|
||
//cmd("search") | ||
cmd("search").action((s, c) => c.copy(mode = "search")) | ||
.text("Search artifact using a query.") | ||
.children( | ||
arg[String]("query").action((x,c) => c.copy(query = x)).text("The query to be used."), | ||
opt[Int]("limit").action((x, c) => c.copy(limit = Some(x))).text("The maximal number of results returned."), | ||
opt[Unit](name="list").action((_, c) => c.copy(list = true)).text("Output results as list (raw option overrides this)") | ||
) | ||
} | ||
} | ||
|
||
|
||
cliParser.parse(args, Config()) match { | ||
case Some(config) => | ||
cliParser.showHeader() | ||
if (!config.silent) cliParser.showHeader() | ||
config.mode match { | ||
case "test" => TestCommand.execute(config) | ||
case "retrieve" => RetrieveCommand.execute(config) | ||
case _ => println("Unknown command") | ||
case "search" => SearchCommand.execute(config) | ||
case x => config.consoleOutput.outputError(s"Unknown command: $x") | ||
} | ||
|
||
case None => println("nope") | ||
case None => | ||
} | ||
|
||
|
||
val poolShutdown = Http().shutdownAllConnectionPools() | ||
Await.result(poolShutdown, Duration.Inf) | ||
|
||
implicit val ec: ExecutionContext = system.dispatcher | ||
val terminationFuture = system.terminate() | ||
|
||
terminationFuture.onComplete { | ||
sys.exit(0) | ||
} | ||
} |
Oops, something went wrong.