GithubHelp home page GithubHelp logo

Parse nested sctructs about go-arg HOT 4 CLOSED

SergeAx avatar SergeAx commented on August 28, 2024 2
Parse nested sctructs

from go-arg.

Comments (4)

alexflint avatar alexflint commented on August 28, 2024 1

Yes I'm open to this. Perhaps using a special prefix tag, like this:

type DBArgs struct {
  User string
  Password string
}

var args struct {
  DB DBArgs `arg:"db."`
}

Note that the prefix includes the dot ".", so you could also do "db-" if you prefer namespacing via hyphens.

As @aspcartman mentioned, this should not break the existing behavior of nested structs, which is to default to no prefix.

from go-arg.

aspcartman avatar aspcartman commented on August 28, 2024

I like the idea, but that will collide with the existing logic for the embedded structs (see the Readme.md) and either become inconsistent:

var args struct {
	DB1 struct {
		User		string
		Password	string
	}
	DB2 struct {
		User		string
		Password	string
	}
}
$ app --user guest # where would "guest" end up?

or break backwards compatibility and require a major version.

May that be solved by a special tag?

from go-arg.

SergeAx avatar SergeAx commented on August 28, 2024

@aspcartman

Currently using structs in go-arg is like this:

type DbArgs struct {
	User	string
	Password string
}

type LogArgs struct {
	Enable	bool
	Level	string
}

var args struct {
	DbArgs
	LogArgs
}

As you can see, it's kinda anonymous (not named).

$ app --user guest # where would "guest" end up?

Nowhere. When using named nested structures you should prepend parameter with struct's name via dot.

from go-arg.

alexflint avatar alexflint commented on August 28, 2024

After considering this some more I think this feature would add too much complexity for how widely it would end up being used. Feel free to re-open this issue if you would like to discuss further.

from go-arg.

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.