I need to parse info from command line, so I choose args4j library. Format of command line: ls [-l] [-h] [-r] [-o output.file] directory_or_file.
I've tried to create options and then parse. When I get only "-ls", output is correct, but when I get "-ls -l"(more than 1 argument) the program does not stop and I can enter on the command line until I forcibly stop the program. I will be grateful for any help!
public class Settings {
@Option(name = "-ls", usage = "Init command")
var command = false
@Option(name = "-l", usage = "Long flag")
var longFlag = false
@Option(name = "-h")
var humanReadable = false
@Option(name = "-r")
var reversed = false
}
fun main() {
val settings = Settings()
val parser = CmdLineParser(settings)
var args = mutableListOf<String>()
val input = readLine()
parser.parseArgument(input)
print("${settings.command} ${settings.longFlag}")