(name, version string)
| 172 | } |
| 173 | |
| 174 | func (c *client) Update(name, version string) (*Metadata, error) { |
| 175 | path, metadata, err := c.GetByName(name) |
| 176 | if err != nil { |
| 177 | return nil, err |
| 178 | } else if metadata == nil { |
| 179 | return nil, fmt.Errorf("couldn't find plugin %s", name) |
| 180 | } |
| 181 | |
| 182 | oldVersion, err := c.parseVersion(metadata.Version) |
| 183 | if err != nil { |
| 184 | return nil, errors.Wrap(err, "parse old version") |
| 185 | } |
| 186 | |
| 187 | newMetadata, err := c.installer.DownloadMetadata(path, version) |
| 188 | if err != nil { |
| 189 | return nil, err |
| 190 | } |
| 191 | |
| 192 | newVersion, err := c.parseVersion(newMetadata.Version) |
| 193 | if err != nil { |
| 194 | return nil, errors.Wrap(err, "parse new version") |
| 195 | } |
| 196 | |
| 197 | if oldVersion.EQ(newVersion) { |
| 198 | return nil, &NewestVersionError{newVersion.String()} |
| 199 | } |
| 200 | |
| 201 | c.log.Infof("Updating plugin %s to version %s", name, newMetadata.Version) |
| 202 | return c.install(path, version) |
| 203 | } |
| 204 | |
| 205 | func (c *client) parseVersion(version string) (semver.Version, error) { |
| 206 | if len(version) == 0 { |
nothing calls this directly
no test coverage detected