Comments (6)
Create a new FlagSet when you want to catch the error, working example:
package main
import (
"fmt"
"log"
"os"
"github.com/namsral/flag"
)
func main() {
var (
age int
config string
)
f := flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
f.IntVar(&age, "age", 0, "age value")
f.StringVar(&config, flag.DefaultConfigFlagname, "gopher.conf", "path to config file")
if err := f.Parse(os.Args[1:]); err != nil {
log.Fatal(err)
}
fmt.Print("age:", age)
}
from flag.
I agree, this is unexpected behaviour and therefore a bug.
Can you confirm d6e73b7 from the parse-default-config-file
branch fixes your issue?
from flag.
It does. Kind of. Problem: If the setting file is missing, it goes through without complaining.
from flag.
Please try 71ceffb.
I was going for mainstream cli behaviour; traverse common config paths and silently fail when none are available but that would be out of the scope of this project.
from flag.
In this case 1. it picks up the file if present, 2. it fails if such file is not present (without any error message), and 3. does not allow me to overwrite config file from command line (it does not show --config as option with I do -h).
from flag.
This works exactly how I want. Thanks :-)
from flag.
Related Issues (20)
- `go test -v` stops working HOT 4
- Execution with -h should just print the usage instruction and exit HOT 2
- print error from config file parsing by default HOT 1
- Parse behaviour is wrong when flag contains "-" HOT 1
- lowercase environment variables HOT 1
- prefix for environment variables HOT 6
- Add camel case flag name example to readme
- type alias for Value, Getter etc.
- Is there a way to disable the ConfigFlagname of a FlagSet?
- Release new version
- Support for fixed-size integer types
- Reading individual values from files (eg. docker secrets) HOT 3
- Support for required flag and Default should be optional
- Out of Sync with latest go version - Newer fork available jnovack/flag HOT 2
- Support Multi Value Flags in Config
- Still Maintained?
- Config file parse failure "configuration variable provided but not defined" is not visible to application HOT 2
- Required environment variables is a regression HOT 6
- Running go test with any of the standard flags throws an "flag provided but not defined:" error HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flag.