Skip to content

Commit 8696070

Browse files
committed
Retrieve command can now take a filename to load an ID from.
1 parent 00cec89 commit 8696070

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ object DelphiCLI extends App {
2626
cmd("retrieve").action((s,c) => c.copy(mode = "retrieve"))
2727
.text("Retrieve a project's description, specified by ID.")
2828
.children(
29-
arg[String]("ID").action((x, c) => c.copy(args = List(x))).text("The ID of the project to retrieve")
29+
arg[String]("ID").action((x, c) => c.copy(args = List(x))).text("The ID of the project to retrieve"),
30+
opt[Unit]('f', "file").action((_, c) => c.copy(opts = List("file"))).text("Use to load the ID from file, " +
31+
"with the filepath given in place of the ID")
3032
)
3133

3234
//cmd("search")
Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
11
package de.upb.cs.swt.delphi.cli.commands
22

33
import de.upb.cs.swt.delphi.cli.Config
4+
import io.Source
45

56
/**
67
* The implementation of the retrieve command.
78
* Retrieves the contents of the file at the endpoint specified by the config file, and prints them to stdout
89
*/
910
object RetrieveCommand extends Command {
10-
override def execute(config: Config): Unit = executeGet(
11-
"/retrieve/" + config.args.head,
12-
s => println(s)
13-
)(config)
11+
override def execute(config: Config): Unit = {
12+
//Checks whether the ID should be loaded from a file or not, and either returns the first line
13+
// of the given file if it is, or the specified ID otherwise
14+
def checkTarget: String = {
15+
if (config.opts.contains("file")) {
16+
val source = Source.fromFile(config.args.head)
17+
val target = source.getLines.next()
18+
source.close()
19+
target
20+
} else config.args.head
21+
}
22+
executeGet(
23+
"/retrieve/" + checkTarget,
24+
s => println(s)
25+
)(config)
26+
}
1427
}

0 commit comments

Comments
 (0)