-
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
f27f8e9
commit f219449
Showing
35 changed files
with
319 additions
and
92 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
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package cli | ||
|
||
import ( | ||
"docker-color-output/internal/cmd" | ||
"docker-color-output/internal/lines" | ||
"docker-color-output/internal/lines/fmt" | ||
) | ||
|
||
func Execute(in []string) ([]*lines.Line, error) { | ||
c, err := cmd.ParseCmd(in) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
res := make([]*lines.Line, len(in)) | ||
|
||
cols, vals := cmd.ParseFirstLine(in[0]) | ||
|
||
res[0] = lines.NewLine(vals, cols, fmt.NewFirstLineFmt()) | ||
|
||
pl, err := cmd.ParseLines(in[1:], cols) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for i, vals := range pl { | ||
res[i+1] = lines.NewLine(vals, cols, c.GetFmt()) | ||
} | ||
|
||
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 cli | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"runtime" | ||
"strings" | ||
"testing" | ||
|
||
"docker-color-output/internal/lines" | ||
"docker-color-output/pkg/utils/assert" | ||
) | ||
|
||
func TestExecute(t *testing.T) { | ||
read := func(filename string) []string { | ||
_, b, _, _ := runtime.Caller(0) | ||
path := filepath.Dir(b) | ||
bytes, _ := os.ReadFile(path + "/../../test/data/" + filename) | ||
vals := strings.Split(string(bytes), "\n") | ||
vals = vals[:len(vals)-1] | ||
if len(vals) == 0 { | ||
return nil | ||
} | ||
return vals | ||
} | ||
|
||
build := func(in []*lines.Line) []string { | ||
var vals []string | ||
for _, v := range in { | ||
vals = append(vals, v.Build()) | ||
} | ||
return vals | ||
} | ||
|
||
tests := map[string]struct { | ||
in string | ||
want string | ||
wantErr bool | ||
}{ | ||
"no_stdin": {wantErr: true}, | ||
"no_first_line": {in: "in/no_first_line.out", wantErr: true}, | ||
"invalid_cols": {in: "in/invalid_cols.out", wantErr: true}, | ||
"docker_ps": {in: "in/docker_ps.out", want: "out/docker_ps.out"}, | ||
"docker_ps:custom_cols": {in: "in/docker_ps_custom_cols.out", want: "out/docker_ps_custom_cols.out"}, | ||
"docker_ps:nullable_col": {in: "in/docker_ps_nullable_col.out", want: "out/docker_ps_nullable_col.out"}, | ||
"docker_ps:nullable_cols": {in: "in/docker_ps_nullable_cols.out", wantErr: true}, | ||
"docker_images": {in: "in/docker_images.out", want: "out/docker_images.out"}, | ||
"docker_compose_ps": {in: "in/docker_compose_ps.out", want: "out/docker_compose_ps.out"}, | ||
} | ||
|
||
for name, tt := range tests { | ||
t.Run(name, func(t *testing.T) { | ||
vals, err := Execute(read(tt.in)) | ||
assert.Equal(t, tt.wantErr, err != nil) | ||
assert.Equal(t, read(tt.want), build(vals)) | ||
}) | ||
} | ||
} |
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,6 +1,6 @@ | ||
package cli | ||
|
||
const ( | ||
Ver = "2.2.0" | ||
Ver = "2.2.0-rc.1" | ||
App = "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
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
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,5 +1,5 @@ | ||
package fmt | ||
|
||
type Formatable interface { | ||
Format(col string, v string) string | ||
Format(vals map[string]string, col string) string | ||
} |
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
Oops, something went wrong.