func unsplashRun()

in cobra/controller/unsplash.go [74:122]


func unsplashRun(cmd *cobra.Command, args []string) error {
	logrus.Traceln("start: command unsplash run")

	cred, err := dao.GetCredentialByProvider(profile, "unsplash")
	if err != nil {
		logrus.Errorf("Unexpected error: %v", err)
		return err
	}

	if (model.Credential{}) == cred {
		return fmt.Errorf("no unsplash credential found or no profile enabled")
	}

	id, err := cmd.Flags().GetString("id")
	if err != nil {
		return fmt.Errorf("unable to get flag id\n%v", err)
	}

	if id != "" {
		// get photo
		response, err := aid.GetPhoto(id, cred)
		if err != nil || response.ID == "" {
			return fmt.Errorf("unablet to get photo\n%v", err)
		}

		size, err := cmd.Flags().GetString("size")
		if err != nil {
			return fmt.Errorf("unable to get flag id\n%v", err)
		}

		if response.ID != "" {
			aid.SaveGetPhotoResult(response)
			aid.DownloadPhotoByID(response, size)
		}

	} else {
		// random photo
		params := aid.GetModelFromFlags(cmd)
		err = aid.DownloadPhoto(params, cred, unsplashPhotoSizes)
		if err != nil {
			logrus.Errorf("unable to download photo\n%v", err)
			return err
		}

	}

	logrus.Traceln("end: command unsplash run")
	return err
}