package cli import ( "errors" "flag" "fmt" "io" "os" "werkdock/internal/registry" "werkdock/internal/store" ) // pullCmd is `docker pull`: fetch an image from a registry into the // store, through package registry (crane). The verb is a thin frontend, // as the API server's images/create is (RFC 0005). func pullCmd(args []string) int { fs := flag.NewFlagSet("pull", flag.ContinueOnError) fs.SetOutput(io.Discard) platform := fs.String("platform", registry.DefaultPlatform(), "os/arch to pull from a multi-arch image") if err := fs.Parse(args); err != nil { return fail(err) } rest := fs.Args() if len(rest) == 0 { return fail(errors.New("pull needs an IMAGE (werkdock pull [REGISTRY/]REPOSITORY[:TAG])")) } if len(rest) > 1 { return fail(fmt.Errorf("unexpected argument %q", rest[1])) } st, err := store.Default() if err != nil { return fail(err) } loaded, err := registry.Pull(st, rest[0], *platform, os.Stderr) if err != nil { return fail(err) } for _, name := range loaded { fmt.Printf("Pulled image: %s\n", name) } return 0 }