Coder Social home page Coder Social logo

Comments (8)

failshell avatar failshell commented on July 20, 2024

At the very least, it should warn the user about it being ignored.

In the best case, it should follow the usual UNIX tool: flags can be used in any order.

from cli.

mitchellh avatar mitchellh commented on July 20, 2024

I'm going to go with (A) because with git this is an error and it makes it cleaner later to implement top-level flags. Doing this now.

from cli.

fatih avatar fatih commented on July 20, 2024

Im using cli too and the way I use is the b option. It also feels idiomatic because I can pass global flags. Example:

$ foo --no-color subcommand -bar -quz 0

Here --no-color is independent of subcommands. But to do this, I'm all my global flags before I pass it to cli. I even created a package for it, so filtering can be made easily: https://github.com/fatih/flags

Having said that, as seen it complicates things a little bit, so I agree with @mitchellh here, however it's also nice to be able to use global flags, such as --no-color.

from cli.

mitchellh avatar mitchellh commented on July 20, 2024

@fatih Yeah we have some global args for some of our projects as well. We preprocess the os.Args and remove the args that we use, and pass the rest into cli. So this approach will work.

from cli.

mitchellh avatar mitchellh commented on July 20, 2024

Done!

from cli.

fatih avatar fatih commented on July 20, 2024

@mitchellh It seems git allows flags before subcommand.

usage: git [--version] [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           [-c name=value] [--help]
           <command> [<args>]

Any flag before <command> is valid. So I think we should allow flags before commands, though it needs to be known to the cli. I think we should add a feature to allow an extend the current global flags --version and --help. What do you think?

from cli.

mitchellh avatar mitchellh commented on July 20, 2024

@fatih Git allows only global flags. It doesn't allow subcommand flags before it.

I think extending the global flags might be useful, but there are easy workarounds (pre-processing the arg slice for example).

from cli.

fatih avatar fatih commented on July 20, 2024

@mitchellh yeah, I'm saying that --version and --help are both global flags. Just saying we should have a feature so people can add their own global flags. Because it's really tedious to implement it manually by ourselves.

So for example, say for packer the output would be in the form :

usage: packer [--template-path] [--version] [--help] <command> [<args>]

Available commands are:
    build       build image(s) from template
    fix         fixes templates from old versions of packer
    inspect     see components of a template
    push        push template files to a Packer build service
    validate    check that a template is valid
    version     Prints the Packer version

Note the --template-path global flag. This is just an example, but it would have the advantages:

  1. Help would auto generate the global flags
  2. No manual pre-processing of commands are needed, this would be built in
  3. --version and --help wouldn't be the only global flags, people would have the choice to add their own

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.