@Command(name = "greet", description = "Greet the user") public class GreetCommand implements CommandHandler { @Override public void execute(CommandContext context) { String name = context.getArgument("name"); System.out.println("Hello, " + name + "!"); } } @Commands public class CommandRegistry { @Command(name = "greet", description = "Greet the user") private final CommandHandler greetCommand; public CommandRegistry() { greetCommand = new GreetCommand(); } } public class Main { public static void main(String[] args) { CommandRegistry commandRegistry = new CommandRegistry(); CommandLineParser parser = new CommandLineParser(commandRegistry); CommandContext context = parser.parse(args); commandRegistry.execute(context); } }


上一篇:
下一篇:
切换中文