Exemple #1
1
func upload(c *cli.Context) {
	if c.NArg() < 2 || c.NArg() > 3 {
		cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage())
	}
	localPath := c.Args().Get(0)
	versionDetails, err := utils.CreateVersionDetails(c.Args().Get(1))
	if err != nil {
		cliutils.Exit(cliutils.ExitCodeError, err.Error())
	}
	uploadPath := c.Args().Get(2)
	if strings.HasPrefix(uploadPath, "/") {
		uploadPath = uploadPath[1:]
	}

	uploadFlags, err := createUploadFlags(c)
	if err != nil {
		cliutils.Exit(cliutils.ExitCodeError, err.Error())
	}
	uploaded, failed, err := commands.Upload(versionDetails, localPath, uploadPath, uploadFlags)
	cliutils.ExitOnErr(err)
	if failed > 0 {
		if uploaded > 0 {
			cliutils.Exit(cliutils.ExitCodeWarning, "")
		}
		cliutils.Exit(cliutils.ExitCodeError, "")
	}
}
Exemple #2
0
func deleteVersion(c *cli.Context) {
	if c.NArg() != 1 {
		cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage())
	}
	versionDetails, err := utils.CreateVersionDetails(c.Args().Get(0))
	if err != nil {
		cliutils.Exit(cliutils.ExitCodeError, err.Error())
	}
	bintrayDetails, err := createBintrayDetails(c, true)
	if err != nil {
		cliutils.Exit(cliutils.ExitCodeError, err.Error())
	}

	if !c.Bool("quiet") {
		var confirm string
		fmt.Print("Delete version " + versionDetails.Version +
			" of package " + versionDetails.Package + "? (y/n): ")
		fmt.Scanln(&confirm)
		if !cliutils.ConfirmAnswer(confirm) {
			return
		}
	}
	err = commands.DeleteVersion(versionDetails, bintrayDetails)
	cliutils.ExitOnErr(err)
}
Exemple #3
0
func testPatternUpload(t *testing.T, flags *UploadFlags) {
	versionDetails, err := utils.CreateVersionDetails("test-subject/test-repo/test-package/ver-1.2")
	if err != nil {
		t.Error(err.Error())
	}
	uploadPath := "/a/b/"

	sep := cliutils.GetTestsFileSeperator()
	uploaded1, _, err := Upload(versionDetails, "testdata"+sep+"*", uploadPath, flags)
	if err != nil {
		t.Error(err.Error())
	}
	uploaded2, _, err := Upload(versionDetails, "testdata"+sep+"a*", uploadPath, flags)
	if err != nil {
		t.Error(err.Error())
	}
	uploaded3, _, err := Upload(versionDetails, "testdata"+sep+"b*", uploadPath, flags)
	if err != nil {
		t.Error(err.Error())
	}

	if uploaded1 != 3 {
		t.Error("Expected 3 file to be uploaded. Got " + strconv.Itoa(uploaded1) + ".")
	}
	if uploaded2 != 2 {
		t.Error("Expected 2 file to be uploaded. Got " + strconv.Itoa(uploaded2) + ".")
	}
	if uploaded3 != 1 {
		t.Error("Expected 1 file to be uploaded. Got " + strconv.Itoa(uploaded3) + ".")
	}
}
Exemple #4
0
func TestSingleFileUpload(t *testing.T) {
	versionDetails, err := utils.CreateVersionDetails("test-subject/test-repo/test-package/ver-1.2")
	if err != nil {
		t.Error(err.Error())
	}
	uploadPath := "/a/b/"
	flags := createUploadFlags()

	uploaded1, _, err := Upload(versionDetails, "testdata/a.txt", uploadPath, flags)
	if err != nil {
		t.Error(err.Error())
	}
	uploaded2, _, err := Upload(versionDetails, "testdata/aa.txt", uploadPath, flags)
	if err != nil {
		t.Error(err.Error())
	}
	uploaded3, _, err := Upload(versionDetails, "testdata/aa1*.txt", uploadPath, flags)
	if err != nil {
		t.Error(err.Error())
	}
	if uploaded1 != 1 {
		t.Error("Expected 1 file to be uploaded. Got " + strconv.Itoa(uploaded1) + ".")
	}
	if uploaded2 != 1 {
		t.Error("Expected 1 file to be uploaded. Got " + strconv.Itoa(uploaded2) + ".")
	}
	if uploaded3 != 0 {
		t.Error("Expected 0 file to be uploaded. Got " + strconv.Itoa(uploaded3) + ".")
	}
}
func CreateVersionDetailsForDownloadVersion(versionStr string) (*utils.VersionDetails, error) {
	parts := strings.Split(versionStr, "/")
	if len(parts) != 4 {
		err := cliutils.CheckError(errors.New("Argument format should be subject/repository/package/version. Got " + versionStr))
		if err != nil {
			return nil, err
		}
	}
	return utils.CreateVersionDetails(versionStr)
}
func TestDownloadVersion(t *testing.T) {
	versionDetails, err := utils.CreateVersionDetails("test-subject/test-repo/test-package/ver-1.2")
	if err != nil {
		t.Error(err.Error())
	}
	url := BuildDownloadVersionUrl(versionDetails, tests.CreateBintrayDetails(), false)
	expected := "https://api.bintray.com/packages/test-subject/test-repo/test-package/versions/ver-1.2/files"
	if expected != url {
		t.Error("Got unexpected url from BuildDownloadVersionUrl. Expected: " + expected + " Got " + url)
	}
}
Exemple #7
0
func gpgSignVersion(c *cli.Context) {
	if c.NArg() != 1 {
		cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage())
	}
	versionDetails, err := utils.CreateVersionDetails(c.Args().Get(0))
	if err != nil {
		cliutils.Exit(cliutils.ExitCodeError, err.Error())
	}
	flags, err := createBintrayDetails(c, true)
	if err != nil {
		cliutils.Exit(cliutils.ExitCodeError, err.Error())
	}
	err = commands.GpgSignVersion(versionDetails, c.String("passphrase"), flags)
	cliutils.ExitOnErr(err)
}
Exemple #8
0
func publishVersion(c *cli.Context) {
	if c.NArg() != 1 {
		cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage())
	}
	versionDetails, err := utils.CreateVersionDetails(c.Args().Get(0))
	if err != nil {
		cliutils.Exit(cliutils.ExitCodeError, err.Error())
	}
	bintrayDetails, err := createBintrayDetails(c, true)
	if err != nil {
		cliutils.Exit(cliutils.ExitCodeError, err.Error())
	}
	err = commands.PublishVersion(versionDetails, bintrayDetails)
	cliutils.ExitOnErr(err)
}
Exemple #9
0
func updateVersion(c *cli.Context) {
	if c.NArg() != 1 {
		cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage())
	}
	versionDetails, err := utils.CreateVersionDetails(c.Args().Get(0))
	if err != nil {
		cliutils.Exit(cliutils.ExitCodeError, err.Error())
	}
	versionFlags, err := createVersionFlags(c, "")
	if err != nil {
		cliutils.Exit(cliutils.ExitCodeError, err.Error())
	}
	err = commands.UpdateVersion(versionDetails, versionFlags)
	cliutils.ExitOnErr(err)
}