3
@Option(name = "-readFromFolder",usage = "specifies a folder containing files to read")
    private String folderName;

The way it works now is that the user has specifies the folder -readFromFolder=/home

I want them to be able to say -readFromFolder and set a default for which to look into, like ${user.home}

Something that works like this, but I ca't figure out the syntax

@Option(name = "-readFromFolder",usage = "specifies a folder containing files to read")
        private String folderName (default=${user.home});
Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
clueless user
  • 1,301
  • 2
  • 11
  • 12

2 Answers2

2

I assume you are using args4j library - it does not support default parameter values. You have to implement it yourself:

private final static String DEFAULT_FOLDER_NAME = "${user.home}";
@Option(name = "-readFromFolder",usage = "specifies a folder containing files to read")
private String folderName;

public String getFolderName() {
    return null == folderName ? DEFAULT_FOLDER_NAME : folderName ;
}
bedrin
  • 4,458
  • 32
  • 53
1

it is feasible to set the default value in the member variable declaration itself instead

@Option(name = "-o", aliases = "--output", usage = "Fully qualified path and name of output JSON file.", required = false)
private String output = "./examples/sample.json"

tested this from command line. seems to work as expected.

sandeepkunkunuru
  • 6,150
  • 5
  • 33
  • 37
  • This makes more sense. You can also see it is intended to be used that way, as args4j will automatically document the default value in `CmdLineParser.printUsage()`, as for example in "Number of requests to perform per action type (default: 10)". – zb226 Jun 30 '23 at 07:42