Git Product home page Git Product logo

Comments (3)

mitchellh avatar mitchellh commented on July 28, 2024

Without having a deeper understanding of the flag package in use (since this library has no opinion on it, it just passes []string), we can’t tell whether -h is a single flag or if baz is an argument to -h. If you’re using the Go standard flag package, its allowed for -h baz to be an argument to -h.

However, this cli library DOES handle -h as a special case (for help). In that case, I think its a valid question if whether this should be help for foo bar baz… and I can see that being totally reasonable.

So, if this issue is talking about flags generally, I don’t think this behavior can be changed. But if we’re talking about the help flag specifically there is something here I think.

Please let me know if I’m misunderstanding.

from cli.

christophermancini avatar christophermancini commented on July 28, 2024

Hey @mitchellh , the issue is focusing on flags generally, not specificallly -h which was used just as an example taken from the test case. I completely understand your point about the trailing argument possibly being an argument for the flag, however, in this case, it is a registered command.

The behavior I am proposing would be to identify foo bar baz as the subcommand when a flag comes before baz, e.g. foo bar --myflag baz, since foo bar baz was registered as a command for the CLI. If the arguments that follow the first flag are not part of a registered command, it continues to behave like it does today.

from cli.

apparentlymart avatar apparentlymart commented on July 28, 2024

FWIW over in Terraform we are intentionally making a distinction between options that appear before the command (global options) and options that appear after the command (command-specific options) and so I think I agree with @mitchellh that making this library itself try to recognize options prior to the command could have adverse affects on existing callers making different assumptions.

In the case of Terraform, we achieve this in a kinda-awkward way of pre-analyzing the original args, noticing the index of the first non-flag argument, and then splitting the args slice into a "global flags" portion and an "everything else" portion. We then pass the global flags portion to the Go flags package and the "everything else" portion to mitchellh/cli. The individual subcommands then in turn separately call the Go flags package again to analyze the command-specific options after mitchellh/cli already did the command handling. Given that, certain changes implemented inside mitchellh/cli might not be breaking for Terraform, since Terraform is already effectively "hiding" the global flags portion from mitchellh/cli.

from cli.

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.