1
1
/*
2
- * Copyright 2021-2023 the original author or authors.
2
+ * Copyright 2021-2024 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
25
25
import org .jline .reader .Parser ;
26
26
import org .jline .reader .impl .DefaultParser ;
27
27
28
- import org .springframework .boot .ApplicationArguments ;
29
28
import org .springframework .core .annotation .Order ;
30
29
import org .springframework .shell .Input ;
31
30
import org .springframework .shell .InputProvider ;
34
33
import org .springframework .shell .Utils ;
35
34
import org .springframework .shell .context .InteractionMode ;
36
35
import org .springframework .shell .context .ShellContext ;
36
+ import org .springframework .util .ObjectUtils ;
37
37
import org .springframework .util .StringUtils ;
38
38
39
39
/**
@@ -65,8 +65,8 @@ public class NonInteractiveShellRunner implements ShellRunner {
65
65
private static final String SINGLE_QUOTE = "\' " ;
66
66
private static final String DOUBLE_QUOTE = "\" " ;
67
67
68
- private Function <ApplicationArguments , List <String >> commandsFromInputArgs = args -> {
69
- if (args . getSourceArgs (). length == 0 ) {
68
+ private Function <String [] , List <String >> commandsFromArgs = args -> {
69
+ if (ObjectUtils . isEmpty ( args ) ) {
70
70
if (StringUtils .hasText (primaryCommand )) {
71
71
Collections .singletonList (primaryCommand );
72
72
}
@@ -75,7 +75,7 @@ public class NonInteractiveShellRunner implements ShellRunner {
75
75
}
76
76
}
77
77
// re-quote if needed having whitespace
78
- String raw = Arrays .stream (args . getSourceArgs () )
78
+ String raw = Arrays .stream (args )
79
79
.map (a -> {
80
80
if (!isQuoted (a ) && StringUtils .containsWhitespace (a )) {
81
81
return "\" " + a + "\" " ;
@@ -113,12 +113,12 @@ public NonInteractiveShellRunner(Shell shell, ShellContext shellContext, String
113
113
/**
114
114
* Sets the function that creates the command() to run from the input application arguments.
115
115
*
116
- * @param commandsFromInputArgs function that takes input application arguments and creates zero or more commands
116
+ * @param commandsFromArgs function that takes input application arguments and creates zero or more commands
117
117
* where each command is a string that specifies the command and options
118
118
* (eg. 'history --file myHistory.txt')
119
119
*/
120
- public void setCommandsFromInputArgs (Function <ApplicationArguments , List <String >> commandsFromInputArgs ) {
121
- this .commandsFromInputArgs = commandsFromInputArgs ;
120
+ public void setCommandsFromArgs (Function <String [] , List <String >> commandsFromArgs ) {
121
+ this .commandsFromArgs = commandsFromArgs ;
122
122
}
123
123
124
124
/**
@@ -131,19 +131,18 @@ public void setLineParser(Parser lineParser) {
131
131
}
132
132
133
133
@ Override
134
- public boolean canRun (ApplicationArguments args ) {
135
- return !commandsFromInputArgs .apply (args ).isEmpty ();
136
- }
137
-
138
- @ Override
139
- public void run (ApplicationArguments args ) throws Exception {
140
- shellContext .setInteractionMode (InteractionMode .NONINTERACTIVE );
141
- List <String > commands = this .commandsFromInputArgs .apply (args );
134
+ public boolean run (String [] args ) throws Exception {
135
+ List <String > commands = commandsFromArgs .apply (args );
136
+ if (commands .isEmpty ()) {
137
+ return false ;
138
+ }
142
139
List <ParsedLine > parsedLines = commands .stream ()
143
140
.map (rawCommandLine -> lineParser .parse (rawCommandLine , rawCommandLine .length () + 1 ))
144
141
.collect (Collectors .toList ());
145
142
MultiParsedLineInputProvider inputProvider = new MultiParsedLineInputProvider (parsedLines );
143
+ shellContext .setInteractionMode (InteractionMode .NONINTERACTIVE );
146
144
shell .run (inputProvider );
145
+ return true ;
147
146
}
148
147
149
148
/**
0 commit comments