如何设置 Spring Boot shell 的默认命令?

问题描述 投票:0回答:1

如何为 Spring Boot Shell 应用程序定义默认命令?

现在我必须进入

java -jar app.jar calculate-cognitive-metrics ".\\src\\main\\java\\"

我想将其更改为

java -jar app.jar ".\\src\\main\\java\\"
,以便它默认执行此命令。

另外,当我尝试运行

java -jar app.jar --help
时,我得到这个
org.springframework.shell.CommandNotFound: No command found for '--help'
而不是帮助输出。我是 Java 和 Spring Shell 的新手,我已经检查过文档,但我真的不知道如何正确配置它来执行我想要的操作。

认知分析应用程序.java

@SpringBootApplication
public class CognitiveAnalysisApplication implements ApplicationRunner {

  public static void main(final String[] args) {
    SpringApplication.run(CognitiveAnalysisApplication.class, args);
  }

  @Override
  public void run(final ApplicationArguments args) throws Exception {
  }
}

ShellCommands.java(摘录)

  @ShellMethod(key = "calculate-cognitive-metrics")
  public void calculateCognitiveMetrics(
      final @ShellOption(defaultValue = "src/main/java") String directoryPath,
      final @ShellOption(defaultValue = "", value = "--html-report") String htmlReport,
      final @ShellOption(defaultValue = "", value = "--csv-report") String csvReport,
      final @ShellOption(defaultValue = "", value = "--json-report") String jsonReport
  ) throws IOException {
spring spring-boot shell command
1个回答
0
投票

在终端中使用此命令:

java -jar app.jar calculate-cognitive-metrics --help

我本地的输出:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/

 :: Spring Boot ::                (v3.3.3)

2024-09-13T09:01:56.437+05:30  INFO 28814 --- [demo-shell] [           main] com.example.DemoShellApplication         : Starting DemoShellApplication v0.0.1-SNAPSHOT using Java 21.0.1 with PID 28814 (/Users/anish/demo-shell-0.0.1-SNAPSHOT.jar started by anish in /Users/anish)
2024-09-13T09:01:56.440+05:30  INFO 28814 --- [demo-shell] [           main] com.example.DemoShellApplication         : No active profile set, falling back to 1 default profile: "default"
2024-09-13T09:01:57.545+05:30  INFO 28814 --- [demo-shell] [           main] com.example.DemoShellApplication         : Started DemoShellApplication in 1.582 seconds (process running for 2.192)
NAME
       calculate-cognitive-metrics -

SYNOPSIS
       calculate-cognitive-metrics --directoryPath String --html-report String --csv-report String --json-report String --help

OPTIONS
       --directoryPath String
       [Optional, default = src/main/java]

       --html-report String
       [Optional]

       --csv-report String
       [Optional]

       --json-report String
       [Optional]

       --help or -h
       help for calculate-cognitive-metrics
       [Optional]
© www.soinside.com 2019 - 2024. All rights reserved.