Skip to content

Commit 8f5b183

Browse files
committed
Fixed completion in profile lib remove
1 parent d7b159c commit 8f5b183

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

internal/cli/arguments/completion.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020

2121
"github.com/arduino/arduino-cli/internal/cli/instance"
2222
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
23+
"github.com/arduino/go-paths-helper"
2324
"go.bug.st/f"
2425
)
2526

@@ -172,3 +173,19 @@ func GetAvailablePorts(ctx context.Context, srv rpc.ArduinoCoreServiceServer) []
172173
// Transform the data structure for the completion (DetectedPort -> Port)
173174
return f.Map(list.GetPorts(), (*rpc.DetectedPort).GetPort)
174175
}
176+
177+
// GetProfileLibraries is an helper function useful to autocomplete.
178+
// It returns a list of libraries present in the specified profile.
179+
func GetProfileLibraries(ctx context.Context, srv rpc.ArduinoCoreServiceServer, sketchPath *paths.Path, profile string) []string {
180+
resp, err := srv.ProfileLibList(ctx, &rpc.ProfileLibListRequest{
181+
SketchPath: sketchPath.String(),
182+
ProfileName: profile,
183+
})
184+
if err != nil {
185+
return nil
186+
}
187+
res := f.Map(resp.GetLibraries(), func(lib *rpc.ProfileLibraryReference) string {
188+
return lib.GetIndexLibrary().GetName()
189+
})
190+
return res
191+
}

internal/cli/profile/profile_lib_remove.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ func initLibRemoveCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
4646
runLibRemoveCommand(cmd.Context(), srv, args, profileArg.Get(), destDir, noDeps)
4747
},
4848
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
49-
return arguments.GetInstallableLibs(cmd.Context(), srv), cobra.ShellCompDirectiveDefault
49+
ctx := cmd.Context()
50+
sketchPath := arguments.InitSketchPath(destDir)
51+
completions := arguments.GetProfileLibraries(ctx, srv, sketchPath, profileArg.Get())
52+
return completions, cobra.ShellCompDirectiveNoFileComp
5053
},
5154
}
5255
profileArg.AddToCommand(removeCommand, srv)

0 commit comments

Comments
 (0)