【发布时间】:2020-11-11 08:28:45
【问题描述】:
我一直在尝试在 CLI 上显示格式化文本。我尝试了 picocli docs (doc link) 中提供的完全相同的代码,但似乎没有应用格式。
请帮我找出我的错误。
预期输出
我的代码
import java.util.concurrent.Callable;
import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Help.Ansi;
@Command(name = "test", mixinStandardHelpOptions = true, version = "test 1.0",
description = "Custom @|bold,underline styles|@ and @|fg(red) colors|@.")
public class Interpreter implements Callable<Integer> {
@Override
public Integer call() throws Exception { // your business logic goes here...
String str = Ansi.AUTO.string("@|red Hello, colored world!|@");
System.out.println(str);
return 0;
}
public static void main (String[] args) {
CommandLine prompt = new CommandLine(new Interpreter());
int exitCode = prompt.execute(args);
System.exit(exitCode);
}
我的输出(未应用格式)
PS。我使用 picocli v 4.5.2,将项目导出为 runnable jar,然后使用 .exe 将其构建为Launch4j。 在windows 10的命令提示符下执行结果exe。
【问题讨论】:
标签: command-line-interface picocli