MCPcopy
hub / github.com/pallets/click / _expand_args

Function _expand_args

src/click/utils.py:604–653  ·  view source on GitHub ↗

Simulate Unix shell expansion with Python functions. See :func:`glob.glob`, :func:`os.path.expanduser`, and :func:`os.path.expandvars`. This is intended for use on Windows, where the shell does not do any expansion. It may not exactly match what a Unix shell would do. :param a

(
    args: cabc.Iterable[str],
    *,
    user: bool = True,
    env: bool = True,
    glob_recursive: bool = True,
)

Source from the content-addressed store, hash-verified

602
603
604def _expand_args(
605 args: cabc.Iterable[str],
606 *,
607 user: bool = True,
608 env: bool = True,
609 glob_recursive: bool = True,
610) -> list[str]:
611 """Simulate Unix shell expansion with Python functions.
612
613 See :func:`glob.glob`, :func:`os.path.expanduser`, and
614 :func:`os.path.expandvars`.
615
616 This is intended for use on Windows, where the shell does not do any
617 expansion. It may not exactly match what a Unix shell would do.
618
619 :param args: List of command line arguments to expand.
620 :param user: Expand user home directory.
621 :param env: Expand environment variables.
622 :param glob_recursive: ``**`` matches directories recursively.
623
624 .. versionchanged:: 8.1
625 Invalid glob patterns are treated as empty expansions rather
626 than raising an error.
627
628 .. versionadded:: 8.0
629
630 :meta private:
631 """
632 from glob import glob
633
634 out = []
635
636 for arg in args:
637 if user:
638 arg = os.path.expanduser(arg)
639
640 if env:
641 arg = os.path.expandvars(arg)
642
643 try:
644 matches = glob(arg, recursive=glob_recursive)
645 except re.error:
646 matches = []
647
648 if not matches:
649 out.append(arg)
650 else:
651 out.extend(matches)
652
653 return out

Callers 1

mainMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…