naydichev
naydichev

Reputation: 4700

Multiple file input, with stdin // Argparse4j, Java

I'm trying to use Argparse4j to build a command line utility. I need to create an option that accepts multiple input files, but also accepts stdin:

        subparser.addArgument("input")                                                                                                                                                                                                                                                                      
                .nargs("*")                                                                                                                                                                                                                                                                                               
                .setDefault(Arrays.asList("-"))                                                                                                                                                                                                                                                                           
                .type(Arguments.fileType().acceptSystemIn().verifyCanRead());                                                                                                                                                                                                                                             

If I don't use Arrays.asList, then sometimes I get just a File object, instead of a List<File>.

However, using nargs("*") also makes it so that I get "-" (as a String) in the list, instead of an actual File object.

Has anyone had any success with something similar?

Upvotes: 1

Views: 275

Answers (1)

Tatsuhiro Tsujikawa
Tatsuhiro Tsujikawa

Reputation: 404

argparse4j does not do any conversion against the value passed by setDefault(). So you need to pass Arrays.asList(new File("-")) to setDefault() to get desired effect.

Upvotes: 1

Related Questions