@@ -7,8 +7,10 @@ import (
7
7
"log"
8
8
"os"
9
9
"path/filepath"
10
+ "sort"
10
11
"strings"
11
12
13
+ "github.com/AlecAivazis/survey/v2"
12
14
"github.com/b4b4r07/afx/pkg/config"
13
15
"github.com/b4b4r07/afx/pkg/env"
14
16
"github.com/b4b4r07/afx/pkg/errors"
@@ -191,6 +193,45 @@ func (m *meta) prompt() (config.Package, error) {
191
193
return nil , errors .New ("pkg not found" )
192
194
}
193
195
196
+ func (m * meta ) askRunCommand (op interface {}, pkgs []string ) (bool , error ) {
197
+ var do string
198
+ switch op .(type ) {
199
+ case installCmd :
200
+ do = "install"
201
+ case uninstallCmd :
202
+ do = "uninstall"
203
+ case updateCmd :
204
+ do = "update"
205
+ default :
206
+ return false , errors .New ("unsupported command type" )
207
+ }
208
+
209
+ length := 3
210
+ target := strings .Join (pkgs , ", " )
211
+ if len (pkgs ) > length {
212
+ target = fmt .Sprintf ("%s, ... (%d packages)" , strings .Join (pkgs [:length ], ", " ), len (pkgs ))
213
+ }
214
+
215
+ yes := false
216
+ confirm := survey.Confirm {
217
+ Message : fmt .Sprintf ("OK to %s these packages? %s" , do , color .YellowString (target )),
218
+ }
219
+
220
+ if len (pkgs ) > length {
221
+ helpMessage := "\n "
222
+ sort .Strings (pkgs )
223
+ for _ , pkg := range pkgs {
224
+ helpMessage += fmt .Sprintf ("- %s\n " , pkg )
225
+ }
226
+ confirm .Help = helpMessage
227
+ }
228
+
229
+ if err := survey .AskOne (& confirm , & yes ); err != nil {
230
+ return false , errors .Wrap (err , "failed to catch answer from console" )
231
+ }
232
+ return yes , nil
233
+ }
234
+
194
235
func getNameInPackages (pkgs []config.Package ) []string {
195
236
var keys []string
196
237
for _ , pkg := range pkgs {
0 commit comments