Skip to content

Commit dbb0901

Browse files
authored
Merge pull request #24 from delphi-hub/develop
Alpha Release
2 parents 2afb0dc + f74c0fd commit dbb0901

File tree

13 files changed

+590
-90
lines changed

13 files changed

+590
-90
lines changed

README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ The command-line interface for the Delphi platform.
55
We are currently in pre-alpha state! There is no release and the code in
66
this repository is purely experimental!
77

8-
|branch | status | codacy |
9-
| :---: | :---: | :---: |
10-
| master | [![Build Status](https://travis-ci.org/delphi-hub/delphi-cli.svg?branch=master)](https://travis-ci.org/delphi-hub/delphi-cli) | [![Codacy Badge](https://api.codacy.com/project/badge/Grade/47046de0e8d64ae4b76191b7dae80075)](https://www.codacy.com/app/delphi-hub/delphi-cli?utm_source=github.com&utm_medium=referral&utm_content=delphi-hub/delphi-cli&utm_campaign=Badge_Grade)|
11-
| develop | [![Build Status](https://travis-ci.org/delphi-hub/delphi-cli.svg?branch=develop)](https://travis-ci.org/delphi-hub/delphi-cli) | |
8+
|branch | status | codacy | snyk |
9+
| :---: | :---: | :---: | :---: |
10+
| master | [![Build Status](https://travis-ci.org/delphi-hub/delphi-cli.svg?branch=master)](https://travis-ci.org/delphi-hub/delphi-cli) | [![Codacy Badge](https://api.codacy.com/project/badge/Grade/47046de0e8d64ae4b76191b7dae80075)](https://www.codacy.com/app/delphi-hub/delphi-cli?utm_source=github.com&utm_medium=referral&utm_content=delphi-hub/delphi-cli&utm_campaign=Badge_Grade)| [![Known Vulnerabilities](https://snyk.io/test/github/delphi-hub/delphi-cli/badge.svg?targetFile=build.sbt)](https://snyk.io/test/github/delphi-hub/delphi-cli?targetFile=build.sbt) |
11+
| develop | [![Build Status](https://travis-ci.org/delphi-hub/delphi-cli.svg?branch=develop)](https://travis-ci.org/delphi-hub/delphi-cli) | [![Codacy Badge](https://api.codacy.com/project/badge/Grade/47046de0e8d64ae4b76191b7dae80075?branch=develop)](https://www.codacy.com/app/delphi-hub/delphi-cli?branch=develop&utm_source=github.com&utm_medium=referral&utm_content=delphi-hub/delphi-cli&utm_campaign=Badge_Grade)| [![Known Vulnerabilities](https://snyk.io/test/github/delphi-hub/delphi-cli/develop/badge.svg?targetFile=build.sbt)](https://snyk.io/test/github/delphi-hub/delphi-cli/develop?targetFile=build.sbt)
1212

1313
## What is the Delphi Command-Line Interface?
1414

@@ -31,11 +31,13 @@ Our software is available as a binary release on [GitHub](https://github.com/del
3131
```
3232
$ delphi-cli --help
3333
Delphi Command Line Tool (1.0.0-SNAPSHOT)
34-
Usage: delphi-cli [test|search|retrieve] [options]
34+
Usage: delphi-cli [test|retrieve|search] [options] <args>...
3535
36-
--version Prints the version of the command line tool.
37-
--help Prints this help text.
38-
--server <value> The url to the Delphi server
36+
--version Prints the version of the command line tool.
37+
--help Prints this help text.
38+
--server <value> The url to the Delphi server
39+
--raw Output the raw results
40+
--silent Suppress non-result output
3941
```
4042
By default the command-line tool uses the official Delphi server at https://delphi.cs.uni-paderborn.de to process queries.
4143
You can override this setting using the `--server` option or by setting the `DELPHI_SERVER` environment variable.

build.sbt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
scalaVersion := "2.12.4"
22

3-
name := "delphi-cli"
3+
name := "delphi"
44
version := "1.0.0-SNAPSHOT"
55
maintainer := "Ben Hermann <[email protected]>"
66

@@ -13,11 +13,21 @@ wixProductUpgradeId := "4552fb0e-e257-4dbd-9ecb-dba9dbacf424"
1313

1414
scalastyleConfig := baseDirectory.value / "project" / "scalastyle_config.xml"
1515

16-
libraryDependencies += "com.github.scopt" %% "scopt" % "3.7.0"
16+
val akkaVersion = "2.5.14"
17+
val akkaHttpVersion = "10.1.5"
18+
1719
libraryDependencies ++= Seq(
18-
"com.typesafe.akka" %% "akka-http-core" % "10.0.11"
20+
"com.typesafe.akka" %% "akka-http-core" % akkaHttpVersion,
21+
"com.typesafe.akka" %% "akka-http-spray-json" % akkaHttpVersion,
22+
"com.typesafe.akka" %% "akka-stream" % akkaVersion
1923
)
2024

25+
libraryDependencies += "com.github.scopt" %% "scopt" % "3.7.0"
26+
libraryDependencies += "io.spray" %% "spray-json" % "1.3.3"
27+
libraryDependencies += "de.vandermeer" % "asciitable" % "0.3.2"
28+
libraryDependencies += "com.lihaoyi" %% "fansi" % "0.2.5"
29+
libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value
30+
2131
debianPackageDependencies := Seq("java8-runtime-headless")
2232

2333
lazy val cli = (project in file(".")).
@@ -34,3 +44,4 @@ lazy val cli = (project in file(".")).
3444
)
3545
scalastyleConfig := baseDirectory.value / "project" / "scalastyle-config.xml"
3646

47+
trapExit := false

project/scalastyle-config.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
</check>
99
<check level="warning" class="org.scalastyle.file.HeaderMatchesChecker" enabled="true">
1010
<parameters>
11-
<parameter name="header"><![CDATA[// Copyright (C) 2011-2012 the original author or authors.
12-
// See the LICENCE.txt file distributed with this work for additional
11+
<parameter name="header"><![CDATA[// Copyright (C) 2018 The Delphi Team.
12+
// See the LICENCE file distributed with this work for additional
1313
// information regarding copyright ownership.
1414
//
1515
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -83,7 +83,7 @@
8383
<parameter name="maxTypes"><![CDATA[30]]></parameter>
8484
</parameters>
8585
</check>
86-
<check level="warning" class="org.scalastyle.scalariform.CyclomaticComplexityChecker" enabled="true">
86+
<check level="warning" class="org.scalastyle.scalariform.CyclomaticComplexityChecker" enabled="false">
8787
<parameters>
8888
<parameter name="maximum"><![CDATA[10]]></parameter>
8989
</parameters>

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

Lines changed: 0 additions & 41 deletions
This file was deleted.
Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,40 @@
1+
// Copyright (C) 2018 The Delphi Team.
2+
// See the LICENCE file distributed with this work for additional
3+
// information regarding copyright ownership.
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
117
package de.upb.cs.swt.delphi.cli
218

319
/**
420
* Represents a configuration for the Delphi CLI
5-
* @param server A server base uri (Defaults to env variable DELPHI_SERVER)
21+
*
22+
* @param server A server base uri (Defaults to env variable DELPHI_SERVER)
623
* @param verbose Marker if logging should be verbose
7-
* @param mode The command to be run
24+
* @param mode The command to be run
825
*/
9-
case class Config (server : String = sys.env.getOrElse("DELPHI_SERVER", "https://delphi.cs.uni-paderborn.de/api/"),
10-
verbose: Boolean = false, mode : String = "", args : List[String] = List(), opts : List[String] = List())
26+
case class Config(server: String = sys.env.getOrElse("DELPHI_SERVER", "https://delphi.cs.uni-paderborn.de/api/"),
27+
verbose: Boolean = false,
28+
raw: Boolean = false,
29+
silent: Boolean = false,
30+
list : Boolean = false,
31+
mode: String = "",
32+
query : String = "",
33+
limit : Option[Int] = None,
34+
id : String = "",
35+
args: List[String] = List(),
36+
opts: List[String] = List()) {
37+
38+
lazy val consoleOutput = new ConsoleOutput(this)
39+
40+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright (C) 2018 The Delphi Team.
2+
// See the LICENCE file distributed with this work for additional
3+
// information regarding copyright ownership.
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
package de.upb.cs.swt.delphi.cli
18+
19+
import de.upb.cs.swt.delphi.cli.artifacts.{RetrieveResult, SearchResult}
20+
21+
class ConsoleOutput(config: Config) {
22+
23+
def outputInformation(value: String): Unit = {
24+
//noinspection ScalaStyle
25+
if (!config.silent) println(value)
26+
}
27+
28+
def outputSuccess(value : String) : Unit = {
29+
//noinspection ScalaStyle
30+
if(!config.silent) println(fansi.Color.Green(value))
31+
}
32+
33+
def outputResult(value: Any): Unit = {
34+
//noinspection ScalaStyle
35+
println(
36+
config.raw match {
37+
case true => value.toString
38+
case false => {
39+
value match {
40+
case Seq() => ""
41+
case searchResults : Seq[SearchResult] if searchResults.head.isInstanceOf[SearchResult] => {
42+
config.list match {
43+
case true => searchResults.map(_.toMavenIdentifier()).mkString(System.lineSeparator())
44+
case false => ResultBeautifier.beautifySearchResults(searchResults)
45+
}
46+
}
47+
case retrieveResults : Seq[RetrieveResult] if retrieveResults.head.isInstanceOf[RetrieveResult] => ResultBeautifier.beautifyRetrieveResults(retrieveResults)
48+
case _ => value.toString
49+
}
50+
}
51+
}
52+
)
53+
}
54+
55+
def outputError(value : String) : Unit = {
56+
//noinspection ScalaStyle
57+
println(fansi.Color.Red(value))
58+
}
59+
}
Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,95 @@
1+
// Copyright (C) 2018 The Delphi Team.
2+
// See the LICENCE file distributed with this work for additional
3+
// information regarding copyright ownership.
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
117
package de.upb.cs.swt.delphi.cli
218

3-
import de.upb.cs.swt.delphi.cli.commands.{RetrieveCommand, TestCommand}
19+
import akka.actor.ActorSystem
20+
import akka.http.scaladsl.Http
21+
import akka.stream.ActorMaterializer
22+
import de.upb.cs.swt.delphi.cli.commands.{RetrieveCommand, SearchCommand, TestCommand}
23+
24+
import scala.concurrent.duration.Duration
25+
import scala.concurrent.{Await, ExecutionContext}
426

527

628
/**
729
* The application class for the Delphi command line interface
830
*/
931
object DelphiCLI extends App {
1032

33+
implicit val system = ActorSystem()
34+
35+
1136
val cliParser = {
1237
new scopt.OptionParser[Config]("delphi-cli") {
1338
head("Delphi Command Line Tool", s"(${BuildInfo.version})")
1439

15-
1640
version("version").text("Prints the version of the command line tool.")
1741

1842
help("help").text("Prints this help text.")
1943
override def showUsageOnError = true
2044

2145
opt[String]("server").action( (x,c) => c.copy(server = x)).text("The url to the Delphi server")
46+
opt[Unit] (name = "raw").action((_,c) => c.copy(raw = true)).text("Output the raw results")
47+
opt[Unit] (name = "silent").action((_,c) => c.copy(silent = true)).text("Suppress non-result output")
48+
2249
checkConfig(c => if (c.server.isEmpty()) failure("Option server is required.") else success)
2350

2451
cmd("test").action((_,c) => c.copy(mode = "test"))
2552

2653
cmd("retrieve").action((s,c) => c.copy(mode = "retrieve"))
2754
.text("Retrieve a project's description, specified by ID.")
2855
.children(
29-
arg[String]("ID").action((x, c) => c.copy(args = List(x))).text("The ID of the project to retrieve"),
56+
arg[String]("id").action((x, c) => c.copy(id = x)).text("The ID of the project to retrieve"),
3057
opt[Unit]('f', "file").action((_, c) => c.copy(opts = List("file"))).text("Use to load the ID from file, " +
3158
"with the filepath given in place of the ID")
3259
)
3360

34-
//cmd("search")
61+
cmd("search").action((s, c) => c.copy(mode = "search"))
62+
.text("Search artifact using a query.")
63+
.children(
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."),
66+
opt[Unit](name="list").action((_, c) => c.copy(list = true)).text("Output results as list (raw option overrides this)")
67+
)
3568
}
3669
}
3770

3871

3972
cliParser.parse(args, Config()) match {
4073
case Some(config) =>
41-
cliParser.showHeader()
74+
if (!config.silent) cliParser.showHeader()
4275
config.mode match {
4376
case "test" => TestCommand.execute(config)
4477
case "retrieve" => RetrieveCommand.execute(config)
45-
case _ => println("Unknown command")
78+
case "search" => SearchCommand.execute(config)
79+
case x => config.consoleOutput.outputError(s"Unknown command: $x")
4680
}
4781

48-
case None => println("nope")
82+
case None =>
4983
}
5084

5185

86+
val poolShutdown = Http().shutdownAllConnectionPools()
87+
Await.result(poolShutdown, Duration.Inf)
88+
89+
implicit val ec: ExecutionContext = system.dispatcher
90+
val terminationFuture = system.terminate()
91+
92+
terminationFuture.onComplete {
93+
sys.exit(0)
94+
}
5295
}

0 commit comments

Comments
 (0)