#like for codegen

1 messages ยท Page 1 of 1 (latest)

tidal forge
#

Oh I didn't mention, yesterday I mostly managed to switch the manual code I made against the API to codegen

#

The old tests still pass, but now I can use ALL of the API

#
api := New()
// FIXME: use scratch instead
dir := api.Git("github.com/dagger/dagger").
    Branch("cloak").
    Tree()

contents, err := dir.
    WithNewFile("/hello.txt", "world").
    File("/hello.txt").
    Contents(ctx)

require.NoError(t, err)
require.Equal(t, "world", contents)
#

Still a bunch of crap to figure out, but it's getting there

#

we should get the container API "for free" as soon as we merge your PR

vestal cipher
#

oh sick

tidal forge
#

I was thinking of using the ContentOpt pattern but that's a bit hard to generate (especially to avoid name clashes)

Also, not sure how good it is for discoverability, as you mentioned

#

I'll do something simple for now and then we can all chime in

#

Also will like your opinion since you have a bunch of experience with language parsing on bass -- the next step would be to generalize this a bit and generate bindings for ts/js/python/etc

vestal cipher
#

i'm not sure how much of my bass experience will really transfer, but i'm always interested in this kind of thing ๐Ÿ™‚

tidal forge
#

@signal hazel I implemented the visitor pattern of the JS tool you mentioned, it should be doable to support other languages and reusing common bits

vestal cipher
#

now i want to write the tests like this, but that's probably flying too close to the sun

tidal forge
#

a little bit ๐Ÿ™‚

#

I don't know yet if we should bundle the core API in the SDK (one off gen) or if the user should always generate on their end

#

(including the extensions)

#

I think if we bundle, we're going to hit type mismatches e.g. go.dagger.io/sdk/go/dagger/core.Container will clash with github.com/aluzzardi/myproject/api.Container (and e.g. the codegen netlify bindings will output a myproject/api.Container rather than core.Container)

tidal forge
signal hazel
signal hazel
tidal forge
#

yeah. maybe we can bundle it in internal/core for ourselves

#

tests and stuff

#

oh btw, for now I added a dumb command:

//go:generate cloak client-gen -o ./api/api.gen.go
#

it's funny how server generation will go away and client gen come back ... classic codegen switcheroo

signal hazel
tidal forge
signal hazel
#

But none of that matters right now

tidal forge
#

right now I like the simplicity of not being containerized. It's hard as it is to debug ๐Ÿ˜‚

#

this is the error I'm getting after the rebase: expected declaration, found Null. Wish me luck

signal hazel
#

Oh totally, not something we have to go right back to. But there is also appeal in the codegen being an API like it is today. Could download generated clients from your browser and stuff like that

tidal forge
#

@signal hazel ah crap. Remember the graphql-go problem where stuff is returned in random order?

tidal forge
#

it's killing me

func (r *Directory) WithNewFile(path string, contents string) *Directory {

sometimes path and contents get swapped

#

and like, this is bad. Not a build error

signal hazel
tidal forge
#

hmmm ...

#

that actually might be worse

#

if they're sorted, instead of returned as declared

#

I mean, I can sort it myself

tidal forge
#

which is not what the API intended

#

ugh

signal hazel
#

Oh right