@@ -2,24 +2,45 @@ package module
22
33import (
44 "fmt"
5+ "os"
56 "strings"
67
78 "github.com/input-output-hk/catalyst-forge/cli/pkg/run"
9+ "github.com/input-output-hk/catalyst-forge/lib/project/deployment"
10+ "github.com/input-output-hk/catalyst-forge/lib/project/schema"
811)
912
1013type TemplateCmd struct {
11- Module string `arg:"" help:"The path to the module (or project)." kong:"arg,predictor=path"`
14+ Path string `arg:"" help:"The path to the module (or project)." kong:"arg,predictor=path"`
1215}
1316
1417func (c * TemplateCmd ) Run (ctx run.RunContext ) error {
15- project , err := ctx . ProjectLoader . Load (c .Module )
18+ stat , err := os . Stat (c .Path )
1619 if err != nil {
17- return fmt .Errorf ("could not load project : %w" , err )
20+ return fmt .Errorf ("could not stat path : %w" , err )
1821 }
1922
20- modules := project .Blueprint .Project .Deployment .Modules
23+ var bundle schema.DeploymentModuleBundle
24+ if stat .IsDir () {
25+ project , err := ctx .ProjectLoader .Load (c .Path )
26+ if err != nil {
27+ return fmt .Errorf ("could not load project: %w" , err )
28+ }
29+
30+ bundle = project .Blueprint .Project .Deployment .Modules
31+ } else {
32+ src , err := os .ReadFile (c .Path )
33+ if err != nil {
34+ return fmt .Errorf ("could not read file: %w" , err )
35+ }
36+
37+ bundle , err = deployment .ParseBundle (src )
38+ if err != nil {
39+ return fmt .Errorf ("could not parse module file: %w" , err )
40+ }
41+ }
2142
22- result , err := ctx .DeploymentGenerator .GenerateBundle (modules )
43+ result , err := ctx .DeploymentGenerator .GenerateBundle (bundle )
2344 if err != nil {
2445 return fmt .Errorf ("failed to generate manifests: %w" , err )
2546 }
0 commit comments