Skip to content

Commit d53d3c2

Browse files
committed
Implemented RPC call LibraryUninstall
1 parent 77f4efe commit d53d3c2

File tree

8 files changed

+181
-124
lines changed

8 files changed

+181
-124
lines changed

cli/lib/uninstall.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,21 @@ func initUninstallCommand() *cobra.Command {
4343
}
4444

4545
func runUninstallCommand(cmd *cobra.Command, args []string) {
46+
logrus.Info("Executing `arduino lib uninstall`")
47+
4648
instance := cli.CreateInstance()
4749
libRefs, err := librariesindex.ParseArgs(args)
4850
if err != nil {
4951
formatter.PrintError(err, "Arguments error")
5052
os.Exit(cli.ErrBadArgument)
5153
}
54+
5255
for _, library := range libRefs {
5356
lib.LibraryUninstall(context.Background(), &rpc.LibraryUninstallReq{
5457
Instance: instance,
5558
Name: library.Name,
5659
Version: library.Version.String(),
57-
})
60+
}, cli.OutputTaskProgress())
5861
}
5962

6063
logrus.Info("Done")

commands/lib/uninstall.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,28 @@ import (
2424
"github.com/arduino/arduino-cli/arduino/libraries/librariesindex"
2525
"github.com/arduino/arduino-cli/commands"
2626
"github.com/arduino/arduino-cli/rpc"
27-
"github.com/sirupsen/logrus"
2827
semver "go.bug.st/relaxed-semver"
2928
)
3029

31-
func LibraryUninstall(ctx context.Context, req *rpc.LibraryUninstallReq) (*rpc.LibraryUninstallResp, error) {
32-
logrus.Info("Executing `arduino lib uninstall`")
33-
30+
func LibraryUninstall(ctx context.Context, req *rpc.LibraryUninstallReq, taskCB commands.TaskProgressCB) error {
3431
lm := commands.GetLibraryManager(req)
3532
var version *semver.Version
36-
if v, err := semver.Parse(req.GetVersion()); err == nil {
37-
version = v
38-
} else {
39-
return nil, fmt.Errorf("invalid version: %s", err)
33+
if req.GetVersion() != "" {
34+
if v, err := semver.Parse(req.GetVersion()); err == nil {
35+
version = v
36+
} else {
37+
return fmt.Errorf("invalid version: %s", err)
38+
}
4039
}
4140
ref := &librariesindex.Reference{Name: req.GetName(), Version: version}
4241
lib := lm.FindByReference(ref)
4342
if lib == nil {
44-
return nil, fmt.Errorf("library not installed: %s", ref.String())
45-
} else {
46-
// formatter.Print("Uninstalling " + lib.String()) tramite il CBTAsk
47-
lm.Uninstall(lib)
43+
return fmt.Errorf("library not installed: %s", ref.String())
4844
}
4945

50-
return &rpc.LibraryUninstallResp{}, nil
46+
taskCB(&rpc.TaskProgress{Name: "Uninstalling " + lib.String()})
47+
lm.Uninstall(lib)
48+
taskCB(&rpc.TaskProgress{Completed: true})
49+
50+
return nil
5151
}

daemon/client/client.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ func main() {
354354

355355
// LIB UNINSTALL
356356
fmt.Println("=== calling LibraryUninstall(WiFi101@0.15.3)")
357-
libUninstallResp, err := client.LibraryUninstall(context.Background(), &rpc.LibraryUninstallReq{
357+
libUninstallRespStream, err := client.LibraryUninstall(context.Background(), &rpc.LibraryUninstallReq{
358358
Instance: instance,
359359
Name: "WiFi101",
360360
Version: "0.15.3",
@@ -363,8 +363,21 @@ func main() {
363363
fmt.Printf("Error uninstalling: %s\n", err)
364364
os.Exit(1)
365365
}
366-
fmt.Printf("---> %+v\n", libUninstallResp)
367-
fmt.Println()
366+
for {
367+
uninstallResp, err := libUninstallRespStream.Recv()
368+
if err == io.EOF {
369+
fmt.Printf("---> %+v\n", uninstallResp)
370+
fmt.Println()
371+
break
372+
}
373+
if err != nil {
374+
fmt.Printf("uninstall error: %s\n", err)
375+
os.Exit(1)
376+
}
377+
if uninstallResp.GetTaskProgress() != nil {
378+
fmt.Printf(">> TASK: %s\n", uninstallResp.GetTaskProgress())
379+
}
380+
}
368381

369382
// DESTROY
370383
fmt.Println("=== calling Destroy()")

daemon/daemon.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,12 @@ func (s *ArduinoCoreServerImpl) LibraryInstall(req *rpc.LibraryInstallReq, strea
196196
return stream.Send(&rpc.LibraryInstallResp{})
197197
}
198198

199-
func (s *ArduinoCoreServerImpl) LibraryUninstall(ctx context.Context, req *rpc.LibraryUninstallReq) (*rpc.LibraryUninstallResp, error) {
200-
return lib.LibraryUninstall(ctx, req)
199+
func (s *ArduinoCoreServerImpl) LibraryUninstall(req *rpc.LibraryUninstallReq, stream rpc.ArduinoCore_LibraryUninstallServer) error {
200+
err := lib.LibraryUninstall(stream.Context(), req,
201+
func(p *rpc.TaskProgress) { stream.Send(&rpc.LibraryUninstallResp{TaskProgress: p}) },
202+
)
203+
if err != nil {
204+
return err
205+
}
206+
return stream.Send(nil)
201207
}

rpc/commands.pb.go

Lines changed: 113 additions & 86 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rpc/commands.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ service ArduinoCore {
7070

7171
rpc LibraryInstall(LibraryInstallReq) returns (stream LibraryInstallResp);
7272

73-
rpc LibraryUninstall(LibraryUninstallReq) returns (LibraryUninstallResp);
73+
rpc LibraryUninstall(LibraryUninstallReq) returns (stream LibraryUninstallResp);
7474
}
7575

7676
// Configuration contains information to instantiate an Arduino Platform Service

rpc/lib.pb.go

Lines changed: 25 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rpc/lib.proto

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ option go_package = "github.com/arduino/arduino-cli/rpc";
2323

2424
import "common.proto";
2525

26-
2726
message LibraryDownloadReq {
2827
Instance instance = 1;
2928
string name = 2;
@@ -52,5 +51,5 @@ message LibraryUninstallReq {
5251
}
5352

5453
message LibraryUninstallResp {
55-
54+
TaskProgress task_progress = 1;
5655
}

0 commit comments

Comments
 (0)