Skip to content

Commit 8dad2f1

Browse files
Andrea Falzettiroboquat
Andrea Falzetti
authored andcommitted
feat(gp-cli): allow disabling output colorization
1 parent 58bd41f commit 8dad2f1

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

components/gitpod-cli/cmd/ports-list.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"time"
1313

1414
supervisor_helper "github.com/gitpod-io/gitpod/gitpod-cli/pkg/supervisor-helper"
15+
"github.com/gitpod-io/gitpod/gitpod-cli/pkg/utils"
1516
supervisor "github.com/gitpod-io/gitpod/supervisor/api"
1617
log "github.com/sirupsen/logrus"
1718
"github.com/spf13/cobra"
@@ -76,9 +77,14 @@ var listPortsCmd = &cobra.Command{
7677
}
7778
}
7879

80+
colors := []tablewriter.Colors{}
81+
if !noColor && utils.ColorsEnabled() {
82+
colors = []tablewriter.Colors{{}, {statusColor}, {}, {}}
83+
}
84+
7985
table.Rich(
8086
[]string{fmt.Sprint(port.LocalPort), status, port.Exposed.Url, nameAndDescription},
81-
[]tablewriter.Colors{{}, {statusColor}, {}, {}},
87+
colors,
8288
)
8389
}
8490

@@ -87,5 +93,6 @@ var listPortsCmd = &cobra.Command{
8793
}
8894

8995
func init() {
96+
listPortsCmd.Flags().BoolVarP(&noColor, "no-color", "", false, "Disable output colorization")
9097
portsCmd.AddCommand(listPortsCmd)
9198
}

components/gitpod-cli/cmd/root.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ var rootCmd = &cobra.Command{
1818
Short: "Command line interface for Gitpod",
1919
}
2020

21+
var noColor bool
22+
2123
// Execute runs the root command
2224
func Execute() {
2325
entrypoint := strings.TrimPrefix(filepath.Base(os.Args[0]), "gp-")

components/gitpod-cli/cmd/tasks-list.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"time"
1313

1414
supervisor_helper "github.com/gitpod-io/gitpod/gitpod-cli/pkg/supervisor-helper"
15+
"github.com/gitpod-io/gitpod/gitpod-cli/pkg/utils"
1516
"github.com/gitpod-io/gitpod/supervisor/api"
1617
"github.com/spf13/cobra"
1718

@@ -48,13 +49,20 @@ var listTasksCmd = &cobra.Command{
4849
}
4950

5051
for _, task := range tasks {
51-
table.Rich([]string{task.Terminal, task.Presentation.Name, task.State.String()}, []tablewriter.Colors{{}, {}, {mapStatusToColor[task.State]}})
52+
colors := []tablewriter.Colors{}
53+
54+
if !noColor && utils.ColorsEnabled() {
55+
colors = []tablewriter.Colors{{}, {}, {mapStatusToColor[task.State]}}
56+
}
57+
58+
table.Rich([]string{task.Terminal, task.Presentation.Name, task.State.String()}, colors)
5259
}
5360

5461
table.Render()
5562
},
5663
}
5764

5865
func init() {
66+
listTasksCmd.Flags().BoolVarP(&noColor, "no-color", "", false, "Disable output colorization")
5967
tasksCmd.AddCommand(listTasksCmd)
6068
}

components/gitpod-cli/cmd/top.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ import (
2121
"github.com/olekukonko/tablewriter"
2222
)
2323

24-
var noColor bool
25-
2624
func outputTable(workspaceResources *supervisor.ResourcesStatusResponse) {
2725
table := tablewriter.NewWriter(os.Stdout)
2826
table.SetHeader([]string{"CPU (millicores)", "Memory (bytes)"})

0 commit comments

Comments
 (0)