Skip to content

Commit

Permalink
Merge pull request #24 from delphi-hub/develop
Browse files Browse the repository at this point in the history
Alpha Release
  • Loading branch information
bhermann authored Nov 1, 2018
2 parents 2afb0dc + f74c0fd commit dbb0901
Show file tree
Hide file tree
Showing 13 changed files with 590 additions and 90 deletions.
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ The command-line interface for the Delphi platform.
We are currently in pre-alpha state! There is no release and the code in
this repository is purely experimental!

|branch | status | codacy |
| :---: | :---: | :---: |
| 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)|
| develop | [![Build Status](https://travis-ci.org/delphi-hub/delphi-cli.svg?branch=develop)](https://travis-ci.org/delphi-hub/delphi-cli) | |
|branch | status | codacy | snyk |
| :---: | :---: | :---: | :---: |
| 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) |
| 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)

## What is the Delphi Command-Line Interface?

Expand All @@ -31,11 +31,13 @@ Our software is available as a binary release on [GitHub](https://github.com/del
```
$ delphi-cli --help
Delphi Command Line Tool (1.0.0-SNAPSHOT)
Usage: delphi-cli [test|search|retrieve] [options]
Usage: delphi-cli [test|retrieve|search] [options] <args>...
--version Prints the version of the command line tool.
--help Prints this help text.
--server <value> The url to the Delphi server
--version Prints the version of the command line tool.
--help Prints this help text.
--server <value> The url to the Delphi server
--raw Output the raw results
--silent Suppress non-result output
```
By default the command-line tool uses the official Delphi server at https://delphi.cs.uni-paderborn.de to process queries.
You can override this setting using the `--server` option or by setting the `DELPHI_SERVER` environment variable.
Expand Down
17 changes: 14 additions & 3 deletions build.sbt
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]>"

Expand All @@ -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(".")).
Expand All @@ -34,3 +44,4 @@ lazy val cli = (project in file(".")).
)
scalastyleConfig := baseDirectory.value / "project" / "scalastyle-config.xml"

trapExit := false
6 changes: 3 additions & 3 deletions project/scalastyle-config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
</check>
<check level="warning" class="org.scalastyle.file.HeaderMatchesChecker" enabled="true">
<parameters>
<parameter name="header"><![CDATA[// Copyright (C) 2011-2012 the original author or authors.
// See the LICENCE.txt file distributed with this work for additional
<parameter name="header"><![CDATA[// 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");
Expand Down Expand Up @@ -83,7 +83,7 @@
<parameter name="maxTypes"><![CDATA[30]]></parameter>
</parameters>
</check>
<check level="warning" class="org.scalastyle.scalariform.CyclomaticComplexityChecker" enabled="true">
<check level="warning" class="org.scalastyle.scalariform.CyclomaticComplexityChecker" enabled="false">
<parameters>
<parameter name="maximum"><![CDATA[10]]></parameter>
</parameters>
Expand Down
41 changes: 0 additions & 41 deletions src/main/scala/de/upb/cs/swt/delphi/cli/BlockingHttpClient.scala

This file was deleted.

38 changes: 34 additions & 4 deletions src/main/scala/de/upb/cs/swt/delphi/cli/Config.scala
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 src/main/scala/de/upb/cs/swt/delphi/cli/ConsoleOutput.scala
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))
}
}
57 changes: 50 additions & 7 deletions src/main/scala/de/upb/cs/swt/delphi/cli/DelphiCLI.scala
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)
}
}
Loading

0 comments on commit dbb0901

Please sign in to comment.