Coder Social home page Coder Social logo

Comments (6)

nex3 avatar nex3 commented on May 28, 2024

There are a lot of details with the merging API you're proposing that seem tricky in practice. What happens if the results are from different parsers? What if they both have positional parameters? What if they select different commands? What if the parser relies on callbacks rather than after-the-fact parsing? These aren't necessarily insurmountable, but the fact that the answer is non-obvious makes me wonder if merging ArgResults after the fact is the best way to represent this idea.

In test, we support this by having a separate Configuration class that can be populated using args or by loading from a file. This gives us more flexibility in terms of the configuration file, where CLI flags aren't necessarily the best UI for setting options (test uses YAML instead) and where not all options configurable via CLI make sense. It also gives us a well-typed way of accessing the configuration, and finer-grained control over exactly how options are merged between different sources.

It is hard for a user to merge each List<String> before parsing them

Can you go into more detail about why this is difficult?

from args.

srawlins avatar srawlins commented on May 28, 2024

Merging the List<String>s manually before parsing them with ArgParser is hard because you have to parse them anyways. You might have flag --force with a short value -f, and then you might have --force on the cmdline and -f from another source, and you're just re-writing the package:args parser.

I'd be happy with the following constraints on such a merge (which could be relaxed later if demand arises):

  • Must come from same ArgParser
  • Must not include positional parameters, or maybe just that other's values overwrite this's values.
  • Maybe different commands don't matter?
  • Callbacks might be tricky... On the face of it, they're just not run again? Probably not a good idea to use callbacks if you're going to merge?

from args.

nex3 avatar nex3 commented on May 28, 2024

Merging the List<String>s manually before parsing them with ArgParser is hard because you have to parse them anyways. You might have flag --force with a short value -f, and then you might have --force on the cmdline and -f from another source, and you're just re-writing the package:args parser.

Can't you just concatenate the lists? args can handle multiple instances of the same argument; it'll just overwrite the value if necessary.

from args.

natebosch avatar natebosch commented on May 28, 2024

@srawlins has this come up again since you filed the request?

I do think that concatenating the args should work in the limited cases we are likely to be able to support here, and that for more complicated cases you'd need to handle conflicts and everything with application specific logic.

from args.

srawlins avatar srawlins commented on May 28, 2024

I don't think so. I'm not certain which project triggered this request, 4 years ago :/

from args.

natebosch avatar natebosch commented on May 28, 2024

Closing for now until we find a current use case.

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.