ScriptShellRunner should have correct run detection

- Fix run detection so that @ has to be first character in a first
  argument and it also has additional content, like @path-to-file.
- This fixes issue where `--arg @` would blow up as an normal
  option argument.
- Fixes #996
This commit is contained in:
Janne Valkealahti
2024-02-15 10:17:04 +00:00
parent afb8bc7104
commit 77a694848c
2 changed files with 58 additions and 7 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2018-2022 the original author or authors.
* Copyright 2018-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,7 +28,6 @@ import org.springframework.boot.ApplicationArguments;
import org.springframework.core.annotation.Order;
import org.springframework.shell.Shell;
import org.springframework.shell.ShellRunner;
import org.springframework.util.ObjectUtils;
/**
* A {@link ShellRunner} that looks for process arguments that start with {@literal @}, which are then interpreted as
@@ -61,11 +60,11 @@ public class ScriptShellRunner implements ShellRunner {
@Override
public boolean canRun(ApplicationArguments args) {
List<File> scriptsToRun = args.getNonOptionArgs().stream()
.filter(s -> s.startsWith("@"))
.map(s -> new File(s.substring(1)))
.collect(Collectors.toList());
return !ObjectUtils.isEmpty(scriptsToRun);
String[] sourceArgs = args.getSourceArgs();
if (sourceArgs.length > 0 && sourceArgs[0].startsWith("@") && sourceArgs[0].length() > 1) {
return true;
}
return false;
}
//tag::documentation[]