final class Flags extends AnyRef
A simple flags implementation. We support only two formats:
for flags with optional values (e.g. booleans): -flag, -flag=value for flags with required values: -flag[= ]value
That's it. These can be parsed without ambiguity.
There is no support for mandatory arguments: That is not what flags are for.
Flags.apply
adds a new flag to the flag set, so it is idiomatic
to assign instances of Flags
to a singular flag
val:
val flag = new Flags("myapp") val i = flag("i", 123, "iteration count")
Global flags, detached from a particular Flags
instance but
accessible to all, are defined by com.twitter.app.GlobalFlag.
- Alphabetic
- By Inheritance
- Flags
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Instance Constructors
- new Flags(argv0: String)
- new Flags(argv0: String, includeGlobal: Boolean)
- new Flags(argv0: String, includeGlobal: Boolean, failFastUntilParsed: Boolean)
- argv0
The name of the application that is to be configured via flags
- includeGlobal
If true, GlobalFlags will be included during flag parsing. If false, only flags defined in the application itself will be consulted.
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- def add(f: Flag[_]): Unit
Add a flag.
Add a flag. The canonical way to do so is via
Flags#apply
, but this method is left public for any rare edge cases where it is necessary.- f
A concrete Flag to add
- def apply[T](name: String, help: String)(implicit _f: Flaggable[T], m: ClassTag[T]): Flag[T]
Add a named flag with a help message.
Add a named flag with a help message.
- name
The name of the flag.
- help
The help string of the flag.
- def apply[T](name: String, default: => T, help: String)(implicit arg0: Flaggable[T]): Flag[T]
Add a named flag with a default value and a help message.
Add a named flag with a default value and a help message.
- name
The name of the flag.
- default
A default value, as a thunk.
- help
The help string of the flag.
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- def create[T](name: String, default: T, help: String, flaggable: Flaggable[T]): Flag[T]
A Java-friendly method for adding named flags.
A Java-friendly method for adding named flags.
- name
The name of the flag.
- default
A default value.
- help
The help string of the flag.
- def createMandatory[T](name: String, help: String, usage: String, flaggable: Flaggable[T]): Flag[T]
A Java-friendly way to create mandatory flags
A Java-friendly way to create mandatory flags
- name
the name passed on the command-line
- help
the help text explaining the purpose of the flag
- usage
a string describing the type of the flag, i.e.: Integer
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- def formattedFlagValues(includeGlobal: Boolean = this.includeGlobal, classLoader: ClassLoader = this.getClass.getClassLoader): (Iterable[String], Iterable[String])
Formats all values of all flags known to this instance into a format suitable for logging.
Formats all values of all flags known to this instance into a format suitable for logging.
- includeGlobal
See
getAll
above.- classLoader
See
getAll
above.- returns
All of the flag values in alphabetical order, grouped into (set, unset).
- def formattedFlagValuesString(includeGlobal: Boolean = this.includeGlobal, classLoader: ClassLoader = this.getClass.getClassLoader): String
Creates a string containing all values of all flags known to this instance into a format suitable for logging.
Creates a string containing all values of all flags known to this instance into a format suitable for logging.
- includeGlobal
See
getAll
above.- classLoader
Set
getAll
above- returns
A string suitable for logging.
- def getAll(includeGlobal: Boolean = this.includeGlobal, classLoader: ClassLoader = this.getClass.getClassLoader): Iterable[Flag[_]]
Get all of the flags known to this Flags instance.
Get all of the flags known to this Flags instance.
- includeGlobal
If true, all registered GlobalFlags will be included in output. Defaults to the
includeGlobal
settings of this instance.- classLoader
The
java.lang.ClassLoader
used to fetch GlobalFlags, if necessary. Defaults to this instance's classloader.- returns
All of the flags known to this this Flags instance.
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- def parseArgs(args: Array[String], allowUndefinedFlags: Boolean = false): FlagParseResult
Parse an array of flag strings.
Parse an array of flag strings.
- args
The array of strings to parse.
- allowUndefinedFlags
If true, undefined flags (i.e. those that are not defined in the application via a
flag.apply
invocation) are allowed. If false, undefined flags will result in a FlagParseException being thrown.- returns
A com.twitter.app.Flags.FlagParseResult representing the result of parsing
args
.
- def parseOrExit1(args: Array[String], undefOk: Boolean = true): Seq[String]
Parse an array of flag strings or exit the application (with exit code 1) upon failure to do so.
Parse an array of flag strings or exit the application (with exit code 1) upon failure to do so.
- args
The array of strings to parse.
- undefOk
If true, undefined flags (i.e. those that are not defined in the application via a
flag.apply
invocation) are allowed. If false, undefined flags will result in a FlagParseException being thrown.
- def registeredDuplicates: Set[String]
Return the set of any registered duplicated flag names.
Return the set of any registered duplicated flag names.
- Attributes
- protected[twitter]
- def reset(): Unit
- def setCmdUsage(u: String): Unit
Set the flags' command usage; this is a message printed before the flag definitions in the usage string.
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- def usage: String
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
Deprecated Value Members
- def parse(args: Array[String], undefOk: Boolean = false): Seq[String]
Parse an array of flag strings.
Parse an array of flag strings.
- args
The array of strings to parse.
- undefOk
If true, undefined flags (i.e. those that are not defined in the application via a
flag.apply
invocation) are allowed. If false, undefined flags will result in a FlagParseException being thrown.
- Annotations
- @deprecated
- Deprecated
(Since version 6.17.1) Prefer result-value based
Flags.parseArgs
method- Exceptions thrown
FlagParseException
if an error occurs during flag-parsing.- Note
This method has been deprecated in favor of
Flags.parseArgs
, which indicates success or failure by returning com.twitter.app.Flags.FlagParseResult rather than relying on thrown exceptions.