Giter Site home page Giter Site logo

Comments (3)

 avatar commented on June 12, 2024

Hi,

Confirmed that it is not an issue with endless. Minimal test code:

main.go
testlib/testlib.go

Recommended directory structure:

   test/
      main.go
      testlib/
         testlib.go

Then in test:

  • go build -o test test.go
  • ./test -param (application flags are illegal)
  • ./test -libarg (library flags also illegal)

I'm certain this arises from the use of different flag libraries, but I am unable to recommend a fix at this time.

from flag.

namsral avatar namsral commented on June 12, 2024

A library should not mandate the user interface of an application unless it is an UI library.

The flag package is a UI library, the testlib package in your example is not.

It is best practice to pass options in libraries through a public function. Take for example the database/sql package:

import "database/sql"

func main() {
    db, err := sql.Open("postgres", "user=pqgotest dbname=pqgotest sslmode=verify-full")
    …

from flag.

 avatar commented on June 12, 2024

Hi,

The code illustrates that the flag library hijacks the interpretation of flags globally, preventing it from being used with other (possibly UI, according to your terminology) libraries that access flags.

I can accept that this is a fundamental design flaw of the flags (both core and namsral versions) libraries, which access shared global state and interpret it as a rule set. It prevents composition of UI libraries for doing things like what endless attempts, which is attempting to re-fork the executable and pass in an argument indicating a restart rather than a virgin launch. Endless does not use namsral/flag for this; it uses the core library. The core library and namsral/flag can not both be used within the same application. It is as if using a Postgres SQL DB library implicitly prevented you from using a MySQL DB library because they both accessed some global shared state and read the configurations as being incompatible.

So: while I still see this as a fundamental design flaw, I don't disagree with closing the ticket as it isn't the namsral/flag's design flaw. It's just unfortunate that it inherits the flaw.

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.