You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: download.go
    path of file: ./repos/ipsw/cmd/ipsw/cmd/download
    
    the code of the file until where you have to start completion: /*
Copyright Â© 2018-2024 blacktop

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package download

import (
	"fmt"
	"path"
	"strings"

	"github.com/blacktop/ipsw/internal/download"
	"github.com/spf13/cobra"
	"github.com/spf13/viper"
)

type downloadFlags struct {
	Proxy        string
	Insecure     bool
	Confirm      bool
	SkipAll      bool
	ResumeAll    bool
	RestartAll   bool
	RemoveCommas bool

	WhiteList []string
	BlackList []string
	Device    string
	Model     string
	Version   string
	Build     string
}

var dFlg downloadFlags

func init() {
	// Persistent Flags which will work for this command and all subcommands
	DownloadCmd.PersistentFlags().StringVar(&dFlg.Proxy, "proxy", "", "HTTP/HTTPS proxy")
	DownloadCmd.PersistentFlags().BoolVar(&dFlg.Insecure, "insecure", false, "do not verify ssl certs")
	DownloadCmd.PersistentFlags().BoolVarP(&dFlg.Confirm, "confirm", "
    
func filterIPSWs(cmd *cobra.Command, macos bool) ([]download.IPSW, error) {

	var err error
	var ipsws []download.IPSW
	var filteredIPSWs []download.IPSW

	viper.BindPFlag("download.white-list", cmd.Flags().Lookup("white-list"))
	viper.BindPFlag("download.black-list", cmd.Flags().Lookup("black-list"))
	viper.BindPFlag("download.confirm", cmd.Flags().Lookup("confirm"))
	viper.BindPFlag("download.skip-all", cmd.Flags().Lookup("skip-all"))
	viper.BindPFlag("download.resume-all", cmd.Flags().Lookup("resume-all"))
	viper.BindPFlag("download.restart-all", cmd.Flags().Lookup("restart-all"))
	viper.BindPFlag("download.remove-commas", cmd.Flags().Lookup("remove-commas"))
	viper.BindPFlag("download.device", cmd.Flags().Lookup("device"))
	viper.BindPFlag("download.model", cmd.Flags().Lookup("model"))
	viper.BindPFlag("download.version", cmd.Flags().Lookup("version"))
	viper.BindPFlag("download.build", cmd.Flags().Lookup("build"))

	// filters
	device := viper.GetString("download.device")
	// model := viper.GetString("download.model")
	version := viper.GetString("download.version")
	build := viper.GetString("download.build")
	doDownload := viper.GetStringSlice("download.white-list")
	doNotDownload := viper.GetStringSlice("download.black-list")

	// verify args
	if len(device) == 0 && len(version) == 0 && len(build) == 0 {
		return nil, fmt.Errorf("you must also supply a --device || --version || --build (or use --latest)")
	}
	if len(version) > 0 && len(build) > 0 {
		return nil, fmt.Errorf("you cannot supply --version AND --build (they are mutually exclusive)")
	}

	if len(version) > 0 {
		ipsws, err = download.GetAllIPSW(version)
		if err != nil {
			return nil, fmt.Errorf("failed to query ipsw.me api for ALL ipsws for version %s: %v", version, err)
		}
	} else if len(build) > 0 {
		version, err = download.GetVersion(build)
		if err != nil {
			return nil, fmt.Errorf("failed to query ipsw.me api for buildID %s => version: %v", build, err)
		}
		ipsws, err = download.GetAllIPSW(version)
		if err != nil {
			return nil, fmt.Errorf("failed to query ipsw.me api for ALL ipsws for version %s: %v", version, err)
		}
		var buildFiltered []download.IPSW
		for _, i := range ipsws {
			if strings.EqualFold(build, i.BuildID) {
				buildFiltered = append(buildFiltered, i)
			}
		}
		ipsws = buildFiltered
	} else if len(device) > 0 {
		ipsws, err = download.GetDeviceIPSWs(device)
		if err != nil {
			return nil, fmt.Errorf("failed to query ipsw.me api for device %s: %v", device, err)
		}
	}

	for _, i := range ipsws {
		if len(device) > 0 {
			if strings.EqualFold(device, i.Identifier) {
				filteredIPSWs = append(filteredIPSWs, i)
			}
		} else {
			if len(doDownload) > 0 {
				for _, doDown := range doDownload {
					if strings.HasPrefix(strings.ToLower(i.Identifier), strings.ToLower(doDown)) {
						filteredIPSWs = append(filteredIPSWs, i)
					}
				}
			} else if len(doNotDownload) > 0 {
				for _, dontDown := range doNotDownload {
					if !strings.HasPrefix(strings.ToLower(i.Identifier), strings.ToLower(dontDown)) {
						filteredIPSWs = append(filteredIPSWs, i)
					}
				}
			} else {
				filteredIPSWs = append(filteredIPSWs, i)
			}
		}
	}

	if macos {
		var furtherFilteredIPSWs []download.IPSW
		for _, i := range filteredIPSWs {
			if strings.Contains(i.Identifier, "Mac") {
				furtherFilteredIPSWs = append(furtherFilteredIPSWs, i)
			}
		}
		filteredIPSWs = furtherFilteredIPSWs
	}

	unique := make(map[string]bool, len(filteredIPSWs))
	uniqueIPSWs := make([]download.IPSW, len(unique))
	for _, i := range filteredIPSWs {
		if len(i.URL) != 0 {
			if !unique[i.URL] {
				uniqueIPSWs = append(uniqueIPSWs, i)
				unique[i.URL] = true
			}
		}
	}

	if len(uniqueIPSWs) == 0 {
		return nil, fmt.Errorf("filter flags matched 0 IPSWs")
	}

	return uniqueIPSWs, nil
}