Skip to content

Commit

Permalink
fix(ls): update ls command to support togomak imports
Browse files Browse the repository at this point in the history
  • Loading branch information
srevinsaju committed Sep 5, 2023
1 parent f0b43ca commit bec7608
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pkg/orchestra/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,48 @@ package orchestra
import (
"context"
"fmt"
"github.com/google/uuid"
"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/hclparse"
"github.com/srevinsaju/togomak/v1/pkg/c"
"github.com/srevinsaju/togomak/v1/pkg/meta"
"github.com/srevinsaju/togomak/v1/pkg/pipeline"
"github.com/srevinsaju/togomak/v1/pkg/ui"
"github.com/srevinsaju/togomak/v1/pkg/x"
"os"
"path/filepath"
)

func List(cfg Config) error {
logger := NewLogger(cfg)
parser := hclparse.NewParser()

// TODO: move this to a function
// TODO: reduce duplication
pipelineId := uuid.New().String()
tmpDir := filepath.Join(meta.BuildDirPrefix, "pipelines", "tmp")
err := os.MkdirAll(tmpDir, 0755)
x.Must(err)
tmpDir, err = os.MkdirTemp(tmpDir, pipelineId)
x.Must(err)

// TODO: move this to a function
ctx := context.Background()
cwd := Chdir(cfg, logger)
ctx = context.WithValue(ctx, c.TogomakContextOwd, cfg.Owd)
ctx = context.WithValue(ctx, c.TogomakContextCwd, cwd)
ctx = context.WithValue(ctx, c.TogomakContextPipelineFilePath, cfg.Pipeline.FilePath)
ctx = context.WithValue(ctx, c.TogomakContextTempDir, tmpDir)

dgwriter := hcl.NewDiagnosticTextWriter(os.Stdout, parser.Files(), 0, true)
pipe, hclDiags := pipeline.Read(ctx, parser)
if hclDiags.HasErrors() {
logger.Fatal(dgwriter.WriteDiagnostics(hclDiags))
}

pipe, d := pipeline.ExpandImports(ctx, pipe)
hclDiags = hclDiags.Extend(d)

for _, stage := range pipe.Stages {
fmt.Println(ui.Bold(stage.Id))
}
Expand Down

0 comments on commit bec7608

Please sign in to comment.