Skip to content

Commit

Permalink
bt: Enable color support
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidGamba committed Oct 9, 2024
1 parent b8b6b36 commit 29560d6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bt/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/DavidGamba/dgtools/cueutils v0.4.0
github.com/DavidGamba/dgtools/fsmodtime v0.3.0
github.com/DavidGamba/dgtools/run v0.9.0
github.com/DavidGamba/go-getoptions v0.30.1-0.20241002032243-d527aa6a4344
github.com/DavidGamba/go-getoptions v0.30.1-0.20241009060655-4dc86a827dae
github.com/hashicorp/terraform-config-inspect v0.0.0-20240801114854-6714b46f5fe4
github.com/mattn/go-isatty v0.0.20
)
Expand Down
2 changes: 2 additions & 0 deletions bt/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ github.com/DavidGamba/go-getoptions v0.30.0 h1:8x69Fc8k/mEWVE0GknpwQ3uGj56MXOUp1
github.com/DavidGamba/go-getoptions v0.30.0/go.mod h1:zE97E3PR9P3BI/HKyNYgdMlYxodcuiC6W68KIgeYT84=
github.com/DavidGamba/go-getoptions v0.30.1-0.20241002032243-d527aa6a4344 h1:KcopOyEKx9IjD0w4u+KeI84inHzgPTyIYDIR/TPFi4E=
github.com/DavidGamba/go-getoptions v0.30.1-0.20241002032243-d527aa6a4344/go.mod h1:zE97E3PR9P3BI/HKyNYgdMlYxodcuiC6W68KIgeYT84=
github.com/DavidGamba/go-getoptions v0.30.1-0.20241009060655-4dc86a827dae h1:/1OeLSWK0iuzuHe5jw2NWVpfZV5CETpV8Hz4TJnSO7w=
github.com/DavidGamba/go-getoptions v0.30.1-0.20241009060655-4dc86a827dae/go.mod h1:zE97E3PR9P3BI/HKyNYgdMlYxodcuiC6W68KIgeYT84=
github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo=
github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew1u1fNQOlOtuGxQY=
Expand Down
7 changes: 7 additions & 0 deletions bt/stack/dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,19 @@ import (
"github.com/DavidGamba/dgtools/bt/terraform"
"github.com/DavidGamba/go-getoptions"
"github.com/DavidGamba/go-getoptions/dag"
"github.com/mattn/go-isatty"
)

func generateDAG(opt *getoptions.GetOpt, id string, cfg *sconfig.Config, normal bool) (*dag.Graph, error) {
color := opt.Value("color").(string)

tm := dag.NewTaskMap()
g := dag.NewGraph("stack " + id)

if color == "always" || (color == "auto" && isatty.IsTerminal(os.Stdout.Fd())) {
g.UseColor = true
}

wd, err := os.Getwd()
if err != nil {
return g, fmt.Errorf("failed to get current working directory: %w", err)
Expand Down
7 changes: 7 additions & 0 deletions bt/terraform/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/DavidGamba/dgtools/bt/config"
"github.com/DavidGamba/go-getoptions"
"github.com/DavidGamba/go-getoptions/dag"
"github.com/mattn/go-isatty"
)

func buildCMD(ctx context.Context, parent *getoptions.GetOpt) *getoptions.GetOpt {
Expand Down Expand Up @@ -41,6 +42,7 @@ func BuildRun(ctx context.Context, opt *getoptions.GetOpt, args []string) error
lock := opt.Value("lock").(bool)
detailedExitcode := opt.Value("detailed-exitcode").(bool)
ws := opt.Value("ws").(string)
color := opt.Value("color").(string)

cfg := config.ConfigFromContext(ctx)
component := ComponentFromContext(ctx)
Expand Down Expand Up @@ -100,6 +102,11 @@ func BuildRun(ctx context.Context, opt *getoptions.GetOpt, args []string) error
}

g := dag.NewGraph(fmt.Sprintf("%s:build", component))

if color == "always" || (color == "auto" && isatty.IsTerminal(os.Stdout.Fd())) {
g.UseColor = true
}

g.TaskDependsOn(tm.Get("plan"), tm.Get("init"))
if lock {
g.TaskDependsOn(tm.Get("lock"), tm.Get("init"))
Expand Down

0 comments on commit 29560d6

Please sign in to comment.