func do(
	packageCopier aptly_package_copier.PackageCopier,
	packageLatestVersion aptly_package_latest_version.PackageLatestVersion,
	packageDetailLatestLister aptly_model_latest_lister.PackageDetailLatestLister,
	repoURL string,
	apiURL string,
	apiUsername string,
	apiPassword string,
	apiPasswordfile string,
	sourceRepo string,
	targetRepo string,
	targetDistribution string,
	name string,
	version string,
) error {
	glog.Infof("repoURL: %v apiURL: %v apiUsername: %v apiPassword: %v apiPasswordfile: %v sourceRepo: %v targetRepo: %v targetDistribution: %v name: %v version: %v", repoURL, apiURL, apiUsername, apiPassword, apiPasswordfile, sourceRepo, targetRepo, targetDistribution, name, version)
	if len(apiPasswordfile) > 0 {
		content, err := ioutil.ReadFile(apiPasswordfile)
		if err != nil {
			return err
		}
		apiPassword = strings.TrimSpace(string(content))
	}
	if len(apiURL) == 0 {
		return fmt.Errorf("parameter %s missing", parameterAPIURL)
	}
	if len(sourceRepo) == 0 {
		return fmt.Errorf("parameter %s missing", parameterSource)
	}
	if len(targetRepo) == 0 {
		return fmt.Errorf("parameter %s missing", parameterTarget)
	}
	if len(name) == 0 {
		return fmt.Errorf("parameter %s missing", parameterName)
	}
	if len(version) == 0 {
		return fmt.Errorf("parameter %s missing", parameterVersion)
	}
	return copy(packageCopier, packageLatestVersion, packageDetailLatestLister, aptly_model.NewAPI(repoURL, apiURL, apiUsername, apiPassword), aptly_model.Repository(sourceRepo), aptly_model.Repository(targetRepo), aptly_model.Distribution(targetDistribution), aptly_model.Package(name), aptly_version.Version(version))
}
func do(
	writer io.Writer,
	packageVersions aptly_package_versions.PackageVersions,
	repoURL string,
	apiURL string,
	apiUsername string,
	apiPassword string,
	apiPasswordfile string,
	repo string,
	name string,
) error {
	glog.Infof("repoURL: %v apiURL: %v apiUsername: %v apiPassword: %v apiPasswordfile: %v repo: %v name: %v", repoURL, apiURL, apiUsername, apiPassword, apiPasswordfile, repo, name)
	if len(apiPasswordfile) > 0 {
		content, err := ioutil.ReadFile(apiPasswordfile)
		if err != nil {
			return err
		}
		apiPassword = strings.TrimSpace(string(content))
	}

	if len(apiURL) == 0 {
		return fmt.Errorf("parameter %s missing", parameterAPIURL)
	}
	if len(repo) == 0 {
		return fmt.Errorf("parameter %s missing", parameterRepo)
	}
	if len(name) == 0 {
		return fmt.Errorf("parameter %s missing", parameterName)
	}

	var err error
	var versions []aptly_version.Version
	if versions, err = packageVersions.PackageVersions(aptly_model.NewAPI(repoURL, apiURL, apiUsername, apiPassword), aptly_model.Repository(repo), aptly_model.Package(name)); err != nil {
		return err
	}
	if len(versions) == 0 {
		return fmt.Errorf("package %s not found", name)
	}
	sort.Sort(aptly_version.VersionByName(versions))
	fmt.Fprintf(writer, "%s\n", versions[len(versions)-1])
	return nil
}