MCPcopy Index your code
hub / github.com/python-cmd2/cmd2 / get_exes_in_path

Function get_exes_in_path

cmd2/utils.py:363–390  ·  view source on GitHub ↗

Return names of executables in a user's path. :param starts_with: what the exes should start with. leave blank for all exes in path. :return: a list of matching exe names

(starts_with: str)

Source from the content-addressed store, hash-verified

361
362
363def get_exes_in_path(starts_with: str) -> list[str]:
364 """Return names of executables in a user's path.
365
366 :param starts_with: what the exes should start with. leave blank for all exes in path.
367 :return: a list of matching exe names
368 """
369 # Purposely don't match any executable containing wildcards
370 wildcards = ["*", "?"]
371 for wildcard in wildcards:
372 if wildcard in starts_with:
373 return []
374
375 # Get a list of every directory in the PATH environment variable and ignore symbolic links
376 env_path = os.getenv("PATH")
377 paths = [] if env_path is None else [p for p in env_path.split(os.path.pathsep) if not os.path.islink(p)]
378
379 # Use a set to store exe names since there can be duplicates
380 exes_set = set()
381
382 # Find every executable file in the user's path that matches the pattern
383 for path in paths:
384 full_path = os.path.join(path, starts_with)
385 matches = files_from_glob_pattern(full_path + "*", access=os.X_OK)
386
387 for match in matches:
388 exes_set.add(os.path.basename(match))
389
390 return list(exes_set)
391
392
393class StdSim:

Callers

nothing calls this directly

Calls 2

files_from_glob_patternFunction · 0.85
addMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…