WarMAC Parser#
Note
Only global variables and constants that are public are documented. Please see the source code for private variable/constant documentation.
- warmac_parser.DEFAULT_TIME: int = 10#
The default time that will be used for calculating listing ages.
- class warmac_parser.CustomHelpFormat(prog: str, indent_increment: int = 2, max_help_position: int = 24, width: int | None = None)#
Bases:
RawDescriptionHelpFormatter
Custom help formatter for
warmac_parser.WarMACParser
.Extend
argparse.RawDescriptionHelpFormatter
to reimplement a few methods. Reimplementations include removing the command metavar tuples, removing the duplicate option metavars, and correcting the over-indentation on the help menu.- __init__(prog: str, indent_increment: int = 2, max_help_position: int = 24, width: int | None = None) None #
Construct a
CustomHelpFormat
object.- Parameters:
prog – The name of the program.
indent_increment – How much space should come before the options on the help screen, defaults to 2.
max_help_position – The width between
indent_increment
and the help text, defaults to 24.width – The maximum width that the help screen is able to occupy in the terminal, defaults to None.
- _format_action(action: Action) str #
Remove command metavar tuple and fix metavar indentation.
Override the
HelpFormatter._format_action
method to remove the command metavar tuple and fix the spacings between the option and its associated metavar.- Parameters:
action – The action in which to be formatted.
- Returns:
HelpFormatter._format_action(action)
. If the action is a_SubParsersAction
, the metavar tuple will be excluded, and the leading indentation will be corrected.
- _format_action_invocation(action: Action) str #
Remove duplicate metavar for options with short and long form.
Override the
HelpFormatter._format_action_invocation
method to remove the duplicate help metavar for options that have both a short-form and a long-form argument.- Parameters:
action – The action in which to be formatted.
- Returns:
The appropriately formatted string.
- _iter_indented_subactions(action: Action) Generator[Action, None, None] #
Fix leading indentation for command names in the help menu.
Override the
HelpFormatter._iter_indented_subactions
method to fix the leading indentation for command names in the help menu.- Parameters:
action – The action to be yielded from.
- Yield:
Actions from a list returned by
action._get_subactions
.
- class warmac_parser.WarMACParser(prog=None, usage=None, description=None, epilog=None, parents=[], formatter_class=HelpFormatter, prefix_chars='-', fromfile_prefix_chars=None, argument_default=None, conflict_handler='error', add_help=True, allow_abbrev=True, exit_on_error=True)#
Bases:
ArgumentParser
Extend
argparse.ArgumentParser
to reimplement the error method.Extend
argparse.ArgumentParser
to reimplement the error method so it exits with status code 2, and prints to stderr.- error(message: str) NoReturn #
Modify exit message for
argparse.ArgumentError
.Modify exit message for
argparse.ArgumentError
occurrences to print to stderr, and return an exit code of 2.- Parameters:
message – The message provided by the standard
argparse.ArgumentParser
class.- Returns:
A value is never returned by this function.
- warmac_parser._int_checking(usr_inp: str, max_val: int) int #
Return
usr_inp
as an integer if0 < usr_inp < max_val
.Cast
usr_inp
to an integer. Ifusr_inp
is not an integer or is not0 < usr_inp < max_val
, then raise anargparse.ArgumentTypeError
.- Parameters:
usr_inp – The user’s input as a string.
max_val – The maximum value that
int(usr_inp)
can be.
- Raises:
argparse.ArgumentTypeError – Raised if
usr_inp
is not an integer or is not0 < int(usr_inp) < max_val
.- Returns:
Return
usr_inp
as an integer.
- warmac_parser._create_parser() WarMACParser #
Create the command-line parser for the program.
Create a
WarMACParser
object that includes global –help and –version options. Create subparsers for multiple commands to be used within the program.- Returns:
The constructed
WarMACParser
object.
- warmac_parser.handle_input() Namespace #
Create a
WarMACParser
and parse arguments.Create
WarMACParser
object, parse command-line arguments, and return the parsed arguments as anargparse.Namespace
object. Exits early if only “warmac” is called.- Returns:
The parsed command-line arguments.