Skip to content

Commit 5dcd546

Browse files
authored
Merge pull request #2393 from theotherjimmy/argument-dependencies
[tools] Prevent trace-backs from incomplete args
2 parents fbf535b + 163fa59 commit 5dcd546

File tree

6 files changed

+31
-14
lines changed

6 files changed

+31
-14
lines changed

tools/build.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
from tools.build_api import static_analysis_scan, static_analysis_scan_lib, static_analysis_scan_library
3737
from tools.build_api import print_build_results
3838
from tools.settings import CPPCHECK_CMD, CPPCHECK_MSG_FORMAT
39-
from utils import argparse_filestring_type
39+
from utils import argparse_filestring_type, args_error
4040
from tools.settings import CPPCHECK_CMD, CPPCHECK_MSG_FORMAT, CLI_COLOR_MAP
4141
from utils import argparse_filestring_type, argparse_dir_not_parent
4242

@@ -167,6 +167,9 @@
167167
# Get toolchains list
168168
toolchains = options.tool if options.tool else TOOLCHAINS
169169

170+
if options.source_dir and not options.build_dir:
171+
args_error(parser, "argument --build is required by argument --source")
172+
170173
if options.color:
171174
# This import happens late to prevent initializing colorization when we don't need it
172175
import colorize

tools/get_config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
if __name__ == '__main__':
3838
# Parse Options
3939
parser = get_default_options_parser(add_clean=False, add_options=False)
40-
parser.add_argument("--source", dest="source_dir", type=argparse_filestring_type,
40+
parser.add_argument("--source", dest="source_dir", type=argparse_filestring_type, required=True,
4141
default=[], help="The source (input) directory", action="append")
4242
parser.add_argument("--prefix", dest="prefix", action="append",
4343
default=[], help="Restrict listing to parameters that have this prefix")
@@ -48,12 +48,12 @@
4848

4949
# Target
5050
if options.mcu is None :
51-
args_error(parser, "[ERROR] You should specify an MCU")
51+
args_error(parser, "argument -m/--mcu is required")
5252
target = options.mcu[0]
5353

5454
# Toolchain
5555
if options.tool is None:
56-
args_error(parser, "[ERROR] You should specify a TOOLCHAIN")
56+
args_error(parser, "argument -t/--toolchain is required")
5757
toolchain = options.tool[0]
5858

5959
options.prefix = options.prefix or [""]

tools/make.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,14 +207,20 @@
207207

208208
# Target
209209
if options.mcu is None :
210-
args_error(parser, "[ERROR] You should specify an MCU")
210+
args_error(parser, "argument -m/--mcu is required")
211211
mcu = options.mcu[0]
212212

213213
# Toolchain
214214
if options.tool is None:
215-
args_error(parser, "[ERROR] You should specify a TOOLCHAIN")
215+
args_error(parser, "argument -t/--tool is required")
216216
toolchain = options.tool[0]
217217

218+
if (options.program is None) and (not options.source_dir):
219+
args_error(parser, "one of -p, -n, or --source is required")
220+
221+
if options.source_dir and not options.build_dir:
222+
args_error(parser, "argument --build is required when argument --source is provided")
223+
218224
if options.color:
219225
# This import happens late to prevent initializing colorization when we don't need it
220226
import colorize

tools/project.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from tools.tests import test_known, test_name_known
1414
from tools.targets import TARGET_NAMES
1515
from tools.libraries import LIBRARIES
16-
from utils import argparse_filestring_type, argparse_many
16+
from utils import argparse_filestring_type, argparse_many, args_error
1717
from utils import argparse_force_lowercase_type, argparse_force_uppercase_type, argparse_dir_not_parent
1818
from project_api import setup_project, perform_export, print_results, get_lib_symbols
1919

@@ -131,6 +131,16 @@
131131

132132
# source_dir = use relative paths, otherwise sources are copied
133133
sources_relative = True if options.source_dir else False
134+
# Target
135+
if not options.mcu:
136+
args_error(parser, "argument -m/--mcu is required")
137+
138+
# Toolchain
139+
if not options.ide:
140+
args_error(parser, "argument -i is required")
141+
142+
if (options.program is None) and (not options.source_dir):
143+
args_error(parser, "one of -p, -n, or --source is required")
134144

135145
for mcu in options.mcu:
136146
# Program Number or name

tools/test.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,12 @@
107107

108108
# Target
109109
if options.mcu is None :
110-
args_error(parser, "[ERROR] You should specify an MCU")
110+
args_error(parser, "argument -m/--mcu is required")
111111
mcu = options.mcu[0]
112112

113113
# Toolchain
114114
if options.tool is None:
115-
args_error(parser, "[ERROR] You should specify a TOOLCHAIN")
115+
args_error(parser, "argument -t/--tool is required")
116116
toolchain = options.tool[0]
117117

118118
# Find all tests in the relevant paths
@@ -152,8 +152,7 @@
152152
else:
153153
# Build all tests
154154
if not options.build_dir:
155-
print "[ERROR] You must specify a build path"
156-
sys.exit(1)
155+
args_error(parser, "argument --build is required")
157156

158157
base_source_paths = options.source_dir
159158

tools/utils.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,8 @@ def args_error(parser, message):
282282
parser - the ArgumentParser object that parsed the command line
283283
message - what went wrong
284284
"""
285-
print "\n\n%s\n\n" % message
286-
parser.print_help()
287-
sys.exit()
285+
parser.error(message)
286+
sys.exit(2)
288287

289288

290289
def construct_enum(**enums):

0 commit comments

Comments
 (0)