-
Notifications
You must be signed in to change notification settings - Fork 9
/
shellscript.go
53 lines (43 loc) · 1.55 KB
/
shellscript.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright 2022 Namespace Labs Inc; All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
package shellscript
import (
"context"
"google.golang.org/protobuf/proto"
"namespacelabs.dev/foundation/internal/frontend/cuefrontend/entity"
"namespacelabs.dev/foundation/internal/frontend/fncue"
"namespacelabs.dev/foundation/internal/parsing"
"namespacelabs.dev/foundation/schema"
"namespacelabs.dev/foundation/std/pkggraph"
)
// Custom type as CUE -> Proto decoding does not accept camel-case syntax.
type cueShellScriptIntegration struct {
Entrypoint string `json:"entrypoint,omitempty"`
RequiredPackages []string `json:"requiredPackages,omitempty"`
}
type parser struct {
}
func (p *parser) Url() string { return "namespace.so/from-shellscript" }
func (p *parser) Shortcut() string { return "shellscript" }
func (p *parser) Parse(ctx context.Context, env *schema.Environment, pl parsing.EarlyPackageLoader, loc pkggraph.Location, v *fncue.CueV) (proto.Message, error) {
if v != nil {
if str, err := v.Val.String(); err == nil {
// Shortcut: `shellscript: "<filename>"`
return &schema.ShellScriptIntegration{Entrypoint: str}, nil
}
}
var msg cueShellScriptIntegration
if v != nil {
if err := v.Val.Decode(&msg); err != nil {
return nil, err
}
}
return &schema.ShellScriptIntegration{
Entrypoint: msg.Entrypoint,
RequiredPackages: msg.RequiredPackages,
}, nil
}
func NewParser() entity.EntityParser {
return &parser{}
}