Skip to content

Commit 0dafbc5

Browse files
committed
Update samples
- Simplify hello world sample to the bare minimum - Update groups in PetClinic commands
1 parent 13c093d commit 0dafbc5

File tree

9 files changed

+19
-176
lines changed

9 files changed

+19
-176
lines changed

spring-shell-samples/spring-shell-sample-hello-world/src/main/java/org/springframework/shell/samples/helloworld/HelloCommand.java

Lines changed: 0 additions & 48 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
package org.springframework.shell.samples.helloworld;
22

3-
import java.io.PrintWriter;
4-
import java.util.List;
5-
63
import org.springframework.context.ApplicationContext;
74
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
8-
import org.springframework.context.annotation.Bean;
95
import org.springframework.shell.core.ShellRunner;
10-
import org.springframework.shell.core.command.CommandContext;
11-
import org.springframework.shell.core.command.annotation.*;
12-
import org.springframework.shell.core.commands.AbstractCommand;
6+
import org.springframework.shell.core.command.annotation.Command;
7+
import org.springframework.shell.core.command.annotation.EnableCommand;
8+
import org.springframework.shell.core.command.annotation.Option;
139

1410
@EnableCommand(SpringShellApplication.class)
1511
public class SpringShellApplication {
@@ -20,59 +16,11 @@ public static void main(String[] args) throws Exception {
2016
runner.run(args);
2117
}
2218

23-
@Command(name = "hi", description = "Say hi to a given name", group = "greetings",
24-
help = "A command that greets the user with 'Hi ${name}!' with a configurable suffix. Example usage: hi -s=! John")
25-
public void sayHi(
26-
@Argument(index = 0, description = "the name of the person to greet", defaultValue = "world") String name,
27-
@Option(shortName = 's', longName = "suffix", description = "the suffix of the greeting message",
28-
defaultValue = "!") char suffix) {
29-
System.out.println("Hi " + name + suffix);
30-
}
31-
32-
@Command(name = "hey", description = "Say hey to everyone", group = "greetings",
33-
help = "A command that greets all given names. Example usage: hey John Doe -s=!")
34-
public void sayHeyToEveryone(@Arguments List<String> names, @Option(shortName = 's', longName = "suffix",
35-
description = "the suffix of the greeting message", defaultValue = "!") char suffix) {
36-
System.out.println("Hey " + String.join(",", names) + suffix);
37-
}
38-
39-
@Command(name = "yo", description = "Say yo", group = "greetings",
40-
help = "A command that greets the user with 'Yo there! what's up?'")
41-
public void sayYo(CommandContext commandContext) {
42-
try (PrintWriter outputWriter = commandContext.outputWriter()) {
43-
outputWriter.println("Yo there! what's up?");
44-
}
45-
}
46-
47-
@Bean
48-
public AbstractCommand sayGoodMorning() {
49-
return org.springframework.shell.core.command.Command.builder()
50-
.name("good-morning")
51-
.description("Say good morning")
52-
.group("greetings")
53-
.help("A command that greets the user with 'Good morning!'")
54-
.execute(commandContext -> {
55-
String ansiString = "Good morning!";
56-
try (PrintWriter outputWriter = commandContext.outputWriter()) {
57-
outputWriter.println(ansiString);
58-
outputWriter.flush();
59-
}
60-
});
61-
}
62-
63-
@Bean
64-
public AbstractCommand sayGoodDay() {
65-
return org.springframework.shell.core.command.Command.builder()
66-
.name("good-day")
67-
.description("Say good day")
68-
.group("greetings")
69-
.help("A command that greets the user with 'Good day!'")
70-
.execute(commandContext -> "Good day!");
71-
}
72-
73-
@Bean
74-
public HelloCommand sayHello() {
75-
return new HelloCommand();
19+
@Command(name = "hello", description = "Say hello to a given name", group = "Greetings",
20+
help = "A command that greets the user with 'Hello ${name}!'. Usage: hello [-n | --name]=<name>")
21+
public void sayHello(@Option(shortName = 'n', longName = "name", description = "the name of the person to greet",
22+
defaultValue = "World") String name) {
23+
System.out.println("Hello " + name + "!");
7624
}
7725

7826
}

spring-shell-samples/spring-shell-sample-petclinic/src/main/java/org/springframework/shell/samples/petclinic/commands/OwnerDetailsCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class OwnerDetailsCommand extends AbstractCommand {
3636
private final JdbcClient jdbcClient;
3737

3838
public OwnerDetailsCommand(JdbcClient jdbcClient) {
39-
super("owners info", "Show details of a given owner", "owners", "show the details of a given owner");
39+
super("owners info", "Show details of a given owner", "Owners", "show the details of a given owner");
4040
this.jdbcClient = jdbcClient;
4141
}
4242

spring-shell-samples/spring-shell-sample-petclinic/src/main/java/org/springframework/shell/samples/petclinic/commands/OwnersListCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class OwnersListCommand extends AbstractCommand {
3737
private final JdbcClient jdbcClient;
3838

3939
public OwnersListCommand(JdbcClient jdbcClient) {
40-
super("owners list", "List owners", "owners", "Command to list owners");
40+
super("owners list", "List owners", "Owners", "Command to list owners");
4141
this.jdbcClient = jdbcClient;
4242
}
4343

spring-shell-samples/spring-shell-sample-petclinic/src/main/java/org/springframework/shell/samples/petclinic/commands/PetCommands.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public PetCommands(JdbcClient jdbcClient) {
3838
this.jdbcClient = jdbcClient;
3939
}
4040

41-
@Command(name = { "pets", "list" }, description = "List pets", group = "pets", help = "List pets in Pet Clinic")
41+
@Command(name = { "pets", "list" }, description = "List pets", group = "Pets", help = "List pets in Pet Clinic")
4242
public void listPets(CommandContext commandContext) {
4343
List<@Nullable Pet> pets = jdbcClient.sql("SELECT id, name FROM PETS")
4444
.query(new DataClassRowMapper<>(Pet.class))
@@ -51,7 +51,7 @@ public void listPets(CommandContext commandContext) {
5151
}
5252

5353
// TODO inject context and use output writer instead of System.out and System.err
54-
@Command(name = { "pets", "info" }, description = "Show detail about a given pet", group = "pets",
54+
@Command(name = { "pets", "info" }, description = "Show detail about a given pet", group = "Pets",
5555
help = "Show the details about a given pet")
5656
public void showPet(@Option(longName = "petId", description = "The pet ID") int id) {
5757
try {

spring-shell-samples/spring-shell-sample-petclinic/src/main/java/org/springframework/shell/samples/petclinic/commands/VetDetailsCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class VetDetailsCommand extends AbstractCommand {
3636
private final JdbcClient jdbcClient;
3737

3838
public VetDetailsCommand(JdbcClient jdbcClient) {
39-
super("vets info", "Show details of a given veterinarian", "vets", "show the details of a given veterinarian");
39+
super("vets info", "Show details of a given veterinarian", "Vets", "show the details of a given veterinarian");
4040
this.jdbcClient = jdbcClient;
4141
}
4242

spring-shell-samples/spring-shell-sample-petclinic/src/main/java/org/springframework/shell/samples/petclinic/commands/VetsListCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class VetsListCommand extends AbstractCommand {
3737
private final JdbcClient jdbcClient;
3838

3939
public VetsListCommand(JdbcClient jdbcClient) {
40-
super("vets list", "List veterinarians", "vets", "Command to list veterinarians");
40+
super("vets list", "List veterinarians", "Vets", "Command to list veterinarians");
4141
this.jdbcClient = jdbcClient;
4242
}
4343

spring-shell-samples/spring-shell-sample-spring-boot/src/main/java/org/springframework/shell/samples/helloworld/boot/HelloCommand.java

Lines changed: 0 additions & 48 deletions
This file was deleted.

spring-shell-samples/spring-shell-sample-spring-boot/src/main/java/org/springframework/shell/samples/helloworld/boot/SpringShellApplication.java

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
5-
import org.springframework.context.annotation.Bean;
6-
import org.springframework.shell.core.command.annotation.Argument;
75
import org.springframework.shell.core.command.annotation.Command;
86
import org.springframework.shell.core.command.annotation.Option;
97

@@ -14,18 +12,11 @@ public static void main(String[] args) {
1412
SpringApplication.run(SpringShellApplication.class, args);
1513
}
1614

17-
@Command(name = "hi", description = "Say hi to a given name", group = "greetings",
18-
help = "A command that greets the user with 'Hi ${name}!' with a configurable suffix. Example usage: hi -s=! John")
19-
public void sayHi(
20-
@Argument(index = 0, description = "the name of the person to greet", defaultValue = "world") String name,
21-
@Option(shortName = 's', longName = "suffix", description = "the suffix of the greeting message",
22-
defaultValue = "!") char suffix) {
23-
System.out.println("Hi " + name + suffix);
24-
}
25-
26-
@Bean
27-
public HelloCommand sayHello() {
28-
return new HelloCommand();
15+
@Command(name = "hello", description = "Say hello to a given name", group = "Greetings",
16+
help = "A command that greets the user with 'Hello ${name}!'. Usage: hello [-n | --name]=<name>")
17+
public void sayHello(@Option(shortName = 'n', longName = "name", description = "the name of the person to greet",
18+
defaultValue = "World") String name) {
19+
System.out.println("Hello " + name + "!");
2920
}
3021

3122
}

0 commit comments

Comments
 (0)