mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-10 05:27:07 +08:00
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 <me@jedevc.com>
This commit is contained in:
@ -55,7 +55,7 @@ func defaultFilenames() []string {
|
|||||||
return names
|
return names
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReadLocalFiles(names []string) ([]File, error) {
|
func ReadLocalFiles(names []string, stdin io.Reader) ([]File, error) {
|
||||||
isDefault := false
|
isDefault := false
|
||||||
if len(names) == 0 {
|
if len(names) == 0 {
|
||||||
isDefault = true
|
isDefault = true
|
||||||
@ -67,7 +67,7 @@ func ReadLocalFiles(names []string) ([]File, error) {
|
|||||||
var dt []byte
|
var dt []byte
|
||||||
var err error
|
var err error
|
||||||
if n == "-" {
|
if n == "-" {
|
||||||
dt, err = io.ReadAll(os.Stdin)
|
dt, err = io.ReadAll(stdin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -1398,7 +1398,7 @@ func TestReadLocalFilesDefault(t *testing.T) {
|
|||||||
for _, tf := range tt.filenames {
|
for _, tf := range tt.filenames {
|
||||||
require.NoError(t, os.WriteFile(tf, []byte(tf), 0644))
|
require.NoError(t, os.WriteFile(tf, []byte(tf), 0644))
|
||||||
}
|
}
|
||||||
files, err := ReadLocalFiles(nil)
|
files, err := ReadLocalFiles(nil, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
if len(files) == 0 {
|
if len(files) == 0 {
|
||||||
require.Equal(t, len(tt.expected), len(files))
|
require.Equal(t, len(tt.expected), len(files))
|
||||||
|
@ -146,7 +146,7 @@ func runBake(dockerCli command.Cli, targets []string, in bakeOptions, cFlags com
|
|||||||
if url != "" {
|
if url != "" {
|
||||||
files, inp, err = bake.ReadRemoteFiles(ctx, nodes, url, in.files, printer)
|
files, inp, err = bake.ReadRemoteFiles(ctx, nodes, url, in.files, printer)
|
||||||
} else {
|
} else {
|
||||||
files, err = bake.ReadLocalFiles(in.files)
|
files, err = bake.ReadLocalFiles(in.files, dockerCli.In())
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -19,7 +19,7 @@ func Disable(cmd *cobra.Command, args []string, toComplete string) ([]string, co
|
|||||||
|
|
||||||
func BakeTargets(files []string) ValidArgsFn {
|
func BakeTargets(files []string) ValidArgsFn {
|
||||||
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
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 {
|
if err != nil {
|
||||||
return nil, cobra.ShellCompDirectiveError
|
return nil, cobra.ShellCompDirectiveError
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user