I have a very simple typescript dagger setup. Basically the hello world of things. I put a object and function in a different folder following the instuctions at https://docs.dagger.io/developer-guide/typescript/370239/module-structure but am having issues calling my subcommand. Is there a specific syntax in order to call command brought in like this?
#How to properly call sub commands?
1 messages Β· Page 1 of 1 (latest)
cc @silver abyss our resident Python SDK expert
The syntax of the dagger call command looks fine. I can't speak to the code of the module. My guess it that the problem is on that side. Are you able to share the code?
This is in the Typescript SDK not Python.
Oops thank you. My brain saw a @ decorator and took a shortcut.
Then copying @latent bough π
Maybe @misty fiber or @proven kernel can point to other modules in Typescript, for quick comparison?
taking a look
In a new dir I did
dagger init --sdk typescript --name motion-ci --source .
dagger call container-echo --string-arg Hi stdout
Which works
Notice in the top image where the module name is "MotionCi" and the function being called by Dagger is "containerEcho"
which is a default function provided by dagger init as an example.
I see in your invocation
so Dagger is looking for an "echo" function
you could add one to your index.ts file
@func()
echo(stringArg: string): Container {
return dag.container().from("alpine:latest").withExec(["echo", stringArg])
}
and then call
Does that help? Then you could move on to calling that first module from another one π
What I was trying to test out with my setup was specifically breaking up my code into mulitple files. The docs at https://docs.dagger.io/developer-guide/typescript/370239/module-structure make it seem like I should be able to break em like I did? Unless I'm just reading those docs incorrectly.
ah, like this?
https://docs.dagger.io/developer-guide/typescript/370239/module-structure/#multiple-files
Yeah exactly.
trying it π
src β€ cp index.ts echo.ts
src β€ cp index.ts grep.ts
# editing to hack the one index file's contents into two
import { dag, Container, Directory, object, func } from "@dagger.io/dagger"
import { Echo } from "./echo" // in src/echo.ts
import { Grep } from "./grep" // in src/grep.ts
Does that setup work on your side?
nope π’ I can't get it to work for me.
I'm no master of TypeScript, but yeah, I tried it like this.
import { dag, Container, Directory, object, func } from "@dagger.io/dagger"
import { Echo } from "./echo" // in src/echo.ts
import { Grep } from "./grep" // in src/grep.ts
@object()
// eslint-disable-next-line @typescript-eslint/no-unused-vars
class MotionCi {}
@field()
echo: Echo = new Echo()
@field()
grep: Grep = new Grep()
}
like docs
and also as a wrapper function. Will look a little harder...
I'm using dagger functions to see if any functions are registered on my Class.
It seems like dagger can see that the inner function command exists. But when I try to call outut in my case, it break just like before.
Ah, could you share how your project is structured. Maybe a repo or a gist and a tree?
I tried with echo in a sub dir as well as at the same level like this, either way, same result.
We'll figure it out and follow up. Thanks for the details!
Wanted to follow up here and see if there were any updates?
Hi, I may be able to help.
That way of doing new Test() in @field looks suspicious to me. If I recall correctly that uses the implicit constructor that gave some issues in initialization so it was changed to require the constructor to be defined explicitly. Correct me if I'm wrong @latent bough, if so the docs need to be updated. @dawn sorrel, try the @func form:
import { object, func } from "@dagger.io/dagger"
import { Echo } from "./echo" // in src/echo.ts
import { Grep } from "./grep" // in src/grep.ts
@object()
class MotionCi {
@func()
echo(): Echo {
return new Echo()
}
@func()
grep(): Grep {
return new Grep()
}
}
Maybe the docs do need to be updated. But the CLI seems to indicate that the way things are setup in docs is right. See my message above with 2 screenshots. The CLI says there is an output command under the Echo command?
Yes, it reports the function but can't execute it. It should either error and not report it, or fix execution.
Either way it's a bug.
And docs should show the @func form instead.
I'll try out the @func form here in just a minute
Yup. That seemed to do the trick! Would you like me to file bugs for the docs issue as well as the issue around that preivous command reporting an error?
Yes, please π
I'm checking this issue right now, I tested that kind of pattern using the @func() decorator and it worked, but I didn't with @field(), I'll add it to my tests cases
Ok I did a quick tests with @func() again, I confirm that it works as expected
// index.ts
import { object, func } from "@dagger.io/dagger"
import { Lint } from './lint';
import { Test } from './test'
@object()
class Obj {
@func()
test(): Test {
return new Test()
}
@func()
lint(): Lint {
return new Lint()
}
}
// test.ts
import { object, func } from "@dagger.io/dagger"
@object()
export class Test {
@func()
echo(): string {
return "world"
}
}
import { object, func } from "@dagger.io/dagger"
@object()
export class Lint {
@func()
echo(): string {
return "world"
}
}
If you have fields with defaults initialization in the constructor, you'll need to specify a constructor in order to init these objects (because it cannot be done from a default value)
import { object, field } from "@dagger.io/dagger"
import { Lint } from './lint';
import { Test } from './test'
@object()
class Obj {
@field()
test: Test = new Test()
@field()
lint: Lint = new Lint()
// Force call the constructor to init objects
constructor() {}
}
However, I found an issue when I tried to call test or lint
Error: could not find result property lint
I know where this comes from, I'll publish a fix today
The PR with the documentation updated: https://github.com/dagger/dagger/pull/6876, I'm working on a fix rn
@upbeat lotus ^to merge asap please π
I see Helder already merged it, so I'm publishing now
published