-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: my potato dagger functions back to works
Signed-off-by: Thanabodee Charoenpiriyakij <wingyminus@gmail.com>
- Loading branch information
Showing
3 changed files
with
55 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace Dagger.SDK.Mod; | ||
|
||
// TODO: move this to source generator. | ||
/// <summary> | ||
/// An interface for invoking the module class. | ||
/// </summary> | ||
public interface IEntrypoint | ||
{ | ||
/// <summary> | ||
/// Register an object as the root of module. | ||
/// </summary> | ||
/// <returns></returns> | ||
Module Register(Query dag); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Dagger.SDK; | ||
using Dagger.SDK.Mod; | ||
|
||
namespace Potato; | ||
|
||
// TODO: move this to source generator. | ||
public partial class Potato : IEntrypoint | ||
{ | ||
public Module Register(Query dag) | ||
{ | ||
return dag.Module().WithObject(ToObjectTypeDef(dag)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,36 @@ | ||
// QUESTION: is it possible to get generate by source generator? | ||
|
||
using System.Text.Json; | ||
using Dagger.SDK; | ||
using Dagger.SDK.Mod; | ||
|
||
public class Program | ||
{ | ||
public static async Task Main(string[] args) | ||
{ | ||
var dag = Dagger.SDK.Dagger.Connect(); | ||
// NOTE: We're in converting from reflection to source generator state. The module is not working | ||
// at the moment. | ||
// await Dagger.SDK.Mod.Entrypoint.Invoke<Potato.Potato>(dag); | ||
await Invoke<Potato.Potato>(dag); | ||
} | ||
|
||
private static async Task Invoke<T>(Query dag) where T : class, IDagSetter, IEntrypoint, new() | ||
{ | ||
T root = new(); | ||
var fnCall = dag.CurrentFunctionCall(); | ||
var parentName = await fnCall.ParentName(); | ||
// TODO: Get module name to check root type name match with it. | ||
|
||
var result = parentName switch | ||
{ | ||
// TODO: Dagger.SDK should automatic serialize into id. | ||
"" => await root.Register(dag).Id(), | ||
_ => throw new Exception($"{parentName} is not supported at the moment.") | ||
}; | ||
|
||
await fnCall.ReturnValue(IntoJson(result)); | ||
} | ||
|
||
private static Json IntoJson(object result) | ||
{ | ||
return new Json { Value = JsonSerializer.Serialize(result) }; | ||
} | ||
} |