From f5f00e68ef41b2305e902d7e2f405983376470e5 Mon Sep 17 00:00:00 2001 From: Justin Chadwell Date: Fri, 9 Jun 2023 10:50:51 +0100 Subject: [PATCH] bake(cli): allow passing in-stream using command.Cli ReadLocalFiles should allow passing the stdin file as an argument, which allows us to read from dockerCli.Stdin() to be consistent with other commands in the same package. Signed-off-by: Justin Chadwell --- bake/bake.go | 4 ++-- bake/bake_test.go | 2 +- commands/bake.go | 2 +- util/cobrautil/completion/completion.go | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bake/bake.go b/bake/bake.go index 9a507cd6e..39cd927eb 100644 --- a/bake/bake.go +++ b/bake/bake.go @@ -55,7 +55,7 @@ func defaultFilenames() []string { return names } -func ReadLocalFiles(names []string) ([]File, error) { +func ReadLocalFiles(names []string, stdin io.Reader) ([]File, error) { isDefault := false if len(names) == 0 { isDefault = true @@ -67,7 +67,7 @@ func ReadLocalFiles(names []string) ([]File, error) { var dt []byte var err error if n == "-" { - dt, err = io.ReadAll(os.Stdin) + dt, err = io.ReadAll(stdin) if err != nil { return nil, err } diff --git a/bake/bake_test.go b/bake/bake_test.go index f3341c06d..efebea204 100644 --- a/bake/bake_test.go +++ b/bake/bake_test.go @@ -1398,7 +1398,7 @@ func TestReadLocalFilesDefault(t *testing.T) { for _, tf := range tt.filenames { require.NoError(t, os.WriteFile(tf, []byte(tf), 0644)) } - files, err := ReadLocalFiles(nil) + files, err := ReadLocalFiles(nil, nil) require.NoError(t, err) if len(files) == 0 { require.Equal(t, len(tt.expected), len(files)) diff --git a/commands/bake.go b/commands/bake.go index 8edd45e6f..574a68741 100644 --- a/commands/bake.go +++ b/commands/bake.go @@ -146,7 +146,7 @@ func runBake(dockerCli command.Cli, targets []string, in bakeOptions, cFlags com if url != "" { files, inp, err = bake.ReadRemoteFiles(ctx, nodes, url, in.files, printer) } else { - files, err = bake.ReadLocalFiles(in.files) + files, err = bake.ReadLocalFiles(in.files, dockerCli.In()) } if err != nil { return err diff --git a/util/cobrautil/completion/completion.go b/util/cobrautil/completion/completion.go index 928be1740..607545378 100644 --- a/util/cobrautil/completion/completion.go +++ b/util/cobrautil/completion/completion.go @@ -19,7 +19,7 @@ func Disable(cmd *cobra.Command, args []string, toComplete string) ([]string, co func BakeTargets(files []string) ValidArgsFn { return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - f, err := bake.ReadLocalFiles(files) + f, err := bake.ReadLocalFiles(files, nil) if err != nil { return nil, cobra.ShellCompDirectiveError }