Giter Site home page Giter Site logo

not a drop-in replacement about flag HOT 12 CLOSED

namsral avatar namsral commented on June 12, 2024
not a drop-in replacement

from flag.

Comments (12)

namsral avatar namsral commented on June 12, 2024 1

Software is opinionated, namsral/flag is no exception.

from flag.

namsral avatar namsral commented on June 12, 2024

Could you post your code because in my tests your described scenario works.

from flag.

skrassiev avatar skrassiev commented on June 12, 2024

Ok, I inaccurately described the issue:

Main package imports "github.com/namsral/flag" and calls flag.Parse()
Main package imports a third-party "someotherpackage".
someotherpackage package imports just standard "flag" and declares some flags.

github.com/namsral/flag.Parse() would not see flags, declared through standard flag package in someotherpackage.

That's definitely a shortcoming as you don't have control over third-parties.

from flag.

namsral avatar namsral commented on June 12, 2024

The flag package is meant to be used by program developers, not library developers. Third party packages should not depend on the flag package. Package variables should be set via exported variables, functions, the init function, etc.

from flag.

skrassiev avatar skrassiev commented on June 12, 2024

there is no limitation on where the flag package should be used from.

from flag.

namsral avatar namsral commented on June 12, 2024

I beg to differ; as a program developer I would like to have the final say in building the user interface instead of the library developer.

Can you provide me with example where it would be an advantage to include the flag package in a library.

from flag.

sundarv85 avatar sundarv85 commented on June 12, 2024

Hello, I’m also facing a similar issue. But I cannot get my head around on why this happens.

Following is what I do:

  • I’m using goji's -- goji.Serve()
  • I have parameter db-address

When I’m running with namsral/flag - I get the error

flag provided but not defined: -db-address
Usage of ./server:
  -bind="::8000": Address to bind on. If this value has a colon, as in ":8000" or
        "127.0.0.1:9001", it will be treated as a TCP address. If it
        begins with a "/" or a ".", it will be treated as a path to a
        UNIX socket. If it begins with the string "fd@", as in "fd@3",
        it will be treated as a file descriptor (useful for use with
        systemd, for instance). If it begins with the string "einhorn@",
        as in "einhorn@0", the corresponding einhorn socket will be
        used. If an option is not explicitly passed, the implementation
        will automatically select among "einhorn@0" (Einhorn), "fd@3"
        (systemd), and ":8000" (fallback) based on its environment.

This error comes from https://github.com/zenazn/goji/blob/master/bind/bind.go

When I use the golang's default flag, then the error is gone.

Any reason why this goes away when I use default flags.

from flag.

namsral avatar namsral commented on June 12, 2024

Within the goji package replace the flag import with github.com/namsral/flag.

from flag.

ivucica avatar ivucica commented on June 12, 2024

Replacing flag is not trivially doable in every situation. For example, I don't believe I can do it in github.com/golang/glog without forking that package.

from flag.

andrejmaya avatar andrejmaya commented on June 12, 2024

@namsral: I want to use glog in my main go program. When I pass -logtostderr=true -v=2 to my main go app, I get a flag provided but not defined: -logtostderr error message back. I tried to export LOGTOSTDERR=true with no luck.

from flag.

namsral avatar namsral commented on June 12, 2024

It's bad practice to parse command line options in a library. Please see a previous comment on a similar issue.

from flag.

ivucica avatar ivucica commented on June 12, 2024

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.