@@ -49,64 +49,81 @@ Otherwise, the built-in default plugin list is used.`,
4949 manifest = & plugin.Manifest {}
5050 }
5151
52- // Filter out already-installed plugins.
53- var missing []plugin.Plugin
54- var skipped []string
55- for _ , p := range plugins {
56- if _ , exists := manifest .Get (p .Name ); exists {
57- skipped = append (skipped , p .Name )
58- } else {
59- missing = append (missing , p )
60- }
61- }
52+ toInstall , toReinstall , skipped := plugin .CategorizeForInit (plugins , manifest )
6253
6354 if len (skipped ) > 0 {
6455 terminal .Infof ("Skipping %d already installed plugin(s): %s" , len (skipped ), formatNames (skipped ))
6556 }
6657
67- if len (missing ) == 0 {
58+ if len (toInstall ) == 0 && len ( toReinstall ) == 0 {
6859 terminal .Success ("All plugins are already installed." )
6960 return nil
7061 }
7162
72- terminal .Infof ("Installing %d missing plugin(s)..." , len (missing ))
63+ if len (toInstall ) > 0 {
64+ terminal .Infof ("Installing %d new plugin(s)..." , len (toInstall ))
65+ }
66+ if len (toReinstall ) > 0 {
67+ terminal .Infof ("Reinstalling %d plugin(s) due to install URL changes:" , len (toReinstall ))
68+ for _ , p := range toReinstall {
69+ if entry , ok := manifest .Get (p .Name ); ok {
70+ fmt .Printf (" • %s: %s → %s\n " , p .Name , entry .Source , p .Script )
71+ }
72+ }
73+ }
7374 fmt .Println ()
7475
7576 var failed []string
7677
77- for _ , p := range missing {
78+ runInstall := func (p plugin.Plugin , reinstall bool ) {
79+ verb := "Installing"
80+ if reinstall {
81+ verb = "Reinstalling"
82+ }
83+
7884 spinner := uicli .NewSpinner ().
7985 WithStyle (uicli .SpinnerDots ).
8086 WithColor (uicli .CyanColor ).
81- WithMessage (fmt .Sprintf ("Installing %q..." , p .Name )).
87+ WithMessage (fmt .Sprintf ("%s %q..." , verb , p .Name )).
8288 Start ()
8389
8490 inst , err := installer .FromPlugin (p )
8591 if err != nil {
8692 spinner .Error (fmt .Sprintf ("Failed to install %q: %v" , p .Name , err ))
8793 failed = append (failed , fmt .Sprintf ("%s (%v)" , p .Name , err ))
88- continue
94+ return
8995 }
9096
9197 version , installErr := inst .Install (p .Name )
9298 if installErr != nil {
9399 spinner .Error (fmt .Sprintf ("Failed to install %q: %v" , p .Name , installErr ))
94100 failed = append (failed , fmt .Sprintf ("%s (%v)" , p .Name , installErr ))
95- continue
101+ return
96102 }
97103
98104 manifest .Add (p .Name , version , inst .PluginType (), inst .Source (), "" )
99105 if p .Description != "" {
100106 manifest .SetDescription (p .Name , p .Description )
101107 }
102108
109+ doneVerb := "Installed"
110+ if reinstall {
111+ doneVerb = "Reinstalled"
112+ }
103113 if path , ok := plugin .Find (p .Name ); ok {
104- spinner .Success (fmt .Sprintf ("Installed %q (%s)" , p .Name , path ))
114+ spinner .Success (fmt .Sprintf ("%s %q (%s)" , doneVerb , p .Name , path ))
105115 } else {
106- spinner .Success (fmt .Sprintf ("Installed %q" , p .Name ))
116+ spinner .Success (fmt .Sprintf ("%s %q" , doneVerb , p .Name ))
107117 }
108118 }
109119
120+ for _ , p := range toInstall {
121+ runInstall (p , false )
122+ }
123+ for _ , p := range toReinstall {
124+ runInstall (p , true )
125+ }
126+
110127 if err := manifest .Save (); err != nil {
111128 return fmt .Errorf ("failed to save manifest: %w" , err )
112129 }
@@ -117,7 +134,8 @@ Otherwise, the built-in default plugin list is used.`,
117134 }
118135
119136 fmt .Println ()
120- terminal .Successf ("All %d plugins installed!" , len (missing ))
137+ total := len (toInstall ) + len (toReinstall )
138+ terminal .Successf ("All %d plugin(s) processed!" , total )
121139 return nil
122140 },
123141}
0 commit comments