apple / swift-argument-parser

Straightforward, type-safe argument parsing for Swift
Apache License 2.0
3.31k stars 311 forks source link

Respect the COLUMNS and LINES environment variables when present #596

Closed gwynne closed 10 months ago

gwynne commented 10 months ago

As documented in both the Linux and BSD versions of the environ(7) manpage, many console utilities respect the presence of the COLUMNS and LINES environment variables, treating them as overrides (or, less commonly, fallbacks) of the terminal's reported size (if any). This adds that same behavior to ArgumentParser's screen size logic, affecting the wrapping of the usage generator's output.

Note: These changes follow the semantics of ls(1), where COLUMNS and LINES individually override the values reported by a terminal when they are present. Setting only one of the two variables has no effect on the other. It is also worth noting that at the present time, overriding the screen height (i.e. LINES) has no impact whatsoever on ArgumentParser's behavior.

The new logic only takes effect on non-Windows/WASI platforms.

Checklist

rauhul commented 10 months ago

@swift-ci please test

gwynne commented 10 months ago

This looks great! Any ideas about how to test this? Could we set COLUMNS for some/one of the help generation tests to verify that it gets picked up as the default?

Test added!

natecook1000 commented 10 months ago

@swift-ci Please test

natecook1000 commented 10 months ago

@swift-ci Please test