argument_parser.py 1.37 KB
Newer Older
1 2
import argparse
import os
3
import sys
4
from typing import Tuple
5

6 7 8
from docker_ascii_map import __version__


9 10 11 12 13 14 15 16 17 18 19 20 21 22
# This code is taken from Django
def supports_color():
    """
    Returns True if the running system's terminal supports color, and False
    otherwise.
    """
    plat = sys.platform
    supported_platform = plat != 'Pocket PC' and (plat != 'win32' or 'ANSICON' in os.environ)
    # isatty is not always implemented, #6223.
    is_a_tty = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty()
    if not supported_platform or not is_a_tty:
        return False
    return True

23

24 25 26 27 28
def get_input_parameters() -> Tuple[bool]:
    parser = argparse.ArgumentParser(description='Display the docker host contents on a visual map.')
    parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + __version__)
    parser.add_argument('-c', '--color', action='store_const', const='color', help='Use color in map display')
    parser.add_argument('-m', '--mono', action='store_const', const='mono', help='Render the map in monochrome')
29 30
    parser.add_argument('-f', '--follow', action='store_const', const='follow',
                        help='Follow status changes continuously')
31 32

    args = parser.parse_args()
33
    color_mode = supports_color()
34 35 36 37 38 39 40

    if args.color:
        color_mode = True

    if args.mono:
        color_mode = False

41
    return color_mode, args.follow is not None