Skip to content

Commit 4410d08

Browse files
committed
Added --install-in-builtin-dir flag in 'lib install'
1 parent 70f172f commit 4410d08

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

internal/cli/lib/install.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func initInstallCommand() *cobra.Command {
3939
var noOverwrite bool
4040
var gitURL bool
4141
var zipPath bool
42+
var useBuiltinLibrariesDir bool
4243
installCommand := &cobra.Command{
4344
Use: fmt.Sprintf("install %s[@%s]...", tr("LIBRARY"), tr("VERSION_NUMBER")),
4445
Short: tr("Installs one or more specified libraries into the system."),
@@ -51,7 +52,7 @@ func initInstallCommand() *cobra.Command {
5152
" " + os.Args[0] + " lib install --zip-path /path/to/WiFi101.zip /path/to/ArduinoBLE.zip\n",
5253
Args: cobra.MinimumNArgs(1),
5354
Run: func(cmd *cobra.Command, args []string) {
54-
runInstallCommand(args, noDeps, noOverwrite, gitURL, zipPath)
55+
runInstallCommand(args, noDeps, noOverwrite, gitURL, zipPath, useBuiltinLibrariesDir)
5556
},
5657
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
5758
return arguments.GetInstallableLibs(), cobra.ShellCompDirectiveDefault
@@ -61,10 +62,11 @@ func initInstallCommand() *cobra.Command {
6162
installCommand.Flags().BoolVar(&noOverwrite, "no-overwrite", false, tr("Do not overwrite already installed libraries."))
6263
installCommand.Flags().BoolVar(&gitURL, "git-url", false, tr("Enter git url for libraries hosted on repositories"))
6364
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"))
6466
return installCommand
6567
}
6668

67-
func runInstallCommand(args []string, noDeps bool, noOverwrite bool, gitURL bool, zipPath bool) {
69+
func runInstallCommand(args []string, noDeps bool, noOverwrite bool, gitURL bool, zipPath bool, useBuiltinLibrariesDir bool) {
6870
instance := instance.CreateAndInit()
6971
logrus.Info("Executing `arduino-cli lib install`")
7072

@@ -79,6 +81,10 @@ func runInstallCommand(args []string, noDeps bool, noOverwrite bool, gitURL bool
7981
feedback.Fatal(tr("--git-url and --zip-path are disabled by default, for more information see: %v", documentationURL), feedback.ErrGeneric)
8082
}
8183
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+
}
8288
}
8389

8490
if zipPath {
@@ -122,12 +128,17 @@ func runInstallCommand(args []string, noDeps bool, noOverwrite bool, gitURL bool
122128
}
123129

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

internal/integrationtest/lib/lib_test.go

Lines 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", "[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)