@@ -51,7 +51,16 @@ func NewLoadCommand(dockerCli command.Cli) *cobra.Command {
5151
5252func runLoad (ctx context.Context , dockerCli command.Cli , opts loadOptions ) error {
5353 var input io.Reader = dockerCli .In ()
54- if opts .input != "" {
54+
55+ // TODO(thaJeztah): add support for "-" as STDIN to match other commands, possibly making it a required positional argument.
56+ switch opts .input {
57+ case "" :
58+ // To avoid getting stuck, verify that a tar file is given either in
59+ // the input flag or through stdin and if not display an error message and exit.
60+ if dockerCli .In ().IsTerminal () {
61+ return errors .Errorf ("requested load from stdin, but stdin is empty" )
62+ }
63+ default :
5564 // We use sequential.Open to use sequential file access on Windows, avoiding
5665 // depleting the standby list un-necessarily. On Linux, this equates to a regular os.Open.
5766 file , err := sequential .Open (opts .input )
@@ -62,12 +71,6 @@ func runLoad(ctx context.Context, dockerCli command.Cli, opts loadOptions) error
6271 input = file
6372 }
6473
65- // To avoid getting stuck, verify that a tar file is given either in
66- // the input flag or through stdin and if not display an error message and exit.
67- if opts .input == "" && dockerCli .In ().IsTerminal () {
68- return errors .Errorf ("requested load from stdin, but stdin is empty" )
69- }
70-
7174 var options []client.ImageLoadOption
7275 if opts .quiet || ! dockerCli .Out ().IsTerminal () {
7376 options = append (options , client .ImageLoadWithQuiet (true ))
0 commit comments