Skip to content

Commit 5550e43

Browse files
committed
ArduinoBackend.library_available?() to check whether libraries exist
1 parent 88a6528 commit 5550e43

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1818
- `shiftIn()` and `shiftOut()`
1919
- `CIConfig.is_default` to detect when the default configuration is used
2020
- `ArduinoBackend.boards_installed?` to detect whether a board family (or package, like `arduino:avr`) is installed
21+
- `ArduinoBackend.library_available?` to detect whether the library manager knows of a library
2122

2223
### Changed
2324
- Rubocop expected syntax downgraded from ruby 2.6 to 2.5

lib/arduino_ci/arduino_backend.rb

+9
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,15 @@ def install_boards(boardfamily)
136136
result[:success]
137137
end
138138

139+
# Find out if a library is available
140+
#
141+
# @param name [String] the library name
142+
# @return [bool] whether the library can be installed via the library manager
143+
def library_available?(name)
144+
# the --names flag limits the size of the response to just the name field
145+
capture_json("lib", "search", "--names", name)[:json]["libraries"].any? { |l| l["name"] == name }
146+
end
147+
139148
# @return [Hash] information about installed libraries via the CLI
140149
def installed_libraries
141150
capture_json("lib", "list")[:json]

spec/arduino_backend_spec.rb

+7
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ def get_sketch(dir, file)
5656
expect(fake_lib.path).to eq(expected_dir)
5757
expect(fake_lib.installed?).to be false
5858
end
59+
60+
it "knows whether libraries exist in the manager" do
61+
expect(backend.library_available?("OneWire")).to be true
62+
63+
# TODO: replace with a less offensive library name guaranteed never to exist?
64+
expect(backend.library_available?("fuck")).to be false
65+
end
5966
end
6067

6168
context "board_manager" do

0 commit comments

Comments
 (0)