#I am trying out constructors and I can't

1 messages · Page 1 of 1 (latest)

wraith kindle
#

just a guess: you shouldn't need to both use Optional[foo] and // +optional. I don't think this will result in any weird double-optional behavior because it just boils down to an optional: true in the backend, but could be worth changing that to see if it fixes it. You could try // +default=17 :

func New(
    // JDK version to download
    // +default=17
    jdkVersion Optional[string],

    // Maven version to download
    // +default=3.9.6
    mavenVersion string,
) *Java {
    return &Java{
        jdkVersion:   jdkVersion,
        mavenVersion: mavenVersion,
    }
}

oh but actually as I typed this out I realized the problem is that the fields are private, so they're not being carried around

#

try renaming those to JDKVersion string and MavenVersion string

woven condor
#

oh boy.. yeah I bet that's it

#

yes that was it. The +optional and +default notation. Is that documented somewhere? I copied the +optional from someone else's code and didn't know it actually had a programmatic relevance. I thought that was just going to decorate the help

#

Still catching up to all the changes since the holidays haha

wraith kindle
#

I was able to find some docs merged here: https://github.com/dagger/dagger/pull/6225 - but can't find where that's been deployed. I don't see it in the docs linked from Daggerverse at least. I know @jovial sand has a big overhaul of those docs in progress though, maybe it'll be included there.

jovial sand
woven condor
#

Hey @jovial sand it will be useful to add an example of // +default flag also or at the minimum point to some documentation explaining how those comment flags work. Same goes for generic Optional

wraith kindle
woven condor
jovial sand
wraith kindle
#

I don't think you really lose much without it

#

The other advantage of //+default is that the default value makes its way into documentation, instead of being purely at runtime