Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.io.File;
import java.util.List;
import java.util.Objects;

import org.springframework.shell.core.FileInputProvider;
import org.springframework.shell.core.NonInteractiveShellRunner;
Expand All @@ -27,6 +28,7 @@
* @author Eric Bottard
* @author Janne Valkealahti
* @author Mahmoud Ben Hassine
* @author David Pilar
*/
public class Script implements Command {

Expand All @@ -44,13 +46,16 @@ public String getGroup() {

@Override
public ExitStatus execute(CommandContext commandContext) throws Exception {
List<CommandArgument> arguments = commandContext.parsedInput().arguments();
if (arguments.size() != 1) {
throw new IllegalArgumentException(
"Script command expects exactly one argument: the absolute path to the script file to execute.");
}
String scriptFile = arguments.get(0).value();
File file = new File(scriptFile);
String scriptFile = commandContext.parsedInput()
.options()
.stream()
.filter(o -> "file".equals(o.longName()) || 'f' == o.shortName())
.map(CommandOption::value)
.filter(Objects::nonNull)
.findFirst()
.orElseThrow(() -> new IllegalArgumentException(
"Script command expects option --file or -f with exactly one argument: the absolute path to the script file to execute."));
File file = new File(Objects.requireNonNull(scriptFile));
try (FileInputProvider inputProvider = new FileInputProvider(file)) {
String input;
while ((input = inputProvider.readInput()) != null) {
Expand Down