Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Zheng <[email protected]>
  • Loading branch information
Two-Hearts committed Nov 17, 2023
1 parent b8592c8 commit 36ba607
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
18 changes: 12 additions & 6 deletions cmd/notation/plugin/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ Example - Install plugin from URL, SHA256 checksum is required:
},
}
opts.LoggingFlagOpts.ApplyFlags(command.Flags())
command.Flags().BoolVar(&opts.isFile, "file", false, "if set, install plugin from a file in file system")
command.Flags().BoolVar(&opts.isUrl, "url", false, " if set, install plugin from a HTTPS URL")
command.Flags().BoolVar(&opts.isFile, "file", false, "install plugin from a file in file system")
command.Flags().BoolVar(&opts.isUrl, "url", false, " install plugin from a HTTPS URL")
command.Flags().StringVar(&opts.inputCheckSum, "sha256sum", "", "must match SHA256 of the plugin source")
command.Flags().BoolVar(&opts.force, "force", false, "force the installation of a plugin")
command.MarkFlagsMutuallyExclusive("file", "url")
Expand Down Expand Up @@ -284,23 +284,25 @@ func installPluginExecutable(ctx context.Context, fileName string, pluginName st
}
pluginVersion := pluginMetadata.Version
// check plugin existence and version
var currentPluginVersion string
if !force {
currentPluginMetadata, err := notationplugin.GetPluginMetadataIfExist(ctx, pluginName)
if err != nil && !errors.Is(err, os.ErrNotExist) {
return err
}
currentPluginVersion = currentPluginMetadata.Version
if err == nil { // plugin already installed
comp, err := notationplugin.ComparePluginVersion(pluginVersion, currentPluginMetadata.Version)
comp, err := notationplugin.ComparePluginVersion(pluginVersion, currentPluginVersion)
if err != nil {
return err
}
if comp < 0 {
return fmt.Errorf("%s current version %s is larger than the installing version %s. To view a list of installed plugins, use `notation plugin list`", pluginName, currentPluginMetadata.Version, pluginVersion)
return fmt.Errorf("%s current version %s is higher than the installing version %s.\n To view a list of installed plugins, use `notation plugin list`. If you want to install an old version, use \"--force\" to force the installation", pluginName, currentPluginVersion, pluginVersion)
}
if comp == 0 {
// if version is the same, no action is needed and no error is
// returned
fmt.Printf("Plugin %s with version %s is already installed. To view a list of installed plugins, use `notation plugin list`.\n", pluginName, currentPluginMetadata.Version)
fmt.Printf("Plugin %s with version %s already exists.\n To view a list of installed plugins, use `notation plugin list`.\n", pluginName, currentPluginVersion)
return nil
}
}
Expand All @@ -320,6 +322,10 @@ func installPluginExecutable(ctx context.Context, fileName string, pluginName st
if err != nil {
return err
}
fmt.Printf("Succussefully installed plugin %s, version %s\n", pluginName, pluginVersion)
if currentPluginVersion != "" {
fmt.Printf("Succussefully installed plugin %s, updated the version from %s to %s\n", pluginName, currentPluginVersion, pluginVersion)
} else {
fmt.Printf("Succussefully installed plugin %s, version %s\n", pluginName, pluginVersion)
}
return nil
}
2 changes: 1 addition & 1 deletion test/e2e/suite/plugin/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var _ = Describe("notation plugin install", func() {
MatchContent("Succussefully installed plugin e2e-plugin, version 1.0.0\n")

notation.Exec("plugin", "install", "--file", NotationE2EPluginTarGzPath).
MatchContent("Plugin e2e-plugin with version 1.0.0 is already installed. To view a list of installed plugins, use `notation plugin list`.\n")
MatchContent("Plugin e2e-plugin with version 1.0.0 already exists.\n To view a list of installed plugins, use `notation plugin list`.\n")
})
})

Expand Down

0 comments on commit 36ba607

Please sign in to comment.