Menu

Constraining to a range

Chris DeGreef

Range constraints apply to the values the user enters on the command-line. The range that you specific for the parameter must be of the same type as the argument itself. So a --range of integers is valid for --type Integer and a --range of Strings is valid for --type String. Values outside of the range will throw an exception.

This example will require the user to enter a value between 20000 and 29999. Ranges are inclusive so 20000 and 29999 are also value.

CmdLine.create("--type integer --key port --range 20000 29999");

> MyProgram --port 21000


Related

Wiki: Compiling

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.