Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added --install-in-builtin-dir flag to lib install command #2077

Merged
merged 3 commits into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions commands/lib/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ func LibraryInstall(ctx context.Context, req *rpc.LibraryInstallRequest, downloa
if installTask.ReplacedLib != nil {
downloadReason = "upgrade"
}
if installLocation == libraries.IDEBuiltIn {
downloadReason += "-builtin"
}
}
if err := downloadLibrary(lm, libRelease, downloadCB, taskCB, downloadReason); err != nil {
return err
Expand Down
38 changes: 24 additions & 14 deletions internal/cli/lib/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,12 @@ import (
semver "go.bug.st/relaxed-semver"
)

var (
noDeps bool
noOverwrite bool
gitURL bool
zipPath bool
)

func initInstallCommand() *cobra.Command {
var noDeps bool
var noOverwrite bool
var gitURL bool
var zipPath bool
var useBuiltinLibrariesDir bool
installCommand := &cobra.Command{
Use: fmt.Sprintf("install %s[@%s]...", tr("LIBRARY"), tr("VERSION_NUMBER")),
Short: tr("Installs one or more specified libraries into the system."),
Expand All @@ -53,7 +51,9 @@ func initInstallCommand() *cobra.Command {
" " + os.Args[0] + " lib install --git-url https://github.com/arduino-libraries/WiFi101.git#0.16.0 # " + tr("for the specific version.") + "\n" +
" " + os.Args[0] + " lib install --zip-path /path/to/WiFi101.zip /path/to/ArduinoBLE.zip\n",
Args: cobra.MinimumNArgs(1),
Run: runInstallCommand,
Run: func(cmd *cobra.Command, args []string) {
runInstallCommand(args, noDeps, noOverwrite, gitURL, zipPath, useBuiltinLibrariesDir)
},
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return arguments.GetInstallableLibs(), cobra.ShellCompDirectiveDefault
},
Expand All @@ -62,10 +62,11 @@ func initInstallCommand() *cobra.Command {
installCommand.Flags().BoolVar(&noOverwrite, "no-overwrite", false, tr("Do not overwrite already installed libraries."))
installCommand.Flags().BoolVar(&gitURL, "git-url", false, tr("Enter git url for libraries hosted on repositories"))
installCommand.Flags().BoolVar(&zipPath, "zip-path", false, tr("Enter a path to zip file"))
installCommand.Flags().BoolVar(&useBuiltinLibrariesDir, "install-in-builtin-dir", false, tr("Install libraries in the IDE-Builtin directory"))
return installCommand
}

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

Expand All @@ -80,6 +81,10 @@ func runInstallCommand(cmd *cobra.Command, args []string) {
feedback.Fatal(tr("--git-url and --zip-path are disabled by default, for more information see: %v", documentationURL), feedback.ErrGeneric)
}
feedback.Print(tr("--git-url and --zip-path flags allow installing untrusted files, use it at your own risk."))

if useBuiltinLibrariesDir {
feedback.Fatal(tr("--git-url or --zip-path can't be used with --install-in-builtin-dir"), feedback.ErrGeneric)
}
}

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

for _, libRef := range libRefs {
installLocation := rpc.LibraryInstallLocation_LIBRARY_INSTALL_LOCATION_USER
if useBuiltinLibrariesDir {
installLocation = rpc.LibraryInstallLocation_LIBRARY_INSTALL_LOCATION_BUILTIN
}
libraryInstallRequest := &rpc.LibraryInstallRequest{
Instance: instance,
Name: libRef.Name,
Version: libRef.Version,
NoDeps: noDeps,
NoOverwrite: noOverwrite,
Instance: instance,
Name: libRef.Name,
Version: libRef.Version,
NoDeps: noDeps,
NoOverwrite: noOverwrite,
InstallLocation: installLocation,
}
err := lib.LibraryInstall(context.Background(), libraryInstallRequest, feedback.ProgressBar(), feedback.TaskProgress())
if err != nil {
Expand Down
14 changes: 14 additions & 0 deletions internal/integrationtest/lib/lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1518,4 +1518,18 @@ func TestLibQueryParameters(t *testing.T) {
require.NoError(t, err)
require.Contains(t, string(stdout),
"Starting download \x1b[36murl\x1b[0m=\"https://downloads.arduino.cc/libraries/github.com/arduino-libraries/WiFi101-0.16.1.zip?query=download\"\n")

// Check query=install-builtin when a library dependency is installed in builtin-directory
cliEnv := cli.GetDefaultEnv()
cliEnv["ARDUINO_DIRECTORIES_BUILTIN_LIBRARIES"] = cli.DataDir().Join("libraries").String()
stdout, _, err = cli.RunWithCustomEnv(cliEnv, "lib", "install", "Firmata@2.5.3", "--install-in-builtin-dir", "-v", "--log-level", "debug")
require.NoError(t, err)
require.Contains(t, string(stdout),
"Starting download \x1b[36murl\x1b[0m=\"https://downloads.arduino.cc/libraries/github.com/firmata/Firmata-2.5.3.zip?query=install-builtin\"\n")

// Check query=update-builtin when a library dependency is updated in builtin-directory
stdout, _, err = cli.RunWithCustomEnv(cliEnv, "lib", "install", "Firmata@2.5.9", "--install-in-builtin-dir", "-v", "--log-level", "debug")
require.NoError(t, err)
require.Contains(t, string(stdout),
"Starting download \x1b[36murl\x1b[0m=\"https://downloads.arduino.cc/libraries/github.com/firmata/Firmata-2.5.9.zip?query=upgrade-builtin\"\n")
}