16
16
17
17
package de .upb .cs .swt .delphi .cli
18
18
19
- import akka .actor .ActorSystem
20
- import akka .http .scaladsl .Http
21
- import de .upb .cs .swt .delphi .cli .commands .{RetrieveCommand , SearchCommand , TestCommand }
22
-
23
- import scala .concurrent .duration .Duration
24
- import scala .concurrent .{Await , ExecutionContext }
25
-
19
+ import com .softwaremill .sttp ._
20
+ import de .upb .cs .swt .delphi .cli .commands ._
26
21
27
22
/**
28
23
* The application class for the Delphi command line interface
29
24
*/
30
- object DelphiCLI extends App {
25
+ object DelphiCLI {
26
+
27
+
28
+ def main (args : Array [String ]): Unit = {
31
29
32
- implicit val system = ActorSystem ( )
30
+ def getEnvOrElse ( envVar : String , defaultPath : String ) = sys.env.getOrElse(envVar, defaultPath )
33
31
34
- val cliParser = {
35
- new scopt.OptionParser [Config ](" delphi-cli" ) {
36
- head(" Delphi Command Line Tool" , s " ( ${BuildInfo .version}) " )
32
+ val javaLibPath = getEnvOrElse(" JAVA_LIB_PATH" , " /usr/lib/jvm/default-java/lib/" )
37
33
38
- version( " version " ).text( " Prints the version of the command line tool. " )
34
+ val trustStorePath = getEnvOrElse( " JAVA_TRUSTSTORE " , " /usr/lib/jvm/default-java/lib/security/cacerts " )
39
35
40
- help( " help " ).text( " Prints this help text. " )
41
- override def showUsageOnError = true
36
+ System .setProperty( " java.library.path " , javaLibPath )
37
+ System .setProperty( " javax.net.ssl.trustStore " , trustStorePath)
42
38
43
- opt[String ](" server" ).action( (x,c) => c.copy(server = x)).text(" The url to the Delphi server" )
44
- opt[Unit ] (name = " raw" ).action((_,c) => c.copy(raw = true )).text(" Output the raw results" )
45
- opt[Unit ] (name = " silent" ).action((_,c) => c.copy(silent = true )).text(" Suppress non-result output" )
39
+ cliParser.parse(args, Config ()) match {
40
+ case Some (c) =>
46
41
47
- checkConfig(c => if (c.server.isEmpty()) failure(" Option server is required." ) else success)
48
42
49
- cmd(" test" ).action((_,c) => c.copy(mode = " test" ))
43
+ implicit val config : Config = c
44
+ implicit val backend : SttpBackend [Id , Nothing ] = HttpURLConnectionBackend ()
50
45
51
- cmd(" retrieve" ).action((s,c) => c.copy(mode = " retrieve" ))
52
- .text(" Retrieve a project's description, specified by ID." )
53
- .children(
54
- arg[String ](" id" ).action((x, c) => c.copy(id = x)).text(" The ID of the project to retrieve" ),
55
- opt[String ](" csv" ).action((x, c) => c.copy(csv = x)).text(" Path to the output .csv file (overwrites existing file)" ),
56
- opt[Unit ]('f' , " file" ).action((_, c) => c.copy(opts = List (" file" ))).text(" Use to load the ID from file, " +
57
- " with the filepath given in place of the ID" )
58
- )
46
+ if (! config.silent) cliParser.showHeader()
59
47
60
- cmd( " search " ).action((s, c) => c.copy( mode = " search " ))
61
- .text( " Search artifact using a query. " )
62
- .children(
63
- arg[ String ]( " query " ).action((x,c) => c.copy(query = x)).text( " The query to be used. " ),
64
- opt[ String ]( " csv " ).action((x, c) => c.copy(csv = x)).text( " Path to the output .csv file (overwrites existing file) " ),
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
- opt[ Int ]( " timeout " ).action((x, c) => c.copy(timeout = Some (x))).text( " Timeout in seconds. " )
68
- )
48
+ config. mode match {
49
+ case " test " => TestCommand .execute
50
+ case " retrieve " => RetrieveCommand .execute
51
+ case " search " => SearchCommand .execute
52
+ case x => config.consoleOutput.outputError( s " Unknown command: $x " )
53
+ }
54
+
55
+
56
+ case None =>
69
57
}
58
+
70
59
}
71
60
61
+ private def cliParser = {
62
+ val parser = {
63
+ new scopt.OptionParser [Config ](" delphi-cli" ) {
64
+ head(" Delphi Command Line Tool" , s " ( ${BuildInfo .version}) " )
72
65
73
- cliParser.parse(args, Config ()) match {
74
- case Some (config) =>
75
- if (! config.silent) cliParser.showHeader()
76
- config.mode match {
77
- case " test" => TestCommand .execute(config)
78
- case " retrieve" => RetrieveCommand .execute(config)
79
- case " search" => SearchCommand .execute(config)
80
- case x => config.consoleOutput.outputError(s " Unknown command: $x" )
81
- }
66
+ version(" version" ).text(" Prints the version of the command line tool." )
82
67
83
- case None =>
84
- }
68
+ help(" help" ).text(" Prints this help text." )
69
+
70
+ override def showUsageOnError = true
85
71
72
+ opt[String ](" server" ).action((x, c) => c.copy(server = x)).text(" The url to the Delphi server" )
73
+ opt[Unit ](name = " raw" ).action((_, c) => c.copy(raw = true )).text(" Output the raw results" )
74
+ opt[Unit ](name = " silent" ).action((_, c) => c.copy(silent = true )).text(" Suppress non-result output" )
86
75
87
- val poolShutdown = Http ().shutdownAllConnectionPools()
88
- Await .result(poolShutdown, Duration .Inf )
76
+ checkConfig(c => if (c.server.isEmpty()) failure(" Option server is required." ) else success)
89
77
90
- implicit val ec : ExecutionContext = system.dispatcher
91
- val terminationFuture = system.terminate()
78
+ cmd(" test" ).action((_, c) => c.copy(mode = " test" ))
92
79
93
- terminationFuture.onComplete {
94
- sys.exit(0 )
80
+ cmd(" retrieve" ).action((s, c) => c.copy(mode = " retrieve" ))
81
+ .text(" Retrieve a project's description, specified by ID." )
82
+ .children(
83
+ arg[String ](" id" ).action((x, c) => c.copy(id = x)).text(" The ID of the project to retrieve" ),
84
+ opt[String ](" csv" ).action((x, c) => c.copy(csv = x)).text(" Path to the output .csv file (overwrites existing file)" ),
85
+ opt[Unit ]('f' , " file" ).action((_, c) => c.copy(opts = List (" file" ))).text(" Use to load the ID from file, " +
86
+ " with the filepath given in place of the ID" )
87
+ )
88
+
89
+ cmd(" search" ).action((s, c) => c.copy(mode = " search" ))
90
+ .text(" Search artifact using a query." )
91
+ .children(
92
+ arg[String ](" query" ).action((x, c) => c.copy(query = x)).text(" The query to be used." ),
93
+ opt[String ](" csv" ).action((x, c) => c.copy(csv = x)).text(" Path to the output .csv file (overwrites existing file)" ),
94
+ opt[Int ](" limit" ).action((x, c) => c.copy(limit = Some (x))).text(" The maximal number of results returned." ),
95
+ opt[Unit ](name = " list" ).action((_, c) => c.copy(list = true )).text(" Output results as list (raw option overrides this)" ),
96
+ opt[Int ](" timeout" ).action((x, c) => c.copy(timeout = Some (x))).text(" Timeout in seconds." )
97
+ )
98
+ }
99
+ }
100
+ parser
95
101
}
96
- }
102
+ }
0 commit comments