Skip to content

Commit d6196c1

Browse 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

File tree

3 files changed

+41
-14
lines changed

3 files changed

+41
-14
lines changed

Diff for: commands/lib/install.go

+3
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

Diff for: internal/cli/lib/install.go

+24-14
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 {

Diff for: internal/integrationtest/lib/lib_test.go

+14
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", "[email protected]", "--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", "[email protected]", "--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)