pborman / getopt Goto Github PK
View Code? Open in Web Editor NEWgetopt style option parsing for Go
License: BSD 3-Clause "New" or "Revised" License
getopt style option parsing for Go
License: BSD 3-Clause "New" or "Revised" License
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
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 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
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?
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.
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
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?
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
Line 75 in 6173d3f
Testing setting a value to a long boolean flag returns the error "invalid value for bool" with the Invalid ErrorCode
Line 21 in 6173d3f
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()
.
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
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!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.