Coder Social home page Coder Social logo

flag's People

Contributors

0xflotus avatar cosiner avatar zhuah avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flag's Issues

How to end greedy-consume arguments?

Given:

type flags struct {
   Something []string `names:"-s" usage:"pass in something(s)"`
   Rest      []string `args:"true"`
}

how does the user end the greedy consumption of -s and provide non-flag arguments? E.g., a common pattern in flag parsing libraries requires multi-value argument flags to be specified once for each argument:

cmd -s A -s B -s C XYZ

would produce len(a.Something) == 3 and a.Rest == []string{"XYZ"}. If multi-value arguments are greedy, len(a.Something) == 4 and a.Rest == []string{}.

How does a user pass in arguments to Rest with greedy consumption?

How deep can I nest the structs?

It looks like the 3rd nested structs aren't visible. Example:

type Arguments struct {
	Index struct {
		Enable bool

		Full struct {
			Enable bool

			// This is not visible
			List struct {
				Enable bool
			}

			// This is not visible as well
			Syncto struct {
				Enable bool

				Cassandra struct {
					Enable bool
					All    bool `names:"--all" default:"true" desc:"Just sync everything from Redis to Cassandra"`
				}
			}
		}
	}
}

This is the error I got:

go run -race main.go index full list
StandaloneValue: standalone value without flag: [main index full] list

Unable to have negative value

This should work: go run main.go logs --from "-1d" /var/log/messages

But it doesn't. Here's the error log:

StandaloneFlag: standalone flag without values: [main logs].--from

Does this support implied flags, like tar?

'-' to ensure next argument must be a flag

That seems to imply that implied flags will work here the same as they do with tar:

tar -xvf test.tar.gz
tar xvf test.tar.gz

Is that true?

Add support for mandatory flags

Hi,

Maybe I missed something, but I couldn't find a way to declare mandatory settings.

It would be great to have such feature implemented.

Regards

README example missing package name

Hi, I'm not sure how it compiles, but your example refers to flag.Flag as simply Flag, which was confusing on the first read. Otherwise, looks like a neat API and is currently on my shortlist for consideration :)

Add positional tag

Is a good idea add a tag for setting postitional arguments. For example:

type Args struct {
	Version string `names:"-v" usage:"Version"`
	Pos     string `names:"positional" positional:"true" usage"positional flag"`
}

Result would be:

Usage:
    cmd [FLAG] [positional]...

Flags:
      -v               Version
      -h, --help   show help

Positional flags:
    positional    positional flag

4 level deep struct breaks again on the latest commit.

Works here: d92f27a

Stop working here: e5854e4

Example config struct:

type Arguments struct {
    Config string `names:"-c" default:"." desc:"Path to config directory"`

    Index struct {
        Enable bool

        Full struct {
            Enable bool

            List struct {
                Enable   bool
                Unsynced bool `names:"--unsynced" default:"false" desc:"Display only unsynced metric indices"`
            }

            Syncto struct {
                Enable bool

                Storage struct {
                    Enable   bool
                    Unsynced bool `names:"--unsynced" default:"false" desc:"Sync only unsynced metric indices"`
                }
            }
        }

        Short struct {
            Enable bool

            List struct {
                Enable   bool
                Unsynced bool `names:"--unsynced" default:"false" desc:"Display only unsynced metric indices"`
            }

            Syncto struct {
                Enable bool

                Storage struct {
                    Enable   bool
                    Unsynced bool `names:"--unsynced" default:"false" desc:"Sync only unsynced metric indices"`
                }
            }
        }
    }
}

Error:

go run main.go index short syncto storage
StandaloneValue: standalone value without flag: [main index short syncto] storage

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.