The class provides parser of commandline options with built-in help created from a description of the options. It also provides default values for options not set on commandline.

class CmdLineOption

initialize   set?  

initialize(short_name,long_name,argument,description,default = :nil,type = :string)

short_name: short form of the option, for example "-o"

long_name: long form of the option, for example "--option"


description: brief description of the option that appears in the help

default: value provided to the program when the option is not set from commandline. If the option must be set by the user, use CommandLine.check_compulsory to raise error when the option is not found.


set? # => boolean

Query whether the option was set from commandline

class CommandLine

[]   check_compulsory   file_count   from_list   initialize   print_help   require_files   set?  

Public methods

initialize(help_on_files, *option_list)

Creates the CommandLine object from array of CmdLineOptions. The commandline is parsed, default values are used where not provided. If -h option is found, help is displayed and the program is terminated.

require_files(min, max = min)

Check commandline for required number of files.


Goes through array of strings (option's long_name) and terminates with error if they are not present in the commandline


Return number of files (non-option items on commandline)


set?(index) # => boolean

Query whether the option was set from commandline

Private methods

from_list(require_order, *option_list)

Fills the object with options from the list, parsing the commandline.


Displays standard help: command syntax and list of options.