Super class of all option's class

Introduced properties

type VALUE: nullable Object

opts :: Option :: VALUE

Type of the value of the option
fun add_aliases(names: String...)

opts :: Option :: add_aliases

Add new aliases for this option
fun default_value: VALUE

opts :: Option :: default_value

Default value of this option
fun default_value=(default_value: VALUE)

opts :: Option :: default_value=

Default value of this option
init defaultinit(help: String, default: VALUE, names: nullable Array[String])

opts :: Option :: defaultinit

Create a new option
fun errors: Array[String]

opts :: Option :: errors

Gathering errors during parsing
protected fun errors=(errors: Array[String])

opts :: Option :: errors=

Gathering errors during parsing
fun helptext: String

opts :: Option :: helptext

Human readable description of the option
protected fun helptext=(helptext: String)

opts :: Option :: helptext=

Human readable description of the option
fun hidden: Bool

opts :: Option :: hidden

Is this option hidden from usage?
fun hidden=(hidden: Bool)

opts :: Option :: hidden=

Is this option hidden from usage?
fun init_opt(help: String, default: VALUE, names: nullable Array[String])

opts :: Option :: init_opt

Init option helptext, default_value and names.
fun mandatory: Bool

opts :: Option :: mandatory

Is this option mandatory?
fun mandatory=(mandatory: Bool)

opts :: Option :: mandatory=

Is this option mandatory?
fun names: Array[String]

opts :: Option :: names

Names for the option (including long and short ones)
protected fun names=(names: Array[String])

opts :: Option :: names=

Names for the option (including long and short ones)
fun pretty(off: Int): String

opts :: Option :: pretty

A pretty print for this help
fun pretty_default: String

opts :: Option :: pretty_default

Pretty print the default value.
fun read: Bool

opts :: Option :: read

Has this option been read?
fun read=(read: Bool)

opts :: Option :: read=

Has this option been read?
protected fun read_param(opts: OptionContext, it: Iterator[String])

opts :: Option :: read_param

Consume parameters for this option
fun value: VALUE

opts :: Option :: value

Current value of this option
fun value=(value: VALUE)

opts :: Option :: value=

Current value of this option

Redefined properties

redef type SELF: Option

opts $ Option :: SELF

Type of this instance, automatically specialized in every class
redef fun to_s: String

opts $ Option :: to_s

An help text for this option with default settings

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
type VALUE: nullable Object

opts :: Option :: VALUE

Type of the value of the option
fun add_aliases(names: String...)

opts :: Option :: add_aliases

Add new aliases for this option
protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
fun default_value: VALUE

opts :: Option :: default_value

Default value of this option
fun default_value=(default_value: VALUE)

opts :: Option :: default_value=

Default value of this option
init defaultinit(help: String, default: VALUE, names: nullable Array[String])

opts :: Option :: defaultinit

Create a new option
fun errors: Array[String]

opts :: Option :: errors

Gathering errors during parsing
protected fun errors=(errors: Array[String])

opts :: Option :: errors=

Gathering errors during parsing
fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun hash: Int

core :: Object :: hash

The hash code of the object.
fun helptext: String

opts :: Option :: helptext

Human readable description of the option
protected fun helptext=(helptext: String)

opts :: Option :: helptext=

Human readable description of the option
fun hidden: Bool

opts :: Option :: hidden

Is this option hidden from usage?
fun hidden=(hidden: Bool)

opts :: Option :: hidden=

Is this option hidden from usage?
init init

core :: Object :: init

fun init_opt(help: String, default: VALUE, names: nullable Array[String])

opts :: Option :: init_opt

Init option helptext, default_value and names.
fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
fun mandatory: Bool

opts :: Option :: mandatory

Is this option mandatory?
fun mandatory=(mandatory: Bool)

opts :: Option :: mandatory=

Is this option mandatory?
fun names: Array[String]

opts :: Option :: names

Names for the option (including long and short ones)
protected fun names=(names: Array[String])

opts :: Option :: names=

Names for the option (including long and short ones)
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
fun pretty(off: Int): String

opts :: Option :: pretty

A pretty print for this help
fun pretty_default: String

opts :: Option :: pretty_default

Pretty print the default value.
fun read: Bool

opts :: Option :: read

Has this option been read?
fun read=(read: Bool)

opts :: Option :: read=

Has this option been read?
protected fun read_param(opts: OptionContext, it: Iterator[String])

opts :: Option :: read_param

Consume parameters for this option
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
fun value: VALUE

opts :: Option :: value

Current value of this option
fun value=(value: VALUE)

opts :: Option :: value=

Current value of this option
package_diagram opts::Option Option core::Object Object opts::Option->core::Object opts::OptionText OptionText opts::OptionText->opts::Option opts::OptionBool OptionBool opts::OptionBool->opts::Option opts::OptionCount OptionCount opts::OptionCount->opts::Option opts::OptionParameter OptionParameter opts::OptionParameter->opts::Option opts::OptionString OptionString opts::OptionString->opts::OptionParameter opts::OptionEnum OptionEnum opts::OptionEnum->opts::OptionParameter opts::OptionInt OptionInt opts::OptionInt->opts::OptionParameter opts::OptionFloat OptionFloat opts::OptionFloat->opts::OptionParameter opts::OptionArray OptionArray opts::OptionArray->opts::OptionParameter privileges::OptionUserAndGroup OptionUserAndGroup privileges::OptionUserAndGroup->opts::OptionParameter opts::OptionString... ... opts::OptionString...->opts::OptionString opts::OptionEnum... ... opts::OptionEnum...->opts::OptionEnum opts::OptionInt... ... opts::OptionInt...->opts::OptionInt opts::OptionFloat... ... opts::OptionFloat...->opts::OptionFloat opts::OptionArray... ... opts::OptionArray...->opts::OptionArray privileges::OptionUserAndGroup... ... privileges::OptionUserAndGroup...->privileges::OptionUserAndGroup

Parents

interface Object

core :: Object

The root of the class hierarchy.

Children

class OptionBool

opts :: OptionBool

A boolean option, true when present, false if not
class OptionCount

opts :: OptionCount

A count option. Count the number of time this option is present
abstract class OptionParameter

opts :: OptionParameter

Option with one parameter (mandatory by default)
class OptionText

opts :: OptionText

Not really an option. Just add a line of text when displaying the usage

Descendants

class OptionArray

opts :: OptionArray

An option with an array as parameter
class OptionEnum

opts :: OptionEnum

An option to choose from an enumeration
class OptionFloat

opts :: OptionFloat

An option with a Float as parameter
class OptionInt

opts :: OptionInt

An option with an Int as parameter
class OptionString

opts :: OptionString

An option with a String as parameter
class OptionUserAndGroup

privileges :: OptionUserAndGroup

Option to ask for a username and group

Class definitions

opts $ Option
# Super class of all option's class
abstract class Option
	# Names for the option (including long and short ones)
	var names: Array[String]

	# Type of the value of the option
	type VALUE: nullable Object

	# Human readable description of the option
	var helptext: String

	# Gathering errors during parsing
	var errors: Array[String] = new Array[String]

	# Is this option mandatory?
	var mandatory: Bool = false is writable

	# Is this option hidden from `usage`?
	var hidden: Bool = false is writable

	# Has this option been read?
	var read: Bool = false is writable

	# Current value of this option
	var value: VALUE is writable

	# Default value of this option
	var default_value: VALUE is writable

	# Create a new option
	init(help: String, default: VALUE, names: nullable Array[String]) is old_style_init do
		init_opt(help, default, names)
	end

	# Init option `helptext`, `default_value` and `names`.
	#
	# Also set current `value` to `default`.
	fun init_opt(help: String, default: VALUE, names: nullable Array[String])
	do
		if names == null then
			self.names = new Array[String]
		else
			self.names = names.to_a
		end
		helptext = help
		default_value = default
		value = default
	end

	# Add new aliases for this option
	fun add_aliases(names: String...) do names.add_all(names)

	# An help text for this option with default settings
	redef fun to_s do return pretty(2)

	# A pretty print for this help
	fun pretty(off: Int): String
	do
		var text = new FlatBuffer.from("  ")
		text.append(names.join(", "))
		text.append("  ")
		var rest = off - text.length
		if rest > 0 then text.append(" " * rest)
		text.append(helptext)
		#text.append(pretty_default)
		return text.to_s
	end

	# Pretty print the default value.
	fun pretty_default: String
	do
		var dv = default_value
		if dv != null then return " ({dv.to_s})"
		return ""
	end

	# Consume parameters for this option
	protected fun read_param(opts: OptionContext, it: Iterator[String])
	do
		read = true
	end
end
lib/opts/opts.nit:17,1--98,3