일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- matplotlib
- license delete
- token filter test
- query
- Mac
- Java
- MySQL
- Elasticsearch
- docker
- plugin
- sort
- Test
- 파이썬
- ELASTIC
- TensorFlow
- high level client
- 차트
- flask
- 900gle
- zip 암호화
- analyzer test
- License
- aggregation
- springboot
- zip 파일 암호화
- aggs
- licence delete curl
- Python
- Kafka
- API
Archives
- Today
- Total
개발잡부
[java] picocli java sample 본문
반응형
https://aragost.com/blog/java/picocli-introduction/
maven
pom.xml
<dependency>
<groupId>info.picocli</groupId>
<artifactId>picocli</artifactId>
<version>4.5.1</version>
</dependency>
gradle
gradle.build
// https://mvnrepository.com/artifact/info.picocli/picocli-spring-boot-starter
implementation group: 'info.picocli', name: 'picocli-spring-boot-starter', version: '4.6.3'
package com.curi.log.runner;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.ExitCodeGenerator;
import org.springframework.stereotype.Component;
import picocli.CommandLine;
@Component
public class AppCommandLineRunner implements CommandLineRunner, ExitCodeGenerator {
private final AppCommand appCommand;
private final CommandLine.IFactory factory;
private int exitCode;
public AppCommandLineRunner(AppCommand appCommand, CommandLine.IFactory factory) {
this.appCommand = appCommand;
this.factory = factory;
}
@Override
public void run(String... args) throws Exception {
exitCode = new CommandLine(appCommand, factory).setExitCodeExceptionMapper(appCommand).execute(args);
System.out.println("AppCommandLineRunner");
}
@Override
public int getExitCode() {
return exitCode;
}
}
package com.bbongdoo.doo.runner;
import com.bbongdoo.doo.service.DynamicIndex;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import picocli.CommandLine.*;
import java.io.IOException;
import java.util.concurrent.Callable;
@Component
@Command(name = "java -jar extract.jar", mixinStandardHelpOptions = true,
version = "1.0.0",
description = "extract"
)
@RequiredArgsConstructor
public class AppCommand implements Callable<Integer>, IExitCodeExceptionMapper {
private final DynamicIndex dynamicIndex;
@ArgGroup(exclusive = true, multiplicity = "3", validate = false)
Exclusive exclusive;
@Parameters(index = "0", paramLabel = "Last Name", description = "value:[L]")
private String lastName;
@Parameters(index = "1", paramLabel = "First Name", description = "value:[D]")
private String firstName;
@Parameters(index = "2", paramLabel = "Second Name", description = "value:[H]")
private String secondName;
@Override
public int getExitCode(Throwable exception) {
exception.printStackTrace();
return 0;
}
@Override
public Integer call() throws Exception {
System.out.println("Call");
if (!lastName.equals("L")) {
System.out.println("H 가 아님");
throw new IOException();
}
if (!firstName.equals("D")) {
System.out.println("H 가 아님");
throw new IOException();
}
if (!secondName.equals("H")) {
System.out.println("H 가 아님");
throw new IOException();
}
dynamicIndex.startDynamic();
return ExitCode.OK;
}
static class Exclusive {
@Option(names = {"-l", "--LastName"}, required = true, description = "last name value")
private boolean isLastName;
@Option(names = {"-d", "--FirstName"}, required = true, description = "first name value")
private boolean isFirstName;
@Option(names = {"-h", "--SecondName"}, required = true, description = "second name value")
private boolean isSecondName;
}
}
Program arguments 값 입력
반응형
'JAVA > java' 카테고리의 다른 글
[java] HashMap (0) | 2022.04.01 |
---|---|
CommandLineRunner (2) | 2022.03.22 |
[java] HTTP 통신하기 (0) | 2022.01.18 |
[java] HttpUtils (0) | 2022.01.18 |
Json 파일 읽기 - json.simple (0) | 2022.01.11 |
Comments