Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion internal/cmd/module/flags.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package module

import "github.com/urfave/cli/v3"
import (
"os"

"github.com/mattn/go-isatty"
"github.com/urfave/cli/v3"
)

var flagModuleID = &cli.StringFlag{
Name: "id",
Expand Down Expand Up @@ -56,3 +61,9 @@ var flagWithGitDir = &cli.BoolFlag{
Name: "with-git-dir",
Usage: "[Optional] Add the .git to the archive, useful when you define custom behavior inside the repository",
}

var flagNoAnimation = &cli.BoolFlag{
Name: "no-animation",
Usage: "[Optional] Disable animated output and print plain text status updates instead. Automatically enabled when the output is not a terminal.",
Value: isatty.IsTerminal(os.Stdout.Fd()),
}
73 changes: 73 additions & 0 deletions internal/cmd/module/local_preview.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ func localPreviewFunc(useHeaders bool) cli.ActionFunc {
return err
}

noAnimation := cliCmd.Bool(flagNoAnimation.Name)
if noAnimation {
return runPlainLocalPreview(ctx, moduleID, triggerMutation.VersionProposeLocalWorkspace)
}

model := newModuleLocalPreviewModel(moduleID, triggerMutation.VersionProposeLocalWorkspace)

go func() {
Expand Down Expand Up @@ -187,6 +192,74 @@ func localPreviewFunc(useHeaders bool) cli.ActionFunc {
}
}

func runPlainLocalPreview(ctx context.Context, moduleID string, initialRuns []runQuery) error {
runs := make([]runQuery, len(initialRuns))
copy(runs, initialRuns)

printRun := func(run runQuery) {
fmt.Printf("%s • %s • %s\n", run.State, run.Title, authenticated.Client().URL(
"/module/%s/run/%s",
moduleID,
run.ID,
))
}

for _, run := range runs {
printRun(run)
}

ticker := time.NewTicker(time.Second * 5)
Comment thread
eliecharra marked this conversation as resolved.
defer ticker.Stop()

for range ticker.C {
newRuns := make([]runQuery, len(runs))
var g errgroup.Group
for i := range newRuns {
index := i
g.Go(func() error {
var getRun struct {
Module struct {
Run runQuery `graphql:"run(id: $run)"`
} `graphql:"module(id: $module)"`
}

if err := authenticated.Client().Query(ctx, &getRun, map[string]interface{}{
"module": graphql.ID(moduleID),
"run": graphql.ID(runs[index].ID),
}); err != nil {
return err
}

newRuns[index] = getRun.Module.Run
return nil
})
}
if err := g.Wait(); err != nil {
return fmt.Errorf("couldn't get runs: %w", err)
}

for i, newRun := range newRuns {
if newRun.State != runs[i].State {
printRun(newRun)
}
}
runs = newRuns

allFinished := true
for _, run := range runs {
if !run.Finished {
allFinished = false
break
}
}
if allFinished {
return nil
}
}

return nil
}

type checkRunsFinishedMsg struct{}

type moduleLocalPreviewModel struct {
Expand Down
2 changes: 2 additions & 0 deletions internal/cmd/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func Command() cmd.Command {
flagDisregardGitignore,
flagWithGitDir,
flagTests,
flagNoAnimation,
},
Action: localPreviewFunc(false),
Before: authenticated.Ensure,
Expand All @@ -90,6 +91,7 @@ func Command() cmd.Command {
flagDisregardGitignore,
flagWithGitDir,
flagTests,
flagNoAnimation,
},
Action: localPreviewFunc(true),
Before: authenticated.Ensure,
Expand Down
Loading