cmd

package
v0.0.0-...-2d56c29 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 18, 2016 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RootCmd = &cobra.Command{
	Use:   "gopixabay /path/to/output",
	Short: "gopixabay image downloader",
	Long:  `gopixabay is an image downloader using the pixabay API`,
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) != 1 {
			cmd.Help()
			return
		}

		validateSizeArgument()

		var result interface{}
		var err error

		switch arguments.request.ResponseGroup {
		case pbapi.ResponseGroupHighResolution:
			result, err = pbapi.QueryHighResolution(arguments.request)
		case pbapi.ResponseGroupImageDetails:
			result, err = pbapi.QueryImageDetails(arguments.request)
		default:
			log.Fatalf("Unknown response group: %s", arguments.request.ResponseGroup)
		}

		if err != nil {
			log.Fatal(err)
		}

		uiprogress.Start()
		wg := &sync.WaitGroup{}
		downloadChan := make(chan string)
		defer close(downloadChan)

		initWorkerThreads(args[0], wg, downloadChan)

		switch realResult := result.(type) {
		case *pbapi.HighResolutionResponse:
			for _, hit := range realResult.Hits {
				switch arguments.size {
				case og:
					downloadChan <- hit.ImageURL
				case lg:
					downloadChan <- hit.FullHDURL
				case md:
					downloadChan <- hit.LargeImageURL
				}
			}
		case *pbapi.ImageDetailsResponse:
			for _, hit := range realResult.Hits {
				switch arguments.size {
				case sm:
					downloadChan <- hit.WebFormatURL
				case xs:
					downloadChan <- hit.PreviewURL
				}
			}
		}

		wg.Wait()
		uiprogress.Stop()
		time.Sleep(time.Second)
	},
}

This represents the base command when called without any subcommands

Functions

func Execute

func Execute()

Execute adds all child commands to the root command sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

Types

type Arguments

type Arguments struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL