mirror of
https://github.com/jlengrand/picocli.git
synced 2026-03-10 08:41:17 +00:00
Polish
This commit is contained in:
committed by
Remko Popma
parent
8ae4b57154
commit
12008cd806
@@ -37,28 +37,12 @@ This will bring in the `info.picocli:picocli` and `org.springframework.boot:spri
|
||||
## Example Application
|
||||
|
||||
```java
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.ExitCodeGenerator;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import picocli.CommandLine;
|
||||
import picocli.CommandLine.IFactory;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan
|
||||
@EnableAutoConfiguration
|
||||
public class MySpringApp implements CommandLineRunner, ExitCodeGenerator {
|
||||
private int exitCode;
|
||||
|
||||
@Autowired
|
||||
IFactory factory; // auto-configured to inject PicocliSpringFactory
|
||||
|
||||
@Autowired
|
||||
MyCommand myCommand;
|
||||
@SpringBootApplication
|
||||
public class MySpringApp {
|
||||
|
||||
@Bean
|
||||
ServiceDependency dependency() {
|
||||
@@ -70,22 +54,44 @@ public class MySpringApp implements CommandLineRunner, ExitCodeGenerator {
|
||||
return new SomeService(dependency);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(String... args) {
|
||||
exitCode = new CommandLine(myCommand, factory).execute(args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getExitCode() {
|
||||
return exitCode;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.exit(SpringApplication.exit(SpringApplication.run(MySpringApp.class, args)));
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
```java
|
||||
import picocli.CommandLine;
|
||||
import picocli.CommandLine.IFactory;
|
||||
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.ExitCodeGenerator;
|
||||
|
||||
public class MyApplicationRunner implements CommandLineRunner, ExitCodeGenerator {
|
||||
|
||||
private final MyCommand myCommand;
|
||||
|
||||
private final IFactory factory; // auto-configured to inject PicocliSpringFactory
|
||||
|
||||
private int exitCode;
|
||||
|
||||
public MyApplicationRunner(MyCommand myCommand, IFactory factory) {
|
||||
this.myCommand = myCommand;
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(String... args) throws Exception {
|
||||
exitCode = new CommandLine(myCommand, factory).execute(args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getExitCode() {
|
||||
return exitCode;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
```java
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
Reference in New Issue
Block a user