Giter Site home page Giter Site logo

using config file by default about flag HOT 6 CLOSED

namsral avatar namsral commented on June 12, 2024
using config file by default

from flag.

Comments (6)

namsral avatar namsral commented on June 12, 2024 1

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.

namsral avatar namsral commented on June 12, 2024

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.

amitu avatar amitu commented on June 12, 2024

It does. Kind of. Problem: If the setting file is missing, it goes through without complaining.

from flag.

namsral avatar namsral commented on June 12, 2024

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.

amitu avatar amitu commented on June 12, 2024

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.

amitu avatar amitu commented on June 12, 2024

This works exactly how I want. Thanks :-)

from flag.

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.