-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4dbe2aa
commit 6b24b4b
Showing
44 changed files
with
759 additions
and
720 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,10 @@ | ||
linters: | ||
enable: | ||
- contextcheck | ||
- depguard | ||
- dogsled | ||
- dupl | ||
- errorlint | ||
- exhaustive | ||
- exportloopref | ||
- forcetypeassert | ||
- funlen | ||
- gochecknoglobals | ||
- gochecknoinits | ||
- gocognit | ||
- goconst | ||
- gocritic | ||
- gocyclo | ||
- gofmt | ||
- gofumpt | ||
- goimports | ||
- goprintffuncname | ||
- gosec | ||
- importas | ||
- ireturn | ||
- lll | ||
- makezero | ||
- misspell | ||
- nakedret | ||
- nestif | ||
- nilerr | ||
- nilnil | ||
- nolintlint | ||
- prealloc | ||
- revive | ||
- stylecheck | ||
- tparallel | ||
- unconvert | ||
- unparam | ||
- whitespace | ||
- wsl | ||
enable-all: true | ||
|
||
linters-settings: | ||
gofumpt: | ||
module-path: docker-color-output | ||
module-path: docker-color-output | ||
varnamelen: | ||
ignore-names: [ i, in, j, m, sb, tt, v ] | ||
wrapcheck: | ||
ignorePackageGlobs: [ docker-color-output/internal/* ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module docker-color-output | ||
|
||
go 1.19 | ||
go 1.20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package app | ||
|
||
import ( | ||
"errors" | ||
"strings" | ||
|
||
"docker-color-output/internal/cmd" | ||
"docker-color-output/internal/layout" | ||
"docker-color-output/internal/util" | ||
"docker-color-output/pkg/color" | ||
) | ||
|
||
var ( | ||
ErrNoFirstLine = errors.New("no first line") | ||
ErrNullableColumns = errors.New("nullable columns more than one") | ||
) | ||
|
||
func Run(in []string) ([]string, error) { | ||
if len(in) == 0 { | ||
return nil, ErrNoFirstLine | ||
} | ||
|
||
header := layout.ParseHeader(in) | ||
rows := layout.ParseRows(in, &header) | ||
|
||
if header.NullableCols() > 1 { | ||
return nil, ErrNullableColumns | ||
} | ||
|
||
command, err := cmd.Parse(header) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
res := make([]string, len(in)) | ||
|
||
// First line | ||
var sb strings.Builder | ||
for _, col := range header { | ||
sb.WriteString(util.Pad(color.LightBlue(string(col.Name)), col.MaxLength)) | ||
} | ||
|
||
res[0] = sb.String() | ||
|
||
// Rows | ||
for i, row := range rows { | ||
sb.Reset() | ||
|
||
for _, col := range header { | ||
sb.WriteString(util.Pad(command.Format(row, col.Name), col.MaxLength)) | ||
} | ||
|
||
res[i+1] = sb.String() | ||
} | ||
|
||
return res, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package app_test | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"runtime" | ||
"strings" | ||
"testing" | ||
|
||
"docker-color-output/internal/app" | ||
"docker-color-output/pkg/util/assert" | ||
) | ||
|
||
func TestRun(t *testing.T) { | ||
t.Parallel() | ||
|
||
read := func(filename string) []string { | ||
_, b, _, _ := runtime.Caller(0) | ||
path := filepath.Dir(b) | ||
bytes, _ := os.ReadFile(path + "/../../test/data/" + filename) | ||
res := strings.Split(string(bytes), "\n") | ||
res = res[:len(res)-1] | ||
|
||
if len(res) == 0 { | ||
return nil | ||
} | ||
|
||
return res | ||
} | ||
|
||
tests := map[string]struct { | ||
in string | ||
want string | ||
wantErr bool | ||
}{ | ||
"no_stdin": {wantErr: true}, | ||
"no_first_line": {in: "no_first_line.out", wantErr: true}, | ||
"invalid_cols": {in: "invalid_cols.out", wantErr: true}, | ||
"docker_ps": {in: "docker_ps.out", want: "docker_ps.out"}, | ||
"docker_ps:custom_cols": {in: "docker_ps_custom_cols.out", want: "docker_ps_custom_cols.out"}, | ||
"docker_ps:nullable_col": {in: "docker_ps_nullable_col.out", want: "docker_ps_nullable_col.out"}, | ||
"docker_ps:nullable_cols": {in: "docker_ps_nullable_cols.out", wantErr: true}, | ||
"docker_images": {in: "docker_images.out", want: "docker_images.out"}, | ||
"docker_compose_ps": {in: "docker_compose_ps.out", want: "docker_compose_ps.out"}, | ||
"docker_compose_ps_1": {in: "docker_compose_ps_1.out", want: "docker_compose_ps_1.out"}, | ||
} | ||
|
||
for name, tt := range tests { | ||
tt := tt | ||
|
||
t.Run(name, func(t *testing.T) { | ||
t.Parallel() | ||
rows, err := app.Run(read("in/" + tt.in)) | ||
assert.Equal(t, tt.wantErr, err != nil) | ||
assert.Equal(t, read("out/"+tt.want), rows) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package app | ||
|
||
const ( | ||
Ver = "2.3.0" | ||
Name = "docker-color-output" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//go:build !test | ||
|
||
package app | ||
|
||
import ( | ||
"fmt" | ||
|
||
"docker-color-output/pkg/color" | ||
) | ||
|
||
//nolint:forbidigo | ||
func Usage(err error) { | ||
fmt.Println(color.LightRed("💡 Error: " + err.Error())) | ||
fmt.Println("💥 Version: " + color.Green(Ver)) | ||
fmt.Println("👌 Usage:") | ||
fmt.Println(" " + color.Green("docker compose ps") + " [-a] | " + color.Brown(Name)) | ||
fmt.Println(" " + color.Green("docker images") + " [--format] | " + color.Brown(Name)) | ||
fmt.Println(" " + color.Green("docker ps") + " [-a] [--format] | " + color.Brown(Name)) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.