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

Appearance settings

Commit d6196c1

Browse filesBrowse files
authored
Added --install-in-builtin-dir flag to lib install command (#2077)
* In download query, report if a library is builtin * 'lib download' flag vars are now local * Added --install-in-builtin-dir flag in 'lib install'
1 parent a1e69dc commit d6196c1
Copy full SHA for d6196c1

File tree

Expand file treeCollapse file tree

3 files changed

+41
-14
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+41
-14
lines changed

‎commands/lib/install.go

Copy file name to clipboardExpand all lines: commands/lib/install.go
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ func LibraryInstall(ctx context.Context, req *rpc.LibraryInstallRequest, downloa
103103
if installTask.ReplacedLib != nil {
104104
downloadReason = "upgrade"
105105
}
106+
if installLocation == libraries.IDEBuiltIn {
107+
downloadReason += "-builtin"
108+
}
106109
}
107110
if err := downloadLibrary(lm, libRelease, downloadCB, taskCB, downloadReason); err != nil {
108111
return err

‎internal/cli/lib/install.go

Copy file name to clipboardExpand all lines: internal/cli/lib/install.go
+24-14Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,12 @@ import (
3434
semver "go.bug.st/relaxed-semver"
3535
)
3636

37-
var (
38-
noDeps bool
39-
noOverwrite bool
40-
gitURL bool
41-
zipPath bool
42-
)
43-
4437
func initInstallCommand() *cobra.Command {
38+
var noDeps bool
39+
var noOverwrite bool
40+
var gitURL bool
41+
var zipPath bool
42+
var useBuiltinLibrariesDir bool
4543
installCommand := &cobra.Command{
4644
Use: fmt.Sprintf("install %s[@%s]...", tr("LIBRARY"), tr("VERSION_NUMBER")),
4745
Short: tr("Installs one or more specified libraries into the system."),
@@ -53,7 +51,9 @@ func initInstallCommand() *cobra.Command {
5351
" " + os.Args[0] + " lib install --git-url https://github.com/arduino-libraries/WiFi101.git#0.16.0 # " + tr("for the specific version.") + "\n" +
5452
" " + os.Args[0] + " lib install --zip-path /path/to/WiFi101.zip /path/to/ArduinoBLE.zip\n",
5553
Args: cobra.MinimumNArgs(1),
56-
Run: runInstallCommand,
54+
Run: func(cmd *cobra.Command, args []string) {
55+
runInstallCommand(args, noDeps, noOverwrite, gitURL, zipPath, useBuiltinLibrariesDir)
56+
},
5757
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
5858
return arguments.GetInstallableLibs(), cobra.ShellCompDirectiveDefault
5959
},
@@ -62,10 +62,11 @@ func initInstallCommand() *cobra.Command {
6262
installCommand.Flags().BoolVar(&noOverwrite, "no-overwrite", false, tr("Do not overwrite already installed libraries."))
6363
installCommand.Flags().BoolVar(&gitURL, "git-url", false, tr("Enter git url for libraries hosted on repositories"))
6464
installCommand.Flags().BoolVar(&zipPath, "zip-path", false, tr("Enter a path to zip file"))
65+
installCommand.Flags().BoolVar(&useBuiltinLibrariesDir, "install-in-builtin-dir", false, tr("Install libraries in the IDE-Builtin directory"))
6566
return installCommand
6667
}
6768

68-
func runInstallCommand(cmd *cobra.Command, args []string) {
69+
func runInstallCommand(args []string, noDeps bool, noOverwrite bool, gitURL bool, zipPath bool, useBuiltinLibrariesDir bool) {
6970
instance := instance.CreateAndInit()
7071
logrus.Info("Executing `arduino-cli lib install`")
7172

@@ -80,6 +81,10 @@ func runInstallCommand(cmd *cobra.Command, args []string) {
8081
feedback.Fatal(tr("--git-url and --zip-path are disabled by default, for more information see: %v", documentationURL), feedback.ErrGeneric)
8182
}
8283
feedback.Print(tr("--git-url and --zip-path flags allow installing untrusted files, use it at your own risk."))
84+
85+
if useBuiltinLibrariesDir {
86+
feedback.Fatal(tr("--git-url or --zip-path can't be used with --install-in-builtin-dir"), feedback.ErrGeneric)
87+
}
8388
}
8489

8590
if zipPath {
@@ -123,12 +128,17 @@ func runInstallCommand(cmd *cobra.Command, args []string) {
123128
}
124129

125130
for _, libRef := range libRefs {
131+
installLocation := rpc.LibraryInstallLocation_LIBRARY_INSTALL_LOCATION_USER
132+
if useBuiltinLibrariesDir {
133+
installLocation = rpc.LibraryInstallLocation_LIBRARY_INSTALL_LOCATION_BUILTIN
134+
}
126135
libraryInstallRequest := &rpc.LibraryInstallRequest{
127-
Instance: instance,
128-
Name: libRef.Name,
129-
Version: libRef.Version,
130-
NoDeps: noDeps,
131-
NoOverwrite: noOverwrite,
136+
Instance: instance,
137+
Name: libRef.Name,
138+
Version: libRef.Version,
139+
NoDeps: noDeps,
140+
NoOverwrite: noOverwrite,
141+
InstallLocation: installLocation,
132142
}
133143
err := lib.LibraryInstall(context.Background(), libraryInstallRequest, feedback.ProgressBar(), feedback.TaskProgress())
134144
if err != nil {

‎internal/integrationtest/lib/lib_test.go

Copy file name to clipboardExpand all lines: internal/integrationtest/lib/lib_test.go
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,4 +1518,18 @@ func TestLibQueryParameters(t *testing.T) {
15181518
require.NoError(t, err)
15191519
require.Contains(t, string(stdout),
15201520
"Starting download \x1b[36murl\x1b[0m=\"https://downloads.arduino.cc/libraries/github.com/arduino-libraries/WiFi101-0.16.1.zip?query=download\"\n")
1521+
1522+
// Check query=install-builtin when a library dependency is installed in builtin-directory
1523+
cliEnv := cli.GetDefaultEnv()
1524+
cliEnv["ARDUINO_DIRECTORIES_BUILTIN_LIBRARIES"] = cli.DataDir().Join("libraries").String()
1525+
stdout, _, err = cli.RunWithCustomEnv(cliEnv, "lib", "install", "Firmata@2.5.3", "--install-in-builtin-dir", "-v", "--log-level", "debug")
1526+
require.NoError(t, err)
1527+
require.Contains(t, string(stdout),
1528+
"Starting download \x1b[36murl\x1b[0m=\"https://downloads.arduino.cc/libraries/github.com/firmata/Firmata-2.5.3.zip?query=install-builtin\"\n")
1529+
1530+
// Check query=update-builtin when a library dependency is updated in builtin-directory
1531+
stdout, _, err = cli.RunWithCustomEnv(cliEnv, "lib", "install", "Firmata@2.5.9", "--install-in-builtin-dir", "-v", "--log-level", "debug")
1532+
require.NoError(t, err)
1533+
require.Contains(t, string(stdout),
1534+
"Starting download \x1b[36murl\x1b[0m=\"https://downloads.arduino.cc/libraries/github.com/firmata/Firmata-2.5.9.zip?query=upgrade-builtin\"\n")
15211535
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.