Skip to content

Commit 5d905ed

Browse files
committed
More helpful handling of unrecognized exe/arduino_ci.rb parameters
1 parent 2d75b6c commit 5d905ed

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1919

2020
### Fixed
2121
- Fix phrasing of free-space check
22+
- Handle unrecognized command line errors in a nicer way
2223

2324
### Security
2425

exe/arduino_ci.rb

+22-10
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@
1919

2020
# Use some basic parsing to allow command-line overrides of config
2121
class Parser
22+
23+
def self.show_help(opts)
24+
puts opts
25+
puts
26+
puts "Additionally, the following environment variables control the script:"
27+
puts " - #{VAR_CUSTOM_INIT_SCRIPT} - if set, this script will be run from the Arduino/libraries directory"
28+
puts " prior to any automated library installation or testing (e.g. to install unofficial libraries)"
29+
puts " - #{VAR_USE_SUBDIR} - if set, the script will install the library from this subdirectory of the cwd"
30+
puts " - #{VAR_EXPECT_EXAMPLES} - if set, testing will fail if no example sketches are present"
31+
puts " - #{VAR_EXPECT_UNITTESTS} - if set, testing will fail if no unit tests are present"
32+
end
33+
2234
def self.parse(options)
2335
unit_config = {}
2436
output_options = {
@@ -58,19 +70,19 @@ def self.parse(options)
5870
end
5971

6072
opts.on("-h", "--help", "Prints this help") do
61-
puts opts
62-
puts
63-
puts "Additionally, the following environment variables control the script:"
64-
puts " - #{VAR_CUSTOM_INIT_SCRIPT} - if set, this script will be run from the Arduino/libraries directory"
65-
puts " prior to any automated library installation or testing (e.g. to install unofficial libraries)"
66-
puts " - #{VAR_USE_SUBDIR} - if set, the script will install the library from this subdirectory of the cwd"
67-
puts " - #{VAR_EXPECT_EXAMPLES} - if set, testing will fail if no example sketches are present"
68-
puts " - #{VAR_EXPECT_UNITTESTS} - if set, testing will fail if no unit tests are present"
73+
show_help(opts)
6974
exit
7075
end
7176
end
7277

73-
opt_parser.parse!(options)
78+
begin
79+
opt_parser.parse!(options)
80+
rescue OptionParser::InvalidOption => e
81+
puts e
82+
puts
83+
show_help(opt_parser)
84+
exit 1
85+
end
7486
output_options
7587
end
7688
end
@@ -585,7 +597,7 @@ def perform_example_compilation_tests(cpp_library, config)
585597
#
586598

587599
# Read in command line options and make them read-only
588-
@cli_options = (Parser.parse ARGV).freeze
600+
@cli_options = Parser.parse(ARGV).freeze
589601

590602
@log = ArduinoCI::Logger.auto_width
591603
@log.banner

0 commit comments

Comments
 (0)