Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Summarise plugins list #2662

Merged
merged 1 commit into from
Jul 24, 2024

Conversation

itowlson
Copy link
Collaborator

Fixes #2638, but:

  • I kept the existing default behaviour and put this on a flag, because it's a breaking change and I vaguely think some things consume the existing.output. We can switch the default behavious in v3.
  • After implementing the behaviour proposed in Hide old plugin versions in spin plugins list #2638, I found it awkward because the number after the plugin meant different things (installed or latest) depending on context. So this PR instead proposes a summary where the number by the plugin is always the latest version, and if you have a different version installed, then that's shown in the [installed] bracket. E.g.
$ spin plugins list --summary
check-for-update 0.1.0 [installed]
cloud-gpu 0.1.0
js2wasm 0.6.1 [installed]
kube 0.1.1
py2wasm 0.3.2 [installed version: 0.3.0]

Note for reviewers: The underlying struct for plugin listing gets a little weird as a result of this, because it can now represent either a single version of a plugin, or an entire plugin (accompanied with latest/installed versions). I considered splitting it out into two different structs, but that would have made the code rather more complicated. Possibly it could be an enum but it didn't feel worth the candle. Definitely open to feedback on this!

Copy link
Collaborator

@rylev rylev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine since it's relatively self contained, but I do find it to be slightly hard to follow since we have a bunch of state that mutates as we go along. I would personally find a more verbose solution easier to read, but I won't block this PR from landing if you disagree.

.collect()
}

fn latest(mut plugins: Vec<PluginDescriptor>) -> (Option<PluginDescriptor>, Vec<PluginDescriptor>) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is non-trivial enough that a doc comment explaining what this function would be very helpful.

fn latest(mut plugins: Vec<PluginDescriptor>) -> (Option<PluginDescriptor>, Vec<PluginDescriptor>) {
let Ok(versions) = plugins
.iter()
.map(|pd| semver::Version::parse(&pd.version))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd hate to make this more complicated, but perhaps we want to treat unparseable versions as not possibly being the latest but still try with any versions that do successfully parse.

else {
return (None, plugins);
};
let Some(latest_ver) = versions.iter().max() else {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to do versions.iter().enumerate().max() to get the index of the max item. This index should match the index of the of the plugin in the plugins collection which means you can avoid turning the version into a string and iterating over the plugins collection again.

@itowlson itowlson force-pushed the plugins-list-only-latest branch 2 times, most recently from ea3686f to d49a5a0 Compare July 22, 2024 00:59
Signed-off-by: itowlson <ivan.towlson@fermyon.com>
@itowlson itowlson force-pushed the plugins-list-only-latest branch from d49a5a0 to 41ec2a8 Compare July 24, 2024 01:48
@itowlson itowlson merged commit ca1dcd3 into spinframework:main Jul 24, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hide old plugin versions in spin plugins list
2 participants