OptionSetBuilder

Builder for creating command-line set options with various configurations and constraints.

This class provides a fluent API for defining set options that can collect unique values, including type refinements, constraints, environment variable support, and help text. Sets preserve insertion order but ensure uniqueness.

Functions

Link copied to clipboard

Creates an arity option for sets where each invocation consumes exactly n values.

Link copied to clipboard
open override fun atLeast(n: Int): OptionSetBuilder<T>

Requires this set option to have at least the specified number of unique values. This constraint is validated after parsing completes.

Link copied to clipboard
open override fun atLeastOneWith(vararg refs: KProperty<*>): OptionSetBuilder<T>

Creates an "at least one" constraint with other options. At least one option from this group (including this option) must be provided.

Link copied to clipboard
open override fun atMostOneWith(vararg refs: KProperty<*>): OptionSetBuilder<T>

Creates an "at most one" constraint with other options. At most one option from this group (including this option) may be provided.

Link copied to clipboard
open override fun conflictsWith(vararg refs: KProperty<*>): OptionSetBuilder<T>

Specifies that this set option conflicts with other options. If this option is provided along with any of the conflicting options, parsing will fail with an error.

Link copied to clipboard
open override fun exactlyOneWith(vararg refs: KProperty<*>): OptionSetBuilder<T>

Creates an "exactly one" constraint with other options. Exactly one option from this group (including this option) must be provided.

Link copied to clipboard

Sets the help text for this collection option. The help text is displayed when the user requests help information.

Link copied to clipboard

Marks this collection option as hidden from help output. Hidden options are not displayed in help text but remain functional.

Link copied to clipboard
open override fun onlyInDomains(vararg refs: KProperty<*>): OptionSetBuilder<T>

Restricts this set option to only be available in specific domains. When specified, this option will only be recognized when one of the referenced domains is active.

Link copied to clipboard
fun onValue(callback: (T) -> Unit): CollectionOptionBuilder<T, Set<T>>

Registers a callback to be executed when this collection option's values are found during parsing. The callback receives each converted value and is executed after all parsing and validation completes. For collection options, the callback is called once for each element in the collection.

Link copied to clipboard
open operator override fun provideDelegate(thisRef: Arguments, property: KProperty<*>): ReadOnlyProperty<Arguments, Set<T>>

Provides the property delegate implementation for collection options. This method is called automatically by Kotlin's property delegation system. It registers the option with the Arguments instance and returns a delegate that provides access to the parsed collection value.

Link copied to clipboard

Marks this set option as required, equivalent to atLeast(1).

Link copied to clipboard
open override fun requireIfAllPresent(vararg refs: KProperty<*>): OptionSetBuilder<T>

Makes this set option required if all of the referenced options are present. This creates a conditional requirement where providing all of the trigger options makes this option mandatory.

Link copied to clipboard
open override fun requireIfAnyPresent(vararg refs: KProperty<*>): OptionSetBuilder<T>

Makes this set option required if any of the referenced options are present. This creates a conditional requirement where providing any of the trigger options makes this option mandatory.

Link copied to clipboard
fun validate(vararg validations: Pair<String, (T) -> Boolean>): OptionSetBuilder<T>

Adds multiple element validators at once.

open override fun validate(message: String, predicate: (T) -> Boolean): OptionSetBuilder<T>

Adds a validator that checks each element in the set against the given predicate.

Link copied to clipboard
open override fun validateCollection(message: String, predicate: (Set<T>) -> Boolean): OptionSetBuilder<T>

Adds a validator that checks the entire set against the given predicate.