GithubHelp home page GithubHelp logo

Positional arguments about go-flags HOT 6 CLOSED

jessevdk avatar jessevdk commented on August 24, 2024 1
Positional arguments

from go-flags.

Comments (6)

jessevdk avatar jessevdk commented on August 24, 2024 3

Ok, I've finally come around to implementing this. It works a bit differently than suggested though. You can now specify a tag positional-args:"true" on a struct field which then makes the struct members being parsed as the positional arguments, in order. A slice field automatically gets all the rest arguments appended. See also the example in the docs for how to use this.

from go-flags.

jessevdk avatar jessevdk commented on August 24, 2024

Not really, it seems too trivial. You can just do:

LocalPath, RemoteUrl, Tags := args[0], args[1], args[2:]

from go-flags.

tobstarr avatar tobstarr commented on August 24, 2024

Yes, you can but e.g. args[2:] breaks badly if your slice is not long enough. So you would need some (boilerplate) checking if the non-flag arguments have a specific length. This could be done in the same way it is done with the flags (validations, type conversions, min/max for slice types etc).

But I was just curious.

from go-flags.

jessevdk avatar jessevdk commented on August 24, 2024

Ok sure. Personally, I never really write applications with have a specific order of positional arguments as it always seems to be hard to remember their order, and thus I much prefer flags. That said, I can see how it's a matter of opinion. Let's say, patches are welcome :)

from go-flags.

tobstarr avatar tobstarr commented on August 24, 2024

Normally I also prefer flagged arguments. There are some cases where positional (especially of type slice) make sense. I am looking at the whole familiy of ec2 cli tools (like ec2-describe-instances id [id...], ec2-terminate-instances id [id...], etc)

from go-flags.

jessevdk avatar jessevdk commented on August 24, 2024

Well, args is also a slice! ec2-describe-instances doesn't seem like a particularly good example of why you would need more support for positional arguments.

from go-flags.

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.