Curious little issue I am running into here:
I would like a client to be able to do something like:
(1) java -jar myJar.jar inputFile outputFile
or
(2) java -jar myJar.jar text outputFile
outputFile is an optional argument.
Essentially (1) will read input from a file for them, while (2) they provide the input my program will use directly. There is no way to determine whether or not the argument is the input or whether it is the location of the file though that I can think of. For normal command line stuff you would specify a flag like -i inputfile to show you want it to read from a file. What are my options here that maintain ease of use for the client?
Is my only option to create a syntax the client must use for the first argument? i.e.
"-t text" or "-i inputFile"?
I have seen libraries such as commons cli which would enable this, but I would prefer a solution that does not involve using a library.
If I understood the problem correctly, can’t you just check the number of arguments instead of explicitly specifying direct input? Like, if one arg is passed the first arg is output, and if 2 args are passed then the first arg is input and the second arg is output?
With that being said – Using a ‘option’ syntax of the hyphen- kind is probably easiest on most people used to a cli.