Giter Club home page Giter Club logo

getopt's People

Contributors

bormanp avatar ib-steffen avatar jmahler avatar pborman avatar pgier avatar ryjen avatar tractaylor 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

getopt's Issues

Add version to PrintUsage output

I would like to see an option or variable defined to allow for the code version 
to show up in the output, maybe something like:
getopt.Version = "2.5.1"


Original issue reported on code.google.com by [email protected] on 25 Nov 2014 at 5:45

Flags don't parse after encountering positional parameter

Based on what I've read in the documentation I would expect the following to work, but I might have misconfigured something. Essentially I would like to support syntax like what git exposes, ala git status --short command.

Here's some sample code:

	connection := ""
	migrations := ""

	getopt.FlagLong(&connection, "connection", 'c', "SQL connection string")
	getopt.FlagLong(&migrations, "migrations", 'm', "Migrations directory")

	getopt.Parse()

	config := MigConfig{
		Connection: connection,
		Migrations: migrations,
	}

	args := getopt.Args()

	fmt.Println("CONFIG")
	fmt.Println(config)
	fmt.Println("ARGS")
	fmt.Println(args)

	return config, nil

Next, I'm invoking the program in two ways:

$ app status --connection="foo"    
CONFIG
{ }
ARGS
[status --connection=foo]

$ app --connection="foo" status
CONFIG
{foo }
ARGS
[status]

The second invocation works as expected, pulling the flag data out and providing the remaining non-flag arguments via .Args(). However the first invocation, in the style of the git command, wasn't able to parse the flags. Have I configured this wrong or is this expected behavior?

Go 1.15: error messages changed so test is failing

Go 1.15 rc 1 on Fedora Rawhide:

Testing    in: /builddir/build/BUILD/getopt-ee0cd42419d3adee9239dbd1c375717fe482dac7/_build/src
         PATH: /builddir/build/BUILD/getopt-ee0cd42419d3adee9239dbd1c375717fe482dac7/_build/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sbin
       GOPATH: /builddir/build/BUILD/getopt-ee0cd42419d3adee9239dbd1c375717fe482dac7/_build:/usr/share/gocode
  GO111MODULE: off
      command: go test -buildmode pie -compiler gc -ldflags "-X github.com/pborman/getopt/version.commit=ee0cd42419d3adee9239dbd1c375717fe482dac7 -X github.com/pborman/getopt/version=0 -extldflags '-Wl,-z,relro -Wl,--as-needed  -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld '"
      testing: github.com/pborman/getopt
github.com/pborman/getopt
--- FAIL: TestDuration (0.00s)
    duration_test.go:64: duration_test.go:40: got error "test: time: missing unit in duration \"1\"\nUsage: test [-d value] [--duration value] [parameters ...]\n", want "test: time: missing unit in duration 1\n"
    duration_test.go:64: duration_test.go:46: got error "test: time: invalid duration \"foo\"\nUsage: test [-d value] [--duration value] [parameters ...]\n", want "test: time: invalid duration foo\n"
FAIL
exit status 1
FAIL	github.com/pborman/getopt	0.003s

Is this package abandoned?

I notice there has been no activity for a couple of years and that Issues persist for years without a response from the maintainer.

Is this package abandoned?

Optional long flags do not accept values after space, only with '='

Hi
Using this declaration:

getopt.FlagLong(&calendar, "calendar", 'c', "Filter events of a specified calendar").SetOptional()

If I call the program like this

prog --calendar "test"

it doesn't parse the argument. Only if I use the equal sign:

prog --calendar="test"

While if I remove .SetOptional() it works fine. Is it a forethought feature or a possible bug? The README mentions that it should work this way.

Variables to contorl help formatting do not always work

Setting these variables:

getopt.HelpColumn = 25
getopt.SetParameters("")

Only take effect when you manually bring out the usage with:
getopt.Usage()

They do not seem to have any impact when the Usage is displayed due to an error 
or a missing argument to a parameter  

Original issue reported on code.google.com by [email protected] on 9 Dec 2014 at 3:57

Required parameters

After looking through the documentation, source code, and spending a fair amount of time trying to find anything useful on Google, I'm still unsure how to bring required arguments from the command-line along with optional flags/values.

I'm using os.Args. The flags/values seem to be ignored if they're provided last but obviously used as the initial arguments if provided first. How are we supposed to do this?

ExtraParameter ErrorCode is never set

It seems that the ErrorCode ExtraParameter "a value was set to a long flag" is never being set.

The related function extraArg is referenced nowhere

func extraArg(o Option, value string) *Error {

Testing setting a value to a long boolean flag returns the error "invalid value for bool" with the Invalid ErrorCode

getopt/bool.go

Line 21 in 6173d3f

return fmt.Errorf("invalid value for bool %s: %q", opt.Name(), value)

IsSet crashes on unknown option names

Querying (*Set).IsSet() for a flag name not actually defined causes a nil ptr crash instead of returning false.

I'm unable to provide demo code (much less a fix) due to CLA conflicts; hopefully this is enough of a report. I'm working around it for now by using .VisitAlI().

Simple README update

While reading over the documentation, I found a simple error. I found a sentence that had "... and and...". I believe the text should say "...a and b..."
In vim, its line 168 in the readme file. And I have attached a sceen shot as well. I will be opening a pull request

screen shot 2018-05-29 at 9 57 16 pm

Also, this is my first time to contribute to this project and I did create a Contributing License Agreement, but not sure what to do with it.

thanks!

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.