Skip to content

Commit

Permalink
cmd/lava: add -forcecolor flag to run command
Browse files Browse the repository at this point in the history
  • Loading branch information
jroimartin committed Oct 25, 2023
1 parent 0e161c0 commit 9540a36
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions cmd/lava/internal/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"os"
"path/filepath"

"github.com/fatih/color"

"github.com/adevinta/lava/cmd/lava/internal/base"
"github.com/adevinta/lava/internal/config"
"github.com/adevinta/lava/internal/engine"
Expand All @@ -17,18 +19,28 @@ import (

// CmdRun represents the run command.
var CmdRun = &base.Command{
UsageLine: "run [-c config.yaml]",
UsageLine: "run [flags]",
Short: "run scan",
Long: `
Run a scan using the provided config file.
By default, "lava run" looks for a configuration file with the name
"lava.yaml" in the current directory. The -c flag allows to specify a
custom configuration file.
The -c flag allows to specify a configuration file. By default, "lava
run" looks for a configuration file with the name "lava.yaml" in the
current directory.
The -forcecolor flag forces colorized output. By default, colorized
output is disabled in the following cases:
- Lava is not executed from a terminal.
- Lava is executed from a "dumb" terminal.
- The NO_COLOR environment variable is set (regardless of its value).
`,
}

var cfgfile = CmdRun.Flag.String("c", "lava.yaml", "config file")
var (
cfgfile = CmdRun.Flag.String("c", "lava.yaml", "config file")
forceColor = CmdRun.Flag.Bool("forcecolor", false, "force colorized output")
)

func init() {
CmdRun.Run = run // Break initialization cycle.
Expand All @@ -40,6 +52,10 @@ func run(args []string) error {
return errors.New("too many arguments")
}

if *forceColor {
color.NoColor = false
}

cfg, err := config.ParseFile(*cfgfile)
if err != nil {
return fmt.Errorf("parse config file: %w", err)
Expand Down

0 comments on commit 9540a36

Please sign in to comment.