Skip to content

Commit 7e55f9e

Browse files
authored
Add multiple libraries installation when using --git-url or --zip-path flags (#1146)
1 parent 6328430 commit 7e55f9e

File tree

2 files changed

+83
-23
lines changed

2 files changed

+83
-23
lines changed

cli/lib/install.go

+28-23
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ func initInstallCommand() *cobra.Command {
4040
Long: "Installs one or more specified libraries into the system.",
4141
Example: "" +
4242
" " + os.Args[0] + " lib install AudioZero # for the latest version.\n" +
43-
" " + os.Args[0] + " lib install [email protected] # for the specific version.",
43+
" " + os.Args[0] + " lib install [email protected] # for the specific version.\n" +
44+
" " + os.Args[0] + " lib install --git-url https://github.com/arduino-libraries/WiFi101.git https://github.com/arduino-libraries/ArduinoBLE.git\n" +
45+
" " + os.Args[0] + " lib install --zip-path /path/to/WiFi101.zip /path/to/ArduinoBLE.zip\n",
4446
Args: cobra.MinimumNArgs(1),
4547
Run: runInstallCommand,
4648
}
@@ -73,36 +75,39 @@ func runInstallCommand(cmd *cobra.Command, args []string) {
7375
}
7476

7577
if installFlags.zipPath {
76-
ziplibraryInstallReq := &rpc.ZipLibraryInstallReq{
77-
Instance: instance,
78-
Path: args[0],
79-
}
80-
err := lib.ZipLibraryInstall(context.Background(), ziplibraryInstallReq, output.TaskProgress())
81-
if err != nil {
82-
feedback.Errorf("Error installing Zip Library: %v", err)
83-
os.Exit(errorcodes.ErrGeneric)
78+
for _, path := range args {
79+
ziplibraryInstallReq := &rpc.ZipLibraryInstallReq{
80+
Instance: instance,
81+
Path: path,
82+
}
83+
err := lib.ZipLibraryInstall(context.Background(), ziplibraryInstallReq, output.TaskProgress())
84+
if err != nil {
85+
feedback.Errorf("Error installing Zip Library: %v", err)
86+
os.Exit(errorcodes.ErrGeneric)
87+
}
8488
}
8589
return
8690
}
8791

8892
if installFlags.gitURL {
89-
url := args[0]
90-
if url == "." {
91-
wd, err := paths.Getwd()
93+
for _, url := range args {
94+
if url == "." {
95+
wd, err := paths.Getwd()
96+
if err != nil {
97+
feedback.Errorf("Couldn't get current working directory: %v", err)
98+
os.Exit(errorcodes.ErrGeneric)
99+
}
100+
url = wd.String()
101+
}
102+
gitlibraryInstallReq := &rpc.GitLibraryInstallReq{
103+
Instance: instance,
104+
Url: url,
105+
}
106+
err := lib.GitLibraryInstall(context.Background(), gitlibraryInstallReq, output.TaskProgress())
92107
if err != nil {
93-
feedback.Errorf("Couldn't get current working directory: %v", err)
108+
feedback.Errorf("Error installing Git Library: %v", err)
94109
os.Exit(errorcodes.ErrGeneric)
95110
}
96-
url = wd.String()
97-
}
98-
gitlibraryInstallReq := &rpc.GitLibraryInstallReq{
99-
Instance: instance,
100-
Url: url,
101-
}
102-
err := lib.GitLibraryInstall(context.Background(), gitlibraryInstallReq, output.TaskProgress())
103-
if err != nil {
104-
feedback.Errorf("Error installing Git Library: %v", err)
105-
os.Exit(errorcodes.ErrGeneric)
106111
}
107112
return
108113
}

test/test_lib.py

+55
Original file line numberDiff line numberDiff line change
@@ -540,3 +540,58 @@ def test_install_with_git_url_does_not_create_git_repo(run_command, downloads_di
540540

541541
# Verifies installed library is not a git repository
542542
assert not Path(lib_install_dir, ".git").exists()
543+
544+
545+
def test_install_with_git_url_multiple_libraries(run_command, downloads_dir, data_dir):
546+
assert run_command("update")
547+
548+
env = {
549+
"ARDUINO_DATA_DIR": data_dir,
550+
"ARDUINO_DOWNLOADS_DIR": downloads_dir,
551+
"ARDUINO_SKETCHBOOK_DIR": data_dir,
552+
"ARDUINO_ENABLE_UNSAFE_LIBRARY_INSTALL": "true",
553+
}
554+
555+
wifi_install_dir = Path(data_dir, "libraries", "WiFi101")
556+
ble_install_dir = Path(data_dir, "libraries", "ArduinoBLE")
557+
# Verifies libraries are not installed
558+
assert not wifi_install_dir.exists()
559+
assert not ble_install_dir.exists()
560+
561+
wifi_url = "https://github.com/arduino-libraries/WiFi101.git"
562+
ble_url = "https://github.com/arduino-libraries/ArduinoBLE.git"
563+
564+
assert run_command(f"lib install --git-url {wifi_url} {ble_url}", custom_env=env)
565+
566+
# Verifies library are installed
567+
assert wifi_install_dir.exists()
568+
assert ble_install_dir.exists()
569+
570+
571+
def test_install_with_zip_path_multiple_libraries(run_command, downloads_dir, data_dir):
572+
assert run_command("update")
573+
574+
env = {
575+
"ARDUINO_DATA_DIR": data_dir,
576+
"ARDUINO_DOWNLOADS_DIR": downloads_dir,
577+
"ARDUINO_SKETCHBOOK_DIR": data_dir,
578+
"ARDUINO_ENABLE_UNSAFE_LIBRARY_INSTALL": "true",
579+
}
580+
581+
# Downloads zip to be installed later
582+
assert run_command("lib download [email protected]")
583+
assert run_command("lib download [email protected]")
584+
wifi_zip_path = Path(downloads_dir, "libraries", "WiFi101-0.16.1.zip")
585+
ble_zip_path = Path(downloads_dir, "libraries", "ArduinoBLE-1.1.3.zip")
586+
587+
wifi_install_dir = Path(data_dir, "libraries", "WiFi101-0.16.1")
588+
ble_install_dir = Path(data_dir, "libraries", "ArduinoBLE-1.1.3")
589+
# Verifies libraries are not installed
590+
assert not wifi_install_dir.exists()
591+
assert not ble_install_dir.exists()
592+
593+
assert run_command(f"lib install --zip-path {wifi_zip_path} {ble_zip_path}", custom_env=env)
594+
595+
# Verifies library are installed
596+
assert wifi_install_dir.exists()
597+
assert ble_install_dir.exists()

0 commit comments

Comments
 (0)