generated from layer5io/layer5-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 191
Expand file tree
/
Copy pathgenerator.go
More file actions
45 lines (39 loc) · 1.18 KB
/
generator.go
File metadata and controls
45 lines (39 loc) · 1.18 KB
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
package generators
import (
"fmt"
"github.com/meshery/meshkit/generators/artifacthub"
"github.com/meshery/meshkit/generators/github"
"github.com/meshery/meshkit/generators/models"
"github.com/meshery/meshkit/utils"
)
const (
artifactHub = "artifacthub"
gitHub = "github"
)
type GeneratorOptions struct {
Recursive bool
MaxDepth int
Extensions []string
}
func NewGenerator(registrant, url, packageName string) (models.PackageManager, error) {
return NewGeneratorWithOptions(registrant, url, packageName, GeneratorOptions{})
}
func NewGeneratorWithOptions(registrant, url, packageName string, opts GeneratorOptions) (models.PackageManager, error) {
registrant = utils.ReplaceSpacesAndConvertToLowercase(registrant)
switch registrant {
case artifactHub:
return artifacthub.ArtifactHubPackageManager{
PackageName: packageName,
SourceURL: url,
}, nil
case gitHub:
return github.GitHubPackageManager{
PackageName: packageName,
SourceURL: url,
Recursive: opts.Recursive,
MaxDepth: opts.MaxDepth,
Extensions: opts.Extensions,
}, nil
}
return nil, ErrUnsupportedRegistrant(fmt.Errorf("generator not implemented for the registrant %s", registrant))
}