Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 45 additions & 25 deletions agent/plugins/commands/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ var askYesNo = coreutils.AskYesNo
var isNonInteractive = agentcommon.IsNonInteractive

const updateAllConfirmPrompt = "Update all discovered plugins under the given harness(es) to their latest version in the repository? " +
"Each install folder name is used as the repository slug (same as update --slug). " +
"Matching packages will be updated, including installs that were not made with JFrog CLI."

// pluginBackupDirName is the directory under the plugins parent where update backups are stored.
Expand All @@ -50,45 +49,66 @@ type preUpdate struct {
func RunUpdate(c *components.Context) error {
all := c.GetBoolFlagValue("all")
slugFlag := strings.TrimSpace(c.GetStringFlagValue("slug"))
if err := validateUpdateArgs(c, all, slugFlag); err != nil {
return err
}

opts, err := newUpdate(c)
if err != nil {
return err
}
if all {
return runUpdateAllMode(opts)
}
return runSingleSlugUpdate(c, opts, slugFlag)
}

func validateUpdateArgs(c *components.Context, all bool, slugFlag string) error {
if !all && slugFlag == "" {
if c.GetNumberOfArgs() > 0 {
return fmt.Errorf("unexpected positional argument(s); use --slug to specify the plugin")
}
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>]")
}
if all {
if slugFlag != "" {
return fmt.Errorf("--all cannot be combined with --slug; it updates every installed plugin for the given --harness list")
}
if c.GetNumberOfArgs() > 0 {
return fmt.Errorf("unexpected positional argument(s); use --slug or --all")
}
if strings.TrimSpace(c.GetStringFlagValue("version")) != "" {
return fmt.Errorf("--all cannot be combined with --version; it always updates to the latest version")
}
if strings.TrimSpace(c.GetStringFlagValue("path")) != "" {
return fmt.Errorf("--all cannot be combined with --path; --path targets a single install directory")
}
if !all {
return nil
}

opts, err := newUpdate(c)
if err != nil {
return err
if slugFlag != "" {
return fmt.Errorf("--all cannot be combined with --slug; it updates every installed plugin for the given --harness list")
}
if c.GetNumberOfArgs() > 0 {
return fmt.Errorf("unexpected positional argument(s); use --slug or --all")
}
if all && opts.flags.AbsoluteInstallBaseDir != "" {
if strings.TrimSpace(c.GetStringFlagValue("version")) != "" {
return fmt.Errorf("--all cannot be combined with --version; it always updates to the latest version")
}
if strings.TrimSpace(c.GetStringFlagValue("path")) != "" {
return fmt.Errorf("--all cannot be combined with --path; --path targets a single install directory")
}
return nil
}

func validateUpdateAllTargets(flags agentcommon.InstallFlagsResult) error {
if flags.AbsoluteInstallBaseDir != "" {
return fmt.Errorf("--all requires --harness; --path is not supported")
}
if all && len(opts.flags.Specs) == 0 {
if len(flags.Specs) == 0 {
return fmt.Errorf("--all requires --harness <name[,name...]>")
}
return nil
}

if all {
if err := confirmUpdateAll(opts); err != nil {
return err
}
return runUpdateAll(opts)
func runUpdateAllMode(opts update) error {
if err := validateUpdateAllTargets(opts.flags); err != nil {
return err
}
if err := confirmUpdateAll(opts); err != nil {
return err
}
return runUpdateAll(opts)
}

func runSingleSlugUpdate(c *components.Context, opts update, slugFlag string) error {
if c.GetNumberOfArgs() > 0 {
return fmt.Errorf("unexpected positional argument(s); use --slug to specify the plugin")
}
Expand Down
10 changes: 0 additions & 10 deletions agent/skills/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func GetSubCommands() []components.Command {
Name: "update",
Flags: flagkit.GetCommandFlags(flagkit.SkillsUpdate),
Description: "Update an installed skill.",
Arguments: getUpdateArguments(),
Action: update.RunUpdate,
},
{
Expand Down Expand Up @@ -85,15 +84,6 @@ func getInstallArguments() []components.Argument {
}
}

func getUpdateArguments() []components.Argument {
return []components.Argument{
{
Name: "slug",
Description: "Skill slug to update.",
},
}
}

func getDeleteArguments() []components.Argument {
return []components.Argument{
{
Expand Down
3 changes: 2 additions & 1 deletion agent/skills/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ func TestGetSubCommands_DescriptionsAndArguments(t *testing.T) {
assert.Equal(t, "Skill slug to install.", installCmd.Arguments[0].Description)

updateCmd := byName["update"]
assert.NotNil(t, updateCmd.Action)
assert.Empty(t, updateCmd.Arguments)
assert.Equal(t, "Update an installed skill.", updateCmd.Description)
assert.Equal(t, "Skill slug to update.", updateCmd.Arguments[0].Description)

searchCmd := byName["search"]
assert.Equal(t, "Search for skills in Artifactory.", searchCmd.Description)
Expand Down
Loading
Loading