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, "") } }
func searchCmd(c *cli.Context) { if c.NArg() > 0 && c.IsSet("spec") { cliutils.Exit(cliutils.ExitCodeError, "No arguments should be sent when the spec option is used. "+cliutils.GetDocumentationMessage()) } if !(c.NArg() == 1 || (c.NArg() == 0 && c.IsSet("spec"))) { cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage()) } var searchSpec *utils.SpecFiles if c.IsSet("spec") { var err error searchSpec, err = getSearchSpec(c) cliutils.ExitOnErr(err) } else { searchSpec = createDefaultSearchSpec(c) } flags, err := createSearchFlags(c) cliutils.ExitOnErr(err) SearchResult, err := commands.Search(searchSpec, flags) cliutils.ExitOnErr(err) result, err := json.Marshal(SearchResult) cliutils.ExitOnErr(err) fmt.Println(string(cliutils.IndentJson(result))) }
func logs(c *cli.Context) { bintrayDetails, err := createBintrayDetails(c, true) if err != nil { cliutils.Exit(cliutils.ExitCodeError, err.Error()) } if c.NArg() == 1 { packageDetails, err := utils.CreatePackageDetails(c.Args().Get(0)) cliutils.ExitOnErr(err) err = commands.LogsList(packageDetails, bintrayDetails) cliutils.ExitOnErr(err) } else if c.NArg() == 3 { if c.Args().Get(0) == "download" { packageDetails, err := utils.CreatePackageDetails(c.Args().Get(1)) if err != nil { cliutils.Exit(cliutils.ExitCodeError, err.Error()) } err = commands.DownloadLog(packageDetails, c.Args().Get(2), bintrayDetails) cliutils.ExitOnErr(err) } else { cliutils.Exit(cliutils.ExitCodeError, "Unkown argument "+c.Args().Get(0)+". "+cliutils.GetDocumentationMessage()) } } else { cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage()) } }
func uploadCmd(c *cli.Context) { if c.NArg() > 0 && c.IsSet("spec") { cliutils.Exit(cliutils.ExitCodeError, "No arguments should be sent when the spec option is used. "+cliutils.GetDocumentationMessage()) } if !(c.NArg() == 2 || (c.NArg() == 0 && c.IsSet("spec"))) { cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage()) } var uploadSpec *utils.SpecFiles if c.IsSet("spec") { var err error uploadSpec, err = getUploadSpec(c) cliutils.ExitOnErr(err) } else { uploadSpec = createDefaultUploadSpec(c) } flags, err := createUploadFlags(c) cliutils.ExitOnErr(err) uploaded, failed, err := commands.Upload(uploadSpec, flags) cliutils.ExitOnErr(err) if failed > 0 { if uploaded > 0 { cliutils.Exit(cliutils.ExitCodeWarning, "") } cliutils.Exit(cliutils.ExitCodeError, "") } }
func buildDistributeCmd(c *cli.Context) { if c.NArg() != 3 { cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage()) } buildDistributeFlags, err := createBuildDistributionFlags(c) if err != nil { cliutils.ExitOnErr(err) } err = commands.BuildDistribute(c.Args().Get(0), c.Args().Get(1), c.Args().Get(2), buildDistributeFlags) cliutils.ExitOnErr(err) }
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) }
func buildPublishCmd(c *cli.Context) { vlidateBuildInfoArgument(c) buildInfoFlags, err := createBuildInfoFlags(c) cliutils.ExitOnErrWithMsg(err) err = commands.BuildPublish(c.Args().Get(0), c.Args().Get(1), buildInfoFlags) cliutils.ExitOnErr(err) }
func configCmd(c *cli.Context) { if len(c.Args()) > 1 { cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage()) } else if len(c.Args()) == 1 { if c.Args()[0] == "show" { commands.ShowConfig() } else if c.Args()[0] == "clear" { commands.ClearConfig() } else { cliutils.Exit(cliutils.ExitCodeError, "Unknown argument '"+c.Args()[0]+"'. Available arguments are 'show' and 'clear'.") } } else { configFlags, err := createConfigFlags(c) cliutils.ExitOnErr(err) _, err = commands.Config(configFlags.ArtDetails, nil, configFlags.Interactive, configFlags.EncPassword) cliutils.ExitOnErr(err) } }
func deleteCmd(c *cli.Context) { if c.NArg() > 0 && c.IsSet("spec") { cliutils.Exit(cliutils.ExitCodeError, "No arguments should be sent when the spec option is used. "+cliutils.GetDocumentationMessage()) } if !(c.NArg() == 1 || (c.NArg() == 0 && c.IsSet("spec"))) { cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage()) } var deleteSpec *utils.SpecFiles if c.IsSet("spec") { var err error deleteSpec, err = getDeleteSpec(c) cliutils.ExitOnErr(err) } else { deleteSpec = createDefaultDeleteSpec(c) } flags, err := createDeleteFlags(c) cliutils.ExitOnErr(err) if !c.Bool("quiet") { pathsToDelete, err := commands.GetPathsToDelete(deleteSpec, flags) cliutils.ExitOnErr(err) if len(pathsToDelete) < 1 { return } for _, v := range pathsToDelete { fmt.Println(" " + v.GetFullUrl()) } var confirm string fmt.Print("Are you sure you want to delete the above paths? (y/n): ") fmt.Scanln(&confirm) if !cliutils.ConfirmAnswer(confirm) { return } err = commands.DeleteFiles(pathsToDelete, flags) cliutils.ExitOnErr(err) } else { err = commands.Delete(deleteSpec, flags) cliutils.ExitOnErr(err) } }
func copyCmd(c *cli.Context) { if c.NArg() > 0 && c.IsSet("spec") { cliutils.Exit(cliutils.ExitCodeError, "No arguments should be sent when the spec option is used. "+cliutils.GetDocumentationMessage()) } if !(c.NArg() == 2 || (c.NArg() == 0 && c.IsSet("spec"))) { cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage()) } var copySpec *utils.SpecFiles if c.IsSet("spec") { var err error copySpec, err = getMoveSpec(c) cliutils.ExitOnErr(err) } else { copySpec = createDefaultMoveSpec(c) } flags, err := createMoveFlags(c) cliutils.ExitOnErr(err) err = commands.Copy(copySpec, flags) cliutils.ExitOnErr(err) }
func downloadVersion(c *cli.Context) { if c.NArg() < 1 || c.NArg() > 2 { cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage()) } versionDetails, err := commands.CreateVersionDetailsForDownloadVersion(c.Args().Get(0)) cliutils.ExitOnErr(err) targetPath := c.Args().Get(1) if strings.HasPrefix(targetPath, "/") { targetPath = targetPath[1:] } flags, err := createDownloadFlags(c) if err != nil { cliutils.Exit(cliutils.ExitCodeError, err.Error()) } downloaded, failed, err := commands.DownloadVersion(versionDetails, targetPath, flags) cliutils.ExitOnErr(err) if failed > 0 { if downloaded > 0 { cliutils.Exit(cliutils.ExitCodeWarning, "") } cliutils.Exit(cliutils.ExitCodeError, "") } }
func handleEntitlements(c *cli.Context) { if c.NArg() == 0 { cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage()) } if c.NArg() == 1 { bintrayDetails, err := createBintrayDetails(c, true) cliutils.ExitOnErr(err) details, err := entitlements.CreateVersionDetails(c.Args().Get(0)) cliutils.ExitOnErr(err) err = entitlements.ShowEntitlements(bintrayDetails, details) cliutils.ExitOnErr(err) return } if c.NArg() != 2 { cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage()) } details, err := entitlements.CreateVersionDetails(c.Args().Get(1)) cliutils.ExitOnErr(err) var flags *entitlements.EntitlementFlags switch c.Args().Get(0) { case "show": flags, err = createEntitlementFlagsForShowAndDelete(c) cliutils.ExitOnErr(err) err = entitlements.ShowEntitlement(flags, details) case "create": flags, err = createEntitlementFlagsForCreate(c) cliutils.ExitOnErr(err) err = entitlements.CreateEntitlement(flags, details) case "update": flags, err = createEntitlementFlagsForUpdate(c) cliutils.ExitOnErr(err) err = entitlements.UpdateEntitlement(flags, details) case "delete": flags, err = createEntitlementFlagsForShowAndDelete(c) cliutils.ExitOnErr(err) err = entitlements.DeleteEntitlement(flags, details) default: cliutils.Exit(cliutils.ExitCodeError, "Expecting show, create, update or delete before "+c.Args().Get(1)+". Got "+c.Args().Get(0)) } cliutils.ExitOnErr(err) }
func updatePackage(c *cli.Context) { if c.NArg() != 1 { cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage()) } packageDetails, err := utils.CreatePackageDetails(c.Args().Get(0)) if err != nil { cliutils.Exit(cliutils.ExitCodeError, err.Error()) } packageFlags, err := createPackageFlags(c) if err != nil { cliutils.Exit(cliutils.ExitCodeError, err.Error()) } err = commands.UpdatePackage(packageDetails, packageFlags) cliutils.ExitOnErr(err) }
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) }
func signUrl(c *cli.Context) { if c.NArg() != 1 { cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage()) } urlSigningDetails, err := utils.CreatePathDetails(c.Args().Get(0)) if err != nil { cliutils.Exit(cliutils.ExitCodeError, err.Error()) } urlSigningFlags, err := createUrlSigningFlags(c) if err != nil { cliutils.Exit(cliutils.ExitCodeError, err.Error()) } err = commands.SignVersion(urlSigningDetails, urlSigningFlags) cliutils.ExitOnErr(err) }
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) }
func createVersion(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.CreateVersion(versionDetails, versionFlags) cliutils.ExitOnErr(err) }
func downloadFile(c *cli.Context) { if c.NArg() < 1 || c.NArg() > 2 { cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage()) } pathDetails, err := utils.CreatePathDetails(c.Args().Get(0)) if err != nil { cliutils.Exit(cliutils.ExitCodeError, err.Error()) } targetPath := c.Args().Get(1) if strings.HasPrefix(targetPath, "/") { targetPath = targetPath[1:] } flags, err := createDownloadFlags(c) if err != nil { cliutils.Exit(cliutils.ExitCodeError, err.Error()) } err = commands.DownloadFile(pathDetails, targetPath, flags) cliutils.ExitOnErr(err) }
func offerConfig(c *cli.Context) (*config.BintrayDetails, error) { exists, err := config.IsBintrayConfExists() if err != nil { return nil, err } if exists { return nil, nil } val, err := cliutils.GetBoolEnvValue("JFROG_CLI_OFFER_CONFIG", true) if err != nil { return nil, err } if !val { config.SaveBintrayConf(new(config.BintrayDetails)) return nil, nil } msg := "Some CLI commands require the following common options:\n" + "- User\n" + "- API Key\n" + "- Default Package Licenses\n" + "Configuring JFrog CLI with these parameters now will save you having to include them as command options.\n" + "You can also configure these parameters later using the 'config' command.\n" + "Configure now? (y/n): " fmt.Print(msg) var confirm string fmt.Scanln(&confirm) if !cliutils.ConfirmAnswer(confirm) { config.SaveBintrayConf(new(config.BintrayDetails)) return nil, nil } bintrayDetails, err := createBintrayDetails(c, false) if err != nil { return nil, err } details, err := commands.Config(nil, bintrayDetails, true) cliutils.ExitOnErr(err) details.ApiUrl = bintrayDetails.ApiUrl details.DownloadServerUrl = bintrayDetails.DownloadServerUrl return details, nil }
func configure(c *cli.Context) { if c.NArg() > 1 { cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage()) } else if c.NArg() == 1 { if c.Args().Get(0) == "show" { commands.ShowConfig() } else if c.Args().Get(0) == "clear" { commands.ClearConfig() } else { cliutils.Exit(cliutils.ExitCodeError, "Unknown argument '"+c.Args().Get(0)+"'. Available arguments are 'show' and 'clear'.") } } else { interactive := cliutils.GetBoolFlagValue(c, "interactive", true) if !interactive { if c.String("user") == "" || c.String("key") == "" { cliutils.Exit(cliutils.ExitCodeError, "The --user and --key options are mandatory when the --interactive option is set to false") } } bintrayDetails, err := createBintrayDetails(c, false) cliutils.ExitOnErr(err) commands.Config(bintrayDetails, nil, interactive) } }
func accessKeys(c *cli.Context) { org := c.String("org") if c.NArg() == 0 { bintrayDetails, err := createBintrayDetails(c, true) cliutils.ExitOnErr(err) err = commands.ShowAccessKeys(bintrayDetails, org) cliutils.ExitOnErr(err) return } if c.NArg() != 2 { cliutils.Exit(cliutils.ExitCodeError, "Wrong number of arguments. "+cliutils.GetDocumentationMessage()) } keyId := c.Args().Get(1) var flags *commands.AccessKeyFlags var err error switch c.Args().Get(0) { case "show": flags, err = createAccessKeyFlagsForShowAndDelete(keyId, c) cliutils.ExitOnErr(err) err = commands.ShowAccessKey(flags, org) case "create": flags, err = createAccessKeyFlagsForCreateAndUpdate(keyId, c) cliutils.ExitOnErr(err) err = commands.CreateAccessKey(flags, org) case "update": flags, err = createAccessKeyFlagsForCreateAndUpdate(keyId, c) cliutils.ExitOnErr(err) err = commands.UpdateAccessKey(flags, org) case "delete": flags, err = createAccessKeyFlagsForShowAndDelete(keyId, c) cliutils.ExitOnErr(err) err = commands.DeleteAccessKey(flags, org) default: cliutils.Exit(cliutils.ExitCodeError, "Expecting show, create, update or delete before the key argument. Got "+c.Args().Get(0)) } cliutils.ExitOnErr(err) }
func buildCleanCmd(c *cli.Context) { vlidateBuildInfoArgument(c) err := commands.BuildClean(c.Args().Get(0), c.Args().Get(1)) cliutils.ExitOnErr(err) }