Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
0f083c2f
Commit
0f083c2f
authored
Feb 04, 2014
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix CLI class tangle
parent
1061d582
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
29 deletions
+64
-29
PromptCommand.java
...springframework/boot/cli/command/shell/PromptCommand.java
+5
-5
Shell.java
...ava/org/springframework/boot/cli/command/shell/Shell.java
+4
-24
ShellPrompts.java
.../springframework/boot/cli/command/shell/ShellPrompts.java
+55
-0
No files found.
spring-boot-cli/src/main/java/org/springframework/boot/cli/command/shell/PromptCommand.java
View file @
0f083c2f
...
...
@@ -26,23 +26,23 @@ import org.springframework.boot.cli.command.Command;
*/
public
class
PromptCommand
extends
AbstractCommand
{
private
final
Shell
shell
;
private
final
Shell
Prompts
prompts
;
public
PromptCommand
(
Shell
shell
)
{
public
PromptCommand
(
Shell
Prompts
shellPrompts
)
{
super
(
"prompt"
,
"Change the prompt used with the current 'shell' command. "
+
"Execute with no arguments to return to the previous value."
);
this
.
shell
=
shell
;
this
.
prompts
=
shellPrompts
;
}
@Override
public
void
run
(
String
...
strings
)
throws
Exception
{
if
(
strings
.
length
>
0
)
{
for
(
String
string
:
strings
)
{
this
.
shell
.
pushPrompt
(
string
+
" "
);
this
.
prompts
.
pushPrompt
(
string
+
" "
);
}
}
else
{
this
.
shell
.
popPrompt
();
this
.
prompts
.
popPrompt
();
}
}
...
...
spring-boot-cli/src/main/java/org/springframework/boot/cli/command/shell/Shell.java
View file @
0f083c2f
...
...
@@ -25,7 +25,6 @@ import java.util.List;
import
java.util.Map
;
import
java.util.ServiceLoader
;
import
java.util.Set
;
import
java.util.Stack
;
import
jline.console.ConsoleReader
;
import
jline.console.completer.CandidateListCompletionHandler
;
...
...
@@ -61,15 +60,13 @@ public class Shell {
private
static
final
Signal
SIG_INT
=
new
Signal
(
"INT"
);
private
static
final
String
DEFAULT_PROMPT
=
"$ "
;
private
final
ShellCommandRunner
commandRunner
;
private
final
ConsoleReader
consoleReader
;
private
final
EscapeAwareWhiteSpaceArgumentDelimiter
argumentDelimiter
=
new
EscapeAwareWhiteSpaceArgumentDelimiter
();
private
final
S
tack
<
String
>
prompts
=
new
Stack
<
String
>
();
private
final
S
hellPrompts
prompts
=
new
ShellPrompts
();
/**
* Create a new {@link Shell} instance.
...
...
@@ -101,7 +98,7 @@ public class Shell {
commands
.
add
(
convertToForkCommand
(
command
));
}
}
commands
.
add
(
new
PromptCommand
(
this
));
commands
.
add
(
new
PromptCommand
(
this
.
prompts
));
commands
.
add
(
new
ClearCommand
(
this
.
consoleReader
));
commands
.
add
(
new
ExitCommand
());
return
commands
;
...
...
@@ -134,23 +131,6 @@ public class Shell {
});
}
/**
* Push a new prompt to be used by the shell.
* @param prompt the prompt
* @see #popPrompt()
*/
public
void
pushPrompt
(
String
prompt
)
{
this
.
prompts
.
push
(
prompt
);
}
/**
* Pop a previously pushed prompt, returning to the previous value.
* @see #pushPrompt(String)
*/
public
void
popPrompt
()
{
this
.
prompts
.
pop
();
}
/**
* Run the shell until the user exists.
* @throws Exception on error
...
...
@@ -168,7 +148,7 @@ public class Shell {
}
private
void
printBanner
()
{
String
version
=
ShellCommand
.
class
.
getPackage
().
getImplementationVersion
();
String
version
=
getClass
()
.
getPackage
().
getImplementationVersion
();
version
=
(
version
==
null
?
""
:
" (v"
+
version
+
")"
);
System
.
out
.
println
(
ansi
(
"Spring Boot"
,
Code
.
BOLD
).
append
(
version
,
Code
.
FAINT
));
System
.
out
.
println
(
ansi
(
"Hit TAB to complete. Type 'help' and hit "
...
...
@@ -190,7 +170,7 @@ public class Shell {
}
private
String
getPrompt
()
{
String
prompt
=
this
.
prompts
.
isEmpty
()
?
DEFAULT_PROMPT
:
this
.
prompts
.
peek
();
String
prompt
=
this
.
prompts
.
getPrompt
();
return
ansi
(
prompt
,
Code
.
FG_BLUE
).
toString
();
}
...
...
spring-boot-cli/src/main/java/org/springframework/boot/cli/command/shell/ShellPrompts.java
0 → 100644
View file @
0f083c2f
/*
* Copyright 2012-2014 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
cli
.
command
.
shell
;
import
java.util.Stack
;
/**
* Abstraction to manage a stack of prompts.
*
* @author Phillip Webb
*/
public
class
ShellPrompts
{
private
static
final
String
DEFAULT_PROMPT
=
"$ "
;
private
final
Stack
<
String
>
prompts
=
new
Stack
<
String
>();
/**
* Push a new prompt to be used by the shell.
* @param prompt the prompt
* @see #popPrompt()
*/
public
void
pushPrompt
(
String
prompt
)
{
this
.
prompts
.
push
(
prompt
);
}
/**
* Pop a previously pushed prompt, returning to the previous value.
* @see #pushPrompt(String)
*/
public
void
popPrompt
()
{
this
.
prompts
.
pop
();
}
/**
* Returns the current prompt.
*/
public
String
getPrompt
()
{
return
this
.
prompts
.
isEmpty
()
?
DEFAULT_PROMPT
:
this
.
prompts
.
peek
();
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment