Skip to content

Commit 48b3b0f

Browse files
thorsten-kleinpdgendt
authored andcommitted
add support for '--list-search-paths'
This flag prints all search paths for config files (contains also files that do not exist).
1 parent 046f64c commit 48b3b0f

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

src/west/app/config.py

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,11 @@
5454
to contain all paths (separated by 'os.pathsep', which is ';' on Windows or
5555
':' otherwise): Latter configuration files have precedence in such lists.
5656
57-
The following command prints a list of all configuration files currently
58-
considered and existing (listed in the order as they are loaded):
57+
To list all configuration files searched by west config, in the order as they
58+
are looked up:
59+
west config --list-search-paths
60+
61+
To list only existing configs (listed in the order as they are loaded):
5962
west config --list-paths
6063
6164
To get the value for config option <name>, type:
@@ -118,7 +121,12 @@ def do_add_parser(self, parser_adder):
118121
group.add_argument(
119122
'--list-paths',
120123
action='store_true',
121-
help='list all config files that are currently considered by west config',
124+
help='list paths of existing config files currently used by west config',
125+
)
126+
group.add_argument(
127+
'--list-search-paths',
128+
action='store_true',
129+
help='list search paths for west config files',
122130
)
123131
group.add_argument(
124132
'-l', '--list', action='store_true', help='list all options and their values'
@@ -171,17 +179,28 @@ def do_add_parser(self, parser_adder):
171179

172180
def do_run(self, args, user_args):
173181
delete = args.delete or args.delete_all
174-
if args.list:
182+
if any([args.list, args.list_paths, args.list_search_paths]):
175183
if args.name:
176-
self.parser.error('-l cannot be combined with name argument')
177-
elif not args.name and not args.list_paths:
184+
self.parser.error(
185+
(
186+
'-l'
187+
if args.list
188+
else '--list-paths'
189+
if args.list_paths
190+
else '--list-search-paths'
191+
)
192+
+ ' cannot be combined with name argument'
193+
)
194+
elif not args.name:
178195
self.parser.error('missing argument name (to list all options and values, use -l)')
179196
elif args.append:
180197
if args.value is None:
181198
self.parser.error('-a requires both name and value')
182199

183200
if args.list_paths:
184201
self.list_paths(args)
202+
elif args.list_search_paths:
203+
self.list_search_paths(args)
185204
elif args.list:
186205
self.list(args)
187206
elif delete:
@@ -198,6 +217,11 @@ def list_paths(self, args):
198217
for config_path in config_paths:
199218
self.inf(config_path)
200219

220+
def list_search_paths(self, args):
221+
search_paths = self.config.get_search_paths(args.configfile or ALL)
222+
for search_path in search_paths:
223+
self.inf(search_path)
224+
201225
def list(self, args):
202226
what = args.configfile or ALL
203227
for option, value in self.config.items(configfile=what):

tests/test_config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ def test_config_list_paths_env(location):
127127

128128

129129
def test_config_list_paths():
130+
_, err_msg = cmd_raises('config --list-paths pytest.foo', SystemExit)
131+
assert '--list-paths cannot be combined with name argument' in err_msg
132+
130133
WEST_CONFIG_LOCAL = os.environ['WEST_CONFIG_LOCAL']
131134
WEST_CONFIG_GLOBAL = os.environ['WEST_CONFIG_GLOBAL']
132135
WEST_CONFIG_SYSTEM = os.environ['WEST_CONFIG_SYSTEM']

0 commit comments

Comments
 (0)