<dependency>
<groupId>com.xenomachina</groupId>
<artifactId>argparse4k</artifactId>
<version>0.27.1</version>
</dependency>
import com.xenomachina.argparser.ArgParser;
import com.xenomachina.argparser.Option;
public class CommandLineParser extends ArgParser {
@Option(names = { "-h", "--help" }, description = "Prints usage help")
private boolean help;
@Option(names = { "-f", "--file" }, description = "File path")
private String filePath;
// Getters for the options
public boolean isHelp() {
return help;
}
public String getFilePath() {
return filePath;
}
}
public class Main {
public static void main(String[] args) {
CommandLineParser parser = new CommandLineParser();
parser.parse(args);
if (parser.isHelp()) {
parser.usage();
System.exit(0);
}
String filePath = parser.getFilePath();
// Do something with filePath
}
}
java Main --file /path/to/file.txt