-
Notifications
You must be signed in to change notification settings - Fork 6
Basics
mosop edited this page Nov 23, 2016
·
11 revisions
[WIP]
The model is a main concept in optarg. Models are used for defining command-line options and arguments. A model is just a Crystal class and inherits the Optarg::Model
class.
class Model < Optarg::Model
end
To define options, call the API methods inside model classes.
class Model < Optarg::Model
string "-s"
end
To parse a command line, call Optarg::Model.parse
.
class Model < Optarg::Model
string "-s"
end
result = Model.parse(%w(-s hello))
To access parsed values, use value accessors or value containers.
class Model < Optarg::Model
string "-s"
end
result = Model.parse(%w(-s hello))
result.s # => hello
result.options[String]["-s"] # => hellp