argtools
- Argparser fun
Parser types for command-line options, arguments and sub-commands
- class torxtools.argtools.is_dir(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)
Returns path if path is an existing regular directory. This follows symbolic links
Example
parser.add_argument( "-d", "--dir" action=argtools.is_dir )
- class torxtools.argtools.is_file(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)
Returns path if path is an existing regular file. This follows symbolic links
Example
parser.add_argument( "-f", "--file" action=argtools.is_file )
- class torxtools.argtools.is_file_and_not_dir(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)
Path must exist and be a file and not a directory.
Example
parser.add_argument( "-f", "--file" action=argtools.is_file_and_not_dir )
- torxtools.argtools.is_int_between(minv, maxv)
Verify that argument passed is between minv and maxv (inclusive)
Example
parser.add_argument( "--percent", help="Percentage (0 to 100)", action=argtools.is_int_between(0, 100), default=50, )
- class torxtools.argtools.is_int_negative(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)
Verify that argument passed is a negative integer.
Example
parser.add_argument( "--temperature", "-t", dest="temperature", help="[C] Temperature colder than freezing point", action=argtools.is_int_negative, default=-50, )
- class torxtools.argtools.is_int_negative_or_zero(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)
Verify that argument passed is a negative integer or zero.
Example
parser.add_argument( "--temperature", "-t", dest="temperature", help="[C] Temperature colder than freezing point", action=argtools.is_int_negative_or_zero, default=-50, )
- class torxtools.argtools.is_int_positive(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)
Verify that argument passed is a positive integer.
Example
parser.add_argument( "--size", "-s", dest="size", help="[MB] Minimal size of attachment", action=argtools.is_int_positive, default=100, )
- class torxtools.argtools.is_int_positive_or_zero(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)
Verify that argument passed is a positive integer or zero.
Example
parser.add_argument( "--size", "-s", dest="size", help="[MB] Minimal size of attachment", action=argtools.is_int_positive_or_zero, default=100, )
- class torxtools.argtools.is_not_dir(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)
- Deprecated:
Since 1.1.3
Use is_file_and_not_dir instead. In the next minor version, this function will only check that it’s not a directory, a no longer check if it’s a file or not
Example
parser.add_argument( "-f", "--file" action=argtools.is_not_dir )