akamensky / argparse

Argparse for golang. Just because `flag` sucks
MIT License
604 stars 62 forks source link

Provide ability to configure helptext maxWidth columns #91

Closed mieubrisse closed 2 years ago

mieubrisse commented 3 years ago

The usage helptext is currently very cramped, at 80 maximum characters ( https://github.com/akamensky/argparse/blob/master/argparse.go#L647 ):

Screen Shot 2021-09-18 at 2 58 36 PM

It would be great if this were configurable

akamensky commented 3 years ago

80 characters is a default terminal width, it has been standard for headless servers terminals for years and still is used everywhere.

FYI, if you don't use very long path and very long argument names, it will look perfectly fine.

I don't think this should touch existing help message formatting, otherwise it will break compatibility. Better option is to introduce override formatter, so that anyone can just provide their own formatting functionality if they wish so.

PRs are welcome for formatter override.

jkugler commented 3 years ago

As far as I know, most help formatters query the terminal (If $ISTTY is true) to find the width, and use that.

akamensky commented 3 years ago

@jkugler while that is correct, there are many cases when those fail to detect width correctly, where you will have then lines extending beyond the visible display area. And correct screen width detection is out of scope for this library I think.

I think would be good to have a way to configure help formatting in some flexible way. Current approach is a bit too tightly coupled with internals.

I think good backward compatible solution would be:

mieubrisse commented 3 years ago

I'd add a +1 to @jkugler 's terminal detection. Speaking from firsthand experience, I know how nasty working with the terminal can be, but it seems like both argparse and argparse4j do it so would definitely be very helpful in this Go port! :)

jkugler commented 3 years ago

Python's argparse "cheats" as it uses a function from another module, but it does do it: https://github.com/python/cpython/blob/main/Lib/argparse.py#L170

akamensky commented 3 years ago

@mieubrisse To clarify. This is not a port of Python's argparse. This library merely inspired by the usability of it.

The goal of this library is to keep it very simple to use, with no external dependencies.

There are many alternative libraries that do a lot more in CLI.

jkugler commented 3 years ago

@akamensky I understand it's not a port. I was just pointing out that 1) the Python version does it, and 2) it does, in fact, rely on an external library, but it just so happens that "external library" is in its own stdlib, so it doesn't have to install anything extra.

So, in your case, unless Go's stdlib has something similar, yes, it would introduce an additional dependency.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed soon if no further activity occurs. Thank you for your contributions. Feel free to comment or otherwise update to keep it alive.

stale[bot] commented 2 years ago

Closing due to old age. Feel free to re-open or ping maintainers.