Skip to content

Update getting started guide with new annotations #1171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
17 changes: 8 additions & 9 deletions spring-shell-docs/modules/ROOT/pages/getting-started.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -106,28 +106,27 @@ better with shell apps.
== Your First Command

Now we can add our first command. To do so, create a new class (named whatever you want) and
annotate it with `@ShellComponent` which is a variation of `@Component` that is used to restrict
annotate it with `@Command` which is a variation of `@Component` that is used to restrict
the set of classes that are scanned for candidate commands.

Then we can create a `helloWorld` method that takes `String` as an argument and
returns it with "Hello world". Add `@ShellMethod` and optionally change command name
using `key` parameter. You can use `@ShellOption` to define argument default value
returns it with "Hello world". Add `@Command` and optionally change command name
using `command` parameter. You can use `@Option` to define argument default value
if it's not given when running a command.

[source, java]
----
package com.example.demo;

import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
import org.springframework.shell.standard.ShellOption;
import org.springframework.shell.command.annotation.Command;
import org.springframework.shell.command.annotation.Option;

@ShellComponent
@Command
public class MyCommands {

@ShellMethod(key = "hello-world")
@Command(command = "hello-world")
public String helloWorld(
@ShellOption(defaultValue = "spring") String arg
@Option(defaultValue = "spring") String arg
) {
return "Hello world " + arg;
}
Expand Down