Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1a2a522

Browse files
committed
Added automatic lib deps add to profile
1 parentf4170da commit1a2a522

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

‎commands/service_profile_lib_add.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ func (s *arduinoCoreServerImpl) ProfileLibAdd(ctx context.Context, req *rpc.Prof
8787
addedLibs=append(addedLibs,libRefToAdd)
8888
return
8989
}
90+
// If the same version of the library has been already added to the profile, skip it
91+
ifexistingLibRef.Version.Equal(libReleaseToAdd.GetVersion()) {
92+
skippedLibs=append(skippedLibs,libRefToAdd)
93+
return
94+
}
9095
// If the library has been already added to the profile, just update the version
9196
ifreq.GetNoOverwrite() {
9297
skippedLibs=append(skippedLibs,libRefToAdd)

‎internal/cli/profile/lib.go‎

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ func initLibCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
4949

5050
funcinitLibAddCommand(srv rpc.ArduinoCoreServiceServer)*cobra.Command {
5151
vardestDirstring
52-
52+
varnoDepsbool
53+
varnoOverwritebool
5354
addCommand:=&cobra.Command{
5455
Use:fmt.Sprintf("add %s[@%s]...",i18n.Tr("LIBRARY"),i18n.Tr("VERSION_NUMBER")),
5556
Short:i18n.Tr("Adds a library to the profile."),
@@ -59,27 +60,31 @@ func initLibAddCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
5960
" "+os.Args[0]+" profile lib add Arduino_JSON@0.2.0 --profile my_profile\n",
6061
Args:cobra.MinimumNArgs(1),
6162
Run:func(cmd*cobra.Command,args []string) {
62-
runLibAddCommand(cmd.Context(),args,srv,destDir)
63+
runLibAddCommand(cmd.Context(),args,srv,destDir,noDeps,noOverwrite)
6364
},
6465
ValidArgsFunction:func(cmd*cobra.Command,args []string,toCompletestring) ([]string, cobra.ShellCompDirective) {
6566
returnarguments.GetInstallableLibs(cmd.Context(),srv),cobra.ShellCompDirectiveDefault
6667
},
6768
}
6869

6970
addCommand.Flags().StringVar(&destDir,"dest-dir","",i18n.Tr("Location of the sketch project file."))
71+
addCommand.Flags().BoolVar(&noDeps,"no-deps",false,i18n.Tr("Do not add dependencies."))
72+
addCommand.Flags().BoolVar(&noOverwrite,"no-overwrite",false,i18n.Tr("Do not overwrite already added libraries."))
73+
7074
profileArg.AddToCommand(addCommand,srv)
7175

7276
returnaddCommand
7377
}
7478

75-
funcrunLibAddCommand(ctx context.Context,args []string,srv rpc.ArduinoCoreServiceServer,destDirstring) {
79+
funcrunLibAddCommand(ctx context.Context,args []string,srv rpc.ArduinoCoreServiceServer,destDirstring,noAddDeps,noOverwritebool) {
7680
sketchPath:=arguments.InitSketchPath(destDir)
7781

7882
instance:=instance.CreateAndInit(ctx,srv)
7983
libRefs,err:=lib.ParseLibraryReferenceArgsAndAdjustCase(ctx,srv,instance,args)
8084
iferr!=nil {
8185
feedback.Fatal(i18n.Tr("Arguments error: %v",err),feedback.ErrBadArgument)
8286
}
87+
addDeps:=!noAddDeps
8388
for_,lib:=rangelibRefs {
8489
resp,err:=srv.ProfileLibAdd(ctx,&rpc.ProfileLibAddRequest{
8590
Instance:instance,
@@ -93,16 +98,23 @@ func runLibAddCommand(ctx context.Context, args []string, srv rpc.ArduinoCoreSer
9398
},
9499
},
95100
},
101+
AddDependencies:&addDeps,
102+
NoOverwrite:&noOverwrite,
96103
})
97104
iferr!=nil {
98105
feedback.Fatal(i18n.Tr("Error adding %s to the profile %s: %v",lib.Name,profileArg.Get(),err),feedback.ErrGeneric)
99106
}
100107
added:=f.Map(resp.GetAddedLibraries(),func(l*rpc.ProfileLibraryReference)*result.ProfileLibraryReference_IndexLibraryResult {
101108
returnresult.NewProfileLibraryReference_IndexLibraryResult(l.GetIndexLibrary())
102109
})
110+
skipped:=f.Map(resp.GetSkippedLibraries(),func(l*rpc.ProfileLibraryReference)*result.ProfileLibraryReference_IndexLibraryResult {
111+
returnresult.NewProfileLibraryReference_IndexLibraryResult(l.GetIndexLibrary())
112+
})
103113
feedback.PrintResult(libAddResult{
104-
AddedLibraries:added,
105-
ProfileName:resp.ProfileName})
114+
AddedLibraries:added,
115+
SkippedLibraries:skipped,
116+
ProfileName:resp.ProfileName,
117+
})
106118
}
107119
}
108120

@@ -179,6 +191,12 @@ func (lr libAddResult) String() string {
179191
res+=fmt.Sprintf(" - %s@%s\n",l.Name,l.Version)
180192
}
181193
}
194+
iflen(lr.SkippedLibraries)>0 {
195+
res+=fmt.Sprintln(i18n.Tr("The following libraries were already present in the profile %s and were not modified:",lr.ProfileName))
196+
for_,l:=rangelr.SkippedLibraries {
197+
res+=fmt.Sprintf(" - %s@%s\n",l.Name,l.Version)
198+
}
199+
}
182200
returnres
183201
}
184202

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp