@@ -20,8 +20,8 @@ import (
2020 "github.com/two-tech-dev/endgit-cli/internal/log"
2121)
2222
23- func downloadAndSave (s * spinner.Spinner , client * api.Client , url string ) (string , error ) {
24- if err := os .MkdirAll ("plugins" , 0o755 ); err != nil {
23+ func downloadAndSave (s * spinner.Spinner , client * api.Client , url string , destDir string ) (string , error ) {
24+ if err := os .MkdirAll (destDir , 0o755 ); err != nil {
2525 s .Stop ()
2626 return "" , fmt .Errorf ("failed to create plugins directory: %w" , err )
2727 }
@@ -37,17 +37,43 @@ func downloadAndSave(s *spinner.Spinner, client *api.Client, url string) (string
3737 }
3838 }
3939
40- filename , err := client .DownloadFile (url , "plugins" , onProgress )
40+ filename , err := client .DownloadFile (url , destDir , onProgress )
4141 if err != nil {
4242 s .Stop ()
4343 return "" , fmt .Errorf ("download failed: %w" , err )
4444 }
4545
4646 s .Stop ()
47- log .Infof ("Saved to: %s" , filepath .Join ("plugins" , filename ))
47+ log .Infof ("Saved to: %s" , filepath .Join (destDir , filename ))
4848 return filename , nil
4949}
5050
51+ func resolveInstallDir () string {
52+ cwd , err := os .Getwd ()
53+ if err == nil && strings .EqualFold (filepath .Base (cwd ), "plugins" ) {
54+ return "."
55+ }
56+
57+ options := []string {
58+ "plugins/ (create if needed)" ,
59+ ". (current directory)" ,
60+ }
61+
62+ var selected string
63+ prompt := & survey.Select {
64+ Message : "Where should the plugin be saved?" ,
65+ Options : options ,
66+ }
67+ if err := survey .AskOne (prompt , & selected ); err != nil {
68+ return ""
69+ }
70+
71+ if strings .HasPrefix (selected , "plugins/" ) {
72+ return "plugins"
73+ }
74+ return "."
75+ }
76+
5177func parsePluginInput (input string ) (plugin , version , commit string , err error ) {
5278 parts := strings .SplitN (input , "@" , 2 )
5379 plugin = strings .TrimSpace (parts [0 ])
@@ -118,6 +144,11 @@ Examples:
118144 }
119145 s .Stop ()
120146
147+ destDir := resolveInstallDir ()
148+ if destDir == "" {
149+ return
150+ }
151+
121152 // DEV BUILD (COMMIT)
122153 if commit != "" {
123154 s .Suffix = fmt .Sprintf (" Searching build %.7s..." , commit )
@@ -148,7 +179,7 @@ Examples:
148179
149180 url := target .ResolveArtifactURL ()
150181
151- if _ , err := downloadAndSave (s , client , url ); err != nil {
182+ if _ , err := downloadAndSave (s , client , url , destDir ); err != nil {
152183 log .Fatal ("Failed to download" , err )
153184 }
154185 log .Successf ("Installed %s dev build #%d (%s)" , plugin , target .BuildNumber , commit [:7 ])
@@ -168,7 +199,7 @@ Examples:
168199 runtime .GOOS ,
169200 )
170201
171- if _ , err := downloadAndSave (s , client , downloadURL ); err != nil {
202+ if _ , err := downloadAndSave (s , client , downloadURL , destDir ); err != nil {
172203 log .Fatal ("Failed to download" , err )
173204 }
174205 log .Successf ("Installed %s@%s" , plugin , version )
@@ -194,7 +225,7 @@ Examples:
194225 runtime .GOOS ,
195226 )
196227
197- if _ , err := downloadAndSave (s , client , downloadURL ); err != nil {
228+ if _ , err := downloadAndSave (s , client , downloadURL , destDir ); err != nil {
198229 log .Fatal ("Failed to download" , err )
199230 }
200231 log .Successf ("Installed %s@%s" , plugin , p .LatestVersion )
0 commit comments