pytoolbox.argparse module¶
Module related to parsing arguments from the command-line.
Example usage
>>> import argparse
>>> from pathlib import Path
>>> parser = argparse.ArgumentParser(
... formatter_class=argparse.ArgumentDefaultsHelpFormatter,
... epilog='My super cool software.')
>>> x = parser.add_argument('directory', action=FullPaths, type=is_dir)
>>> str(parser.parse_args(['/usr/lib']).directory)
'/usr/lib'
>>> assert parser.parse_args(['.']).directory == Path(os.getcwd()).expanduser().resolve()
>>> parser.parse_args(['/does_not_exist/'])
Traceback (most recent call last):
...
SystemExit: 2
- class pytoolbox.argparse.HelpFormatter(prog, indent_increment=2, max_help_position=24, width=None)[source]¶
Bases:
ArgumentDefaultsHelpFormatter
,RawDescriptionHelpFormatter
- pytoolbox.argparse.is_dir(path: str | Path) Path [source]¶
Check if path is an actual directory and return it.
- pytoolbox.argparse.multiple(func)[source]¶
Return a list with the result of `func`(value) for value in values.
- class pytoolbox.argparse.HelpArgumentParser(*args, **kwargs)[source]¶
Bases:
ArgumentParser
- pytoolbox.argparse.is_file(path: str | Path) Path [source]¶
Check if path is an actual file and return it.