Coder Social home page Coder Social logo

Support positional args about args HOT 5 OPEN

dart-lang avatar dart-lang commented on May 28, 2024 12
Support positional args

from args.

Comments (5)

nex3 avatar nex3 commented on May 28, 2024 1

I'm skeptical of adding such a complex and detailed validation API for positional arguments. In my experience, the handling of positional arguments is very idiosyncratic; either it's something very simple like "this takes two or three arguments" or it's something very complicated that isn't worth the hassle of trying to write an API to express. I'd still prefer the much simpler minPositional/maxPositional API I proposed originally in issue 20042.

from args.

gerardsimons avatar gerardsimons commented on May 28, 2024 1

I would personally think I would enjoy more structure around the positional args. I find myself using options just so it is better self-documenting, better structured in the code and with more strict checks.

from args.

seaneagan avatar seaneagan commented on May 28, 2024

The above proposed API is not complex, addPositional(...)/addRest(...) are pretty much exactly like the existing addFlag(...)/addOption(...), and startOptionalPositionals() doesn't even take any arguments. Yet it covers any cases I'm aware of how positional arguments are passed to commands.

@nex3 can you give an example of a command-line interface which this simple API does not handle?

from args.

nex3 avatar nex3 commented on May 28, 2024

The above proposed API is not complex, addPositional(...)/addRest(...) are pretty much exactly like the existing addFlag(...)/addOption(...), and startOptionalPositionals() doesn't even take any arguments. Yet it covers any cases I'm aware of how positional arguments are passed to commands.

Clearly I disagree.

@nex3 can you give an example of a command-line interface which this simple API does not handle?

It doesn't handle things like "zero or two parameters" or "allow this flag only with a positional argument" or "the first positional should be named foo unless there's a second in which case it should be named bar". All of these require extra munging after the arguments have been parsed.

from args.

seaneagan avatar seaneagan commented on May 28, 2024

It doesn't handle things like "zero or two parameters"

Do you have a real world example? Surely there is a better design.

or "allow this flag only with a positional argument"

That's not specific to positional arguments, it's just a special case of "allow this argument only with this other argument".

or "the first positional should be named foo unless there's a second in which case it should be named bar".

So some_command foo or some_command bar baz? foo and bar are sub-commands then, not positional arguments.

All of these require extra munging after the arguments have been parsed.

Again, this is not specific to positional arguments, or even to command-line interfaces. It's just as common with (sets of) named arguments, and with programming language interfaces to have to do "precondition checks" after the arguments have passed the built-in standardized signature checks.

from args.

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.