cool-easter-32542
05/24/2023, 2:04 AMclass GlobalOptions(BootstrapOptions, Subsystem):
options_scope = GLOBAL_SCOPE
help = "Options to control the overall behavior of Pants."
@bool_option
class Colors:
default = sys.stdout.isatty()
help = softwrap(
"""
Whether Pants should use colors in output or not. This may also impact whether
some tools Pants runs use color.
When unset, this value defaults based on whether the output destination supports color.
"""
)
which was previously:
colors = BoolOption(
default=sys.stdout.isatty(),
help=softwrap(
"""
Whether Pants should use colors in output or not. This may also impact whether
some tools Pants runs use color.
When unset, this value defaults based on whether the output destination supports color.
"""
),
)
Then rule code needing the option would use:
@rule
def my_rule(colors_container: GlobalOptions.Colors) -> ...:
colors_container.value # known to be type `bool`
# And we'd also have `colors_container.is_default_value` of type `bool`
# instead of `subsystem.options.is_default("<name>")`
This would extend to environment-aware options as well (although the details are fuzzy to me)
pantsbuild/pants