@@ -24,7 +24,6 @@ var askYesNo = coreutils.AskYesNo
2424var isNonInteractive = agentcommon .IsNonInteractive
2525
2626const updateAllConfirmPrompt = "Update all discovered plugins under the given harness(es) to their latest version in the repository? " +
27- "Each install folder name is used as the repository slug (same as update --slug). " +
2827 "Matching packages will be updated, including installs that were not made with JFrog CLI."
2928
3029// pluginBackupDirName is the directory under the plugins parent where update backups are stored.
@@ -50,45 +49,66 @@ type preUpdate struct {
5049func RunUpdate (c * components.Context ) error {
5150 all := c .GetBoolFlagValue ("all" )
5251 slugFlag := strings .TrimSpace (c .GetStringFlagValue ("slug" ))
52+ if err := validateUpdateArgs (c , all , slugFlag ); err != nil {
53+ return err
54+ }
55+
56+ opts , err := newUpdate (c )
57+ if err != nil {
58+ return err
59+ }
60+ if all {
61+ return runUpdateAllMode (opts )
62+ }
63+ return runSingleSlugUpdate (c , opts , slugFlag )
64+ }
65+
66+ func validateUpdateArgs (c * components.Context , all bool , slugFlag string ) error {
5367 if ! all && slugFlag == "" {
5468 if c .GetNumberOfArgs () > 0 {
5569 return fmt .Errorf ("unexpected positional argument(s); use --slug to specify the plugin" )
5670 }
5771 return fmt .Errorf ("usage: jf agent plugins update --slug <slug> (--harness <name[,name...]> [--global] [--project-dir <dir>] | --path <dir>) [--repo <repo>] [--version <ver>] [--dry-run] [--force] [--format <table|json>]\n jf agent plugins update --all --harness <name[,name...]> [--global] [--project-dir <dir>] [--repo <repo>] [--dry-run] [--force] [--format <table|json>]" )
5872 }
59- if all {
60- if slugFlag != "" {
61- return fmt .Errorf ("--all cannot be combined with --slug; it updates every installed plugin for the given --harness list" )
62- }
63- if c .GetNumberOfArgs () > 0 {
64- return fmt .Errorf ("unexpected positional argument(s); use --slug or --all" )
65- }
66- if strings .TrimSpace (c .GetStringFlagValue ("version" )) != "" {
67- return fmt .Errorf ("--all cannot be combined with --version; it always updates to the latest version" )
68- }
69- if strings .TrimSpace (c .GetStringFlagValue ("path" )) != "" {
70- return fmt .Errorf ("--all cannot be combined with --path; --path targets a single install directory" )
71- }
73+ if ! all {
74+ return nil
7275 }
73-
74- opts , err := newUpdate (c )
75- if err != nil {
76- return err
76+ if slugFlag != "" {
77+ return fmt .Errorf ("--all cannot be combined with --slug; it updates every installed plugin for the given --harness list" )
78+ }
79+ if c .GetNumberOfArgs () > 0 {
80+ return fmt .Errorf ("unexpected positional argument(s); use --slug or --all" )
81+ }
82+ if strings .TrimSpace (c .GetStringFlagValue ("version" )) != "" {
83+ return fmt .Errorf ("--all cannot be combined with --version; it always updates to the latest version" )
7784 }
78- if all && opts .flags .AbsoluteInstallBaseDir != "" {
85+ if strings .TrimSpace (c .GetStringFlagValue ("path" )) != "" {
86+ return fmt .Errorf ("--all cannot be combined with --path; --path targets a single install directory" )
87+ }
88+ return nil
89+ }
90+
91+ func validateUpdateAllTargets (flags agentcommon.InstallFlagsResult ) error {
92+ if flags .AbsoluteInstallBaseDir != "" {
7993 return fmt .Errorf ("--all requires --harness; --path is not supported" )
8094 }
81- if all && len (opts . flags .Specs ) == 0 {
95+ if len (flags .Specs ) == 0 {
8296 return fmt .Errorf ("--all requires --harness <name[,name...]>" )
8397 }
98+ return nil
99+ }
84100
85- if all {
86- if err := confirmUpdateAll (opts ); err != nil {
87- return err
88- }
89- return runUpdateAll (opts )
101+ func runUpdateAllMode (opts update ) error {
102+ if err := validateUpdateAllTargets (opts .flags ); err != nil {
103+ return err
90104 }
105+ if err := confirmUpdateAll (opts ); err != nil {
106+ return err
107+ }
108+ return runUpdateAll (opts )
109+ }
91110
111+ func runSingleSlugUpdate (c * components.Context , opts update , slugFlag string ) error {
92112 if c .GetNumberOfArgs () > 0 {
93113 return fmt .Errorf ("unexpected positional argument(s); use --slug to specify the plugin" )
94114 }
@@ -145,7 +165,7 @@ func runUpdateOnSlug(opts update, slug, requestedVersion string) error {
145165 return err
146166 }
147167
148- targetVersion , err := resolveTargetVersion (opts .serverDetails , opts .repoKey , slug , requestedVersion , opts .quiet )
168+ targetVersion , err := resolvePluginVersion (opts .serverDetails , opts .repoKey , slug , requestedVersion , opts .quiet )
149169 if err != nil {
150170 return err
151171 }
@@ -294,10 +314,6 @@ func finalizeUpdateAll(combined []agentcommon.UpdateAllSummaryRow, outcome updat
294314 return nil
295315}
296316
297- func resolveTargetVersion (serverDetails * config.ServerDetails , repoKey , slug , requested string , quiet bool ) (string , error ) {
298- return resolvePluginVersion (serverDetails , repoKey , slug , requested , quiet )
299- }
300-
301317// updateSlugAcrossTargets fetches the slug once and runs the backup+copy loop per target.
302318// Returns the per-target summary rows. Targets that are not installed or already at the
303319// target version are reported without performing a download.
0 commit comments