@@ -48,34 +48,48 @@ func (s *arduinoCoreServerImpl) ProfileLibAdd(ctx context.Context, req *rpc.Prof
48
48
return nil , err
49
49
}
50
50
51
- // Obtain the library index from the manager
52
- li , err := instances .GetLibrariesIndex (req .GetInstance ())
53
- if err != nil {
54
- return nil , err
55
- }
56
- version , err := parseVersion (req .LibVersion )
57
- if err != nil {
58
- return nil , err
59
- }
60
- libRelease , err := li .FindRelease (req .GetLibName (), version )
61
- if err != nil {
62
- return nil , err
63
- }
64
-
65
- // If the library has been already added to the profile, just update the version
66
- if lib , _ := profile .GetLibrary (req .LibName , false ); lib != nil {
67
- lib .Version = libRelease .GetVersion ()
51
+ var addedLib * sketch.ProfileLibraryReference
52
+ if reqLocalLib := req .GetLibrary ().GetLocalLibrary (); reqLocalLib != nil {
53
+ // Add a local library
54
+ path := paths .New (reqLocalLib .GetPath ())
55
+ if path == nil {
56
+ return nil , & cmderrors.InvalidArgumentError {Message : "invalid library path" }
57
+ }
58
+ addedLib = & sketch.ProfileLibraryReference {InstallDir : path }
59
+ profile .Libraries = append (profile .Libraries , addedLib )
60
+ } else if reqIndexLib := req .GetLibrary ().GetIndexLibrary (); reqIndexLib != nil {
61
+ // Obtain the library index from the manager
62
+ li , err := instances .GetLibrariesIndex (req .GetInstance ())
63
+ if err != nil {
64
+ return nil , err
65
+ }
66
+ version , err := parseVersion (reqIndexLib .GetVersion ())
67
+ if err != nil {
68
+ return nil , err
69
+ }
70
+ libRelease , err := li .FindRelease (reqIndexLib .GetName (), version )
71
+ if err != nil {
72
+ return nil , err
73
+ }
74
+ // If the library has been already added to the profile, just update the version
75
+ if lib , _ := profile .GetLibrary (reqIndexLib .GetName (), false ); lib != nil {
76
+ lib .Version = libRelease .GetVersion ()
77
+ addedLib = lib
78
+ } else {
79
+ addedLib = & sketch.ProfileLibraryReference {
80
+ Library : reqIndexLib .GetName (),
81
+ Version : libRelease .GetVersion (),
82
+ }
83
+ profile .Libraries = append (profile .Libraries , addedLib )
84
+ }
68
85
} else {
69
- profile .Libraries = append (profile .Libraries , & sketch.ProfileLibraryReference {
70
- Library : req .GetLibName (),
71
- Version : libRelease .GetVersion (),
72
- })
86
+ return nil , & cmderrors.InvalidArgumentError {Message : "library must be specified" }
73
87
}
74
88
75
89
err = projectFilePath .WriteFile ([]byte (sk .Project .AsYaml ()))
76
90
if err != nil {
77
91
return nil , err
78
92
}
79
93
80
- return & rpc.ProfileLibAddResponse {LibName : req . LibName , LibVersion : libRelease . GetVersion (). String (), ProfileName : profileName }, nil
94
+ return & rpc.ProfileLibAddResponse {Library : addedLib . ToRpc (), ProfileName : profileName }, nil
81
95
}
0 commit comments