From d28d3e548af0aee7af37a9f4751141ffcd6a2d84 Mon Sep 17 00:00:00 2001 From: Silvano Cerza Date: Thu, 21 Jan 2021 12:06:55 +0100 Subject: [PATCH] Add multiple libraries installation when using --git-url or --zip-path flags --- cli/lib/install.go | 51 +++++++++++++++++++++++------------------- test/test_lib.py | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 23 deletions(-) diff --git a/cli/lib/install.go b/cli/lib/install.go index 4a46300604d..9fa94dc67b0 100644 --- a/cli/lib/install.go +++ b/cli/lib/install.go @@ -40,7 +40,9 @@ func initInstallCommand() *cobra.Command { Long: "Installs one or more specified libraries into the system.", Example: "" + " " + os.Args[0] + " lib install AudioZero # for the latest version.\n" + - " " + os.Args[0] + " lib install AudioZero@1.0.0 # for the specific version.", + " " + os.Args[0] + " lib install AudioZero@1.0.0 # for the specific version.\n" + + " " + os.Args[0] + " lib install --git-url https://github.com/arduino-libraries/WiFi101.git https://github.com/arduino-libraries/ArduinoBLE.git\n" + + " " + os.Args[0] + " lib install --zip-path /path/to/WiFi101.zip /path/to/ArduinoBLE.zip\n", Args: cobra.MinimumNArgs(1), Run: runInstallCommand, } @@ -73,36 +75,39 @@ func runInstallCommand(cmd *cobra.Command, args []string) { } if installFlags.zipPath { - ziplibraryInstallReq := &rpc.ZipLibraryInstallReq{ - Instance: instance, - Path: args[0], - } - err := lib.ZipLibraryInstall(context.Background(), ziplibraryInstallReq, output.TaskProgress()) - if err != nil { - feedback.Errorf("Error installing Zip Library: %v", err) - os.Exit(errorcodes.ErrGeneric) + for _, path := range args { + ziplibraryInstallReq := &rpc.ZipLibraryInstallReq{ + Instance: instance, + Path: path, + } + err := lib.ZipLibraryInstall(context.Background(), ziplibraryInstallReq, output.TaskProgress()) + if err != nil { + feedback.Errorf("Error installing Zip Library: %v", err) + os.Exit(errorcodes.ErrGeneric) + } } return } if installFlags.gitURL { - url := args[0] - if url == "." { - wd, err := paths.Getwd() + for _, url := range args { + if url == "." { + wd, err := paths.Getwd() + if err != nil { + feedback.Errorf("Couldn't get current working directory: %v", err) + os.Exit(errorcodes.ErrGeneric) + } + url = wd.String() + } + gitlibraryInstallReq := &rpc.GitLibraryInstallReq{ + Instance: instance, + Url: url, + } + err := lib.GitLibraryInstall(context.Background(), gitlibraryInstallReq, output.TaskProgress()) if err != nil { - feedback.Errorf("Couldn't get current working directory: %v", err) + feedback.Errorf("Error installing Git Library: %v", err) os.Exit(errorcodes.ErrGeneric) } - url = wd.String() - } - gitlibraryInstallReq := &rpc.GitLibraryInstallReq{ - Instance: instance, - Url: url, - } - err := lib.GitLibraryInstall(context.Background(), gitlibraryInstallReq, output.TaskProgress()) - if err != nil { - feedback.Errorf("Error installing Git Library: %v", err) - os.Exit(errorcodes.ErrGeneric) } return } diff --git a/test/test_lib.py b/test/test_lib.py index 6dfe0495dde..b4283637f8c 100644 --- a/test/test_lib.py +++ b/test/test_lib.py @@ -540,3 +540,58 @@ def test_install_with_git_url_does_not_create_git_repo(run_command, downloads_di # Verifies installed library is not a git repository assert not Path(lib_install_dir, ".git").exists() + + +def test_install_with_git_url_multiple_libraries(run_command, downloads_dir, data_dir): + assert run_command("update") + + env = { + "ARDUINO_DATA_DIR": data_dir, + "ARDUINO_DOWNLOADS_DIR": downloads_dir, + "ARDUINO_SKETCHBOOK_DIR": data_dir, + "ARDUINO_ENABLE_UNSAFE_LIBRARY_INSTALL": "true", + } + + wifi_install_dir = Path(data_dir, "libraries", "WiFi101") + ble_install_dir = Path(data_dir, "libraries", "ArduinoBLE") + # Verifies libraries are not installed + assert not wifi_install_dir.exists() + assert not ble_install_dir.exists() + + wifi_url = "https://github.com/arduino-libraries/WiFi101.git" + ble_url = "https://github.com/arduino-libraries/ArduinoBLE.git" + + assert run_command(f"lib install --git-url {wifi_url} {ble_url}", custom_env=env) + + # Verifies library are installed + assert wifi_install_dir.exists() + assert ble_install_dir.exists() + + +def test_install_with_zip_path_multiple_libraries(run_command, downloads_dir, data_dir): + assert run_command("update") + + env = { + "ARDUINO_DATA_DIR": data_dir, + "ARDUINO_DOWNLOADS_DIR": downloads_dir, + "ARDUINO_SKETCHBOOK_DIR": data_dir, + "ARDUINO_ENABLE_UNSAFE_LIBRARY_INSTALL": "true", + } + + # Downloads zip to be installed later + assert run_command("lib download WiFi101@0.16.1") + assert run_command("lib download ArduinoBLE@1.1.3") + wifi_zip_path = Path(downloads_dir, "libraries", "WiFi101-0.16.1.zip") + ble_zip_path = Path(downloads_dir, "libraries", "ArduinoBLE-1.1.3.zip") + + wifi_install_dir = Path(data_dir, "libraries", "WiFi101-0.16.1") + ble_install_dir = Path(data_dir, "libraries", "ArduinoBLE-1.1.3") + # Verifies libraries are not installed + assert not wifi_install_dir.exists() + assert not ble_install_dir.exists() + + assert run_command(f"lib install --zip-path {wifi_zip_path} {ble_zip_path}", custom_env=env) + + # Verifies library are installed + assert wifi_install_dir.exists() + assert ble_install_dir.exists() pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy