Skip to content

Commit

Permalink
Silent mode
Browse files Browse the repository at this point in the history
  • Loading branch information
devemlight committed Mar 1, 2025
1 parent de359e1 commit 42070ac
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 16 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ sudo apt install docker-color-output

You can download the Windows build from the [releases](https://github.com/devemio/docker-color-output/releases) page.

## 😺 Configuration
## ⚙️ Configuration

You can customize the color palette to your liking, to do this you need to run `docker-color-output` with the `-c`
flag and specify the path to the configuration file. You can overwrite only the colors you want, the rest will be
Expand Down Expand Up @@ -73,6 +73,16 @@ Default configuration file:
}
```

#### 🔕 Silent mode

The silent mode suppresses error messages and prints the original output instead. This is useful when you want to keep
the standard output even in case of errors. If an error occurs, it will not display an error message but will pass
through the original output instead.

```bash
docker ps | docker-color-output -s
```

## 📚 Usage

### 🪄 Aliases
Expand Down
10 changes: 7 additions & 3 deletions cmd/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@ func run() error {
color.SetPalette(color.Palette(cfg.Colors))

return stdin.Get(func(rows []string) error { //nolint:wrapcheck
rows, err = app.Run(rows)
formatted, err := app.Run(rows)
if err != nil {
return fmt.Errorf("app: %w", err)
if !cfg.SilentMode {
return fmt.Errorf("app: %w", err)
}

formatted = rows
}

for _, row := range rows {
for _, row := range formatted {
stdout.Println(row)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/app/const.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package app

const (
Ver = "2.5.2"
Ver = "2.6.0"
Name = "docker-color-output"
)
21 changes: 11 additions & 10 deletions internal/app/usage.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
package app

import (
"github.com/devemio/docker-color-output/internal/stdout"
"github.com/devemio/docker-color-output/internal/stderr"
"github.com/devemio/docker-color-output/pkg/color"
)

const indent = " "

func Usage(err error) {
if err != nil {
stdout.Println(color.LightRed("💡 Error: " + err.Error()))
stderr.Println(color.LightRed("💡 Error: " + err.Error()))
}

stdout.Println("💥 Version: " + color.Green(Ver))
stderr.Println("💥 Version: " + color.Green(Ver))

stdout.Println("👌 Usage:")
stdout.Println(indent + color.Green("docker compose ps") + " [-a] | " + color.Brown(Name))
stdout.Println(indent + color.Green("docker images") + " [--format] | " + color.Brown(Name))
stdout.Println(indent + color.Green("docker ps") + " [-a] [--format] | " + color.Brown(Name))
stdout.Println(indent + color.Green("docker stats") + " [--no-stream] | " + color.Brown(Name))
stderr.Println("👌 Usage:")
stderr.Println(indent + color.Green("docker compose ps") + " [-a] | " + color.Brown(Name))
stderr.Println(indent + color.Green("docker images") + " [--format] | " + color.Brown(Name))
stderr.Println(indent + color.Green("docker ps") + " [-a] [--format] | " + color.Brown(Name))
stderr.Println(indent + color.Green("docker stats") + " [--no-stream] | " + color.Brown(Name))

stdout.Println("🚀 Flags:")
stdout.Println(indent + color.Green("-c") + " " + color.Brown("string") + " Path to configuration file")
stderr.Println("🚀 Flags:")
stderr.Println(indent + color.Green("-c") + " " + color.Brown("string") + " Path to configuration file")
stderr.Println(indent + color.Green("-s") + " " + color.Brown("bool") + " Silent mode (suppress errors)")
}
9 changes: 8 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import (
)

type Config struct {
Colors Colors `json:"colors"`
SilentMode bool `json:"-"`
Colors Colors `json:"colors"`
}

type Colors struct {
Expand Down Expand Up @@ -41,6 +42,7 @@ func Get() (Config, error) {
}

cfgPath := flag.String("c", "", "Path to configuration file")
silentMode := flag.Bool("s", false, "Silent mode (suppress errors)")
flag.Parse()

if *cfgPath != "" {
Expand All @@ -54,11 +56,16 @@ func Get() (Config, error) {
}
}

if *silentMode {
cfg.SilentMode = true
}

return cfg, nil
}

func createDefault() Config {
return Config{
SilentMode: false,
Colors: Colors{
Reset: "\u001B[0m",
Black: "\u001B[0;30m",
Expand Down
10 changes: 10 additions & 0 deletions internal/stderr/stderr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package stderr

import (
"fmt"
"os"
)

func Println(in string) {
_, _ = fmt.Fprintln(os.Stderr, in)
}

0 comments on commit 42070ac

Please sign in to comment.