Skip to content

Commit

Permalink
feat: my potato dagger functions back to works
Browse files Browse the repository at this point in the history
Signed-off-by: Thanabodee Charoenpiriyakij <wingyminus@gmail.com>
  • Loading branch information
wingyplus committed Jun 30, 2024
1 parent a5d33b6 commit 57614df
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
14 changes: 14 additions & 0 deletions potato/dagger/Potato/Dagger_Mod_Attributes.cs
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);
}
13 changes: 13 additions & 0 deletions potato/dagger/Potato/Potato_IEntrypoint.cs
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));
}
}
31 changes: 28 additions & 3 deletions potato/dagger/Potato/Program.cs
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) };
}
}

0 comments on commit 57614df

Please sign in to comment.