To be clear: This question is not about how to parse arguments to the program like commons CLI/JCommando etc. does.
I would like to write Unix commands using Java. Although I don't want to write most of the stuff myself, I intend to use libraries and looking for your help to do so.
I found commons cli for parse arguments, like getopt. However I am looking for a last piece of library that works like Perl's diamond operator or Python's fileinput-library.
As unix commands (or GNU commands as I come from Linux) works is that after any flags have been parsed any arguments left are considered files. The command then loops through these files line by line, file by file. A dubble dash (e.g. git checkout -- myfile.txt) is there to separate filenames from arguments. If no arguments are left after parsing all arguments the program should read from standard in instead.
This is what Perl's diamond operator does as well as Python's fileinput library, on very very few lines:
Perl
@ARGV = ("diamond.pl", "stdin.pl");
while (<>) {
print();
}
Python
import fileinput
for line in fileinput.input():
process(line)
Is there a library in Java that does what these do as simple as they do it (a library that basically have the same API as https://docs.python.org/2/library/fileinput.html)? I don't want to write the stuff myself (look for arguments, if not loop through stdin otherwise load each file, preferably lazy, feed each line to the command etc)...I just want the business end, the loop like:
My idea
LineIterator li = new MagicTextLineFeeder(remainingAfterCommonsCliParsing);
for (String line : li.nextRow()) {
System.out.println(line);
}
EDIT: Made it clear that I don't looking for another argument parsing library.