Git Product home page Git Product logo

Comments (9)

akamensky avatar akamensky commented on May 24, 2024

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.

from argparse.

jkugler avatar jkugler commented on May 24, 2024

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

from argparse.

akamensky avatar akamensky commented on May 24, 2024

@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:

  • Define interface that describes message formatter functionality (for example receive list of strings and produce a single formatted string)
  • Extract current formatting methods into a type like SimpleFormatter that implements this interface
  • Define this SimpleFormatter as default (that is -- it will be used unless explicitly overwritten)
  • Define method for Parser to overwrite default formatter

from argparse.

mieubrisse avatar mieubrisse commented on May 24, 2024

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! :)

from argparse.

jkugler avatar jkugler commented on May 24, 2024

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

from argparse.

akamensky avatar akamensky commented on May 24, 2024

@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.

from argparse.

jkugler avatar jkugler commented on May 24, 2024

@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.

from argparse.

stale avatar stale commented on May 24, 2024

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.

from argparse.

stale avatar stale commented on May 24, 2024

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

from argparse.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.