Skip to content

Commit

Permalink
feat: Add flag for turning off colors in TTY printing
Browse files Browse the repository at this point in the history
  • Loading branch information
varungandhi-src committed Oct 31, 2023
1 parent 79eeae0 commit 2993496
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
20 changes: 14 additions & 6 deletions cmd/scip/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,38 @@ import (
)

func printCommand() cli.Command {
var json bool
var json, colorOutput bool
snapshot := cli.Command{
Name: "print",
Usage: "Print a SCIP index in a human-readable format for debugging",
Description: `WARNING: The output may change over time.
Do not rely on the output of this command in scripts`,
Usage: "Print a SCIP index for debugging",
Description: `WARNING: The TTY output may change over time.
Do not rely on non-JSON output in scripts`,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "json",
Usage: "Output in JSON format",
Destination: &json,
},
&cli.BoolFlag{
Name: "color",
Usage: "Enable color output for TTY (no effect for JSON)",
Destination: &colorOutput,
Value: true,
DefaultText: "true",
},
},
Action: func(c *cli.Context) error {
indexPath := c.Args().Get(0)
if indexPath == "" {
return errors.New("missing argument for path to SCIP index")
}
return printMain(indexPath, json, c.App.Writer)
return printMain(indexPath, colorOutput, json, c.App.Writer)
},
}
return snapshot
}

func printMain(indexPath string, json bool, out io.Writer) error {
func printMain(indexPath string, colorOutput bool, json bool, out io.Writer) error {
index, err := readFromOption(indexPath)
if err != nil {
return err
Expand All @@ -51,6 +58,7 @@ func printMain(indexPath string, json bool, out io.Writer) error {
return err
} else {
prettyPrinter := pp.New()
prettyPrinter.SetColoringEnabled(colorOutput)
prettyPrinter.SetExportedOnly(true)
prettyPrinter.SetOutput(out)
_, err = prettyPrinter.Print(index)
Expand Down
15 changes: 10 additions & 5 deletions docs/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ USAGE:
scip [global options] command [command options] [arguments...]
VERSION:
v0.3.1
v0.3.1-dev
SHA: 3289897621a5e4eeecf7c17c1dc93f4025181597
timestamp: 2023-10-31T07:03:12Z
clean: true
DESCRIPTION:
For more details, see the project README at:
Expand All @@ -28,7 +31,7 @@ DESCRIPTION:
COMMANDS:
convert Convert a SCIP index to an LSIF index
lint Flag potential issues with a SCIP index
print Print a SCIP index in a human-readable format for debugging
print Print a SCIP index for debugging
snapshot Generate snapshot files for golden testing
stats Output useful statistics about a SCIP index
help, h Shows a list of commands or help for one command
Expand Down Expand Up @@ -74,17 +77,19 @@ DESCRIPTION:

```
NAME:
scip print - Print a SCIP index in a human-readable format for debugging
scip print - Print a SCIP index for debugging
USAGE:
scip print [command options] [arguments...]
DESCRIPTION:
WARNING: The output may change over time.
Do not rely on the output of this command in scripts
WARNING: The TTY output may change over time.
Do not rely on non-JSON output in scripts
OPTIONS:
--json Output in JSON format (default: false)
--color Enable color output for TTY (no effect for JSON) (default: true)
--help, -h show help
```

## `scip snapshot`
Expand Down

0 comments on commit 2993496

Please sign in to comment.