# Path: catkin_tools/common.py
# def is_tty(stream):
#     """Returns True if the given stream is a tty, else False"""
#     return hasattr(stream, 'isatty') and stream.isatty()
# 
# Path: catkin_tools/config.py
# def get_verb_aliases(path=catkin_config_path):
#     if not os.path.isdir(path):
#         raise RuntimeError(
#             "Cannot get verb aliases because the catkin config path ('{0}') does not exist or is a file."
#             .format(path))
#     verb_aliases_path = os.path.join(path, 'verb_aliases')
#     if not os.path.isdir(verb_aliases_path):
#         raise RuntimeError(
#             "Cannot get verb aliases because the verb aliases config path ('{0}') does not exist or is a file."
#             .format(verb_aliases_path))
#     verb_aliases = {}
#     for file_name in sorted(os.listdir(verb_aliases_path)):
#         if file_name.endswith('.yaml'):
#             full_path = os.path.join(verb_aliases_path, file_name)
#             with open(full_path, 'r') as f:
#                 yaml_dict = yaml.safe_load(f)
#             if yaml_dict is None:
#                 continue
#             if not isinstance(yaml_dict, dict):
#                 raise RuntimeError("Invalid alias file ('{0}'), expected a dict but got a {1}"
#                                    .format(full_path, type(yaml_dict)))
#             for key, value in yaml_dict.items():
#                 if not isinstance(key, str):
#                     raise RuntimeError("Invalid alias in file ('{0}'), expected a string but got '{1}' of type {2}"
#                                        .format(full_path, key, type(key)))
#                 parsed_value = None
#                 if isinstance(value, str):
#                     # Parse using shlex
#                     parsed_value = cmd_split(value)
#                 elif isinstance(value, list) or isinstance(value, type(None)):
#                     # Take plainly
#                     parsed_value = value
#                 else:
#                     raise RuntimeError(
#                         "Invalid alias expansion in file ('{0}'), expected a string or a list but got '{1}' of type {2}"
#                         .format(full_path, value, type(value)))
#                 verb_aliases[key] = parsed_value
#     for alias, value in dict(verb_aliases).items():
#         if not value:
#             del verb_aliases[alias]
#     return verb_aliases
# 
# Path: catkin_tools/config.py
# def initialize_config(path=catkin_config_path):
#     # Assert that the config path exists, otherwise try to create it
#     if not os.path.isdir(path):
#         if os.path.isfile(path):
#             raise RuntimeError("The catkin config directory ('{0}') exists, but is a file."
#                                .format(path))
#         os.makedirs(path)
#     # Initialize the verbs
#     initialize_verb_aliases(path)
# 
# Path: catkin_tools/terminal_color.py
# def fmt(msg, reset=True):
#     """Replaces color annotations with ansi escape sequences"""
#     global _ansi
#     msg = msg.replace('@!', '@{boldon}')
#     msg = msg.replace('@/', '@{italicson}')
#     msg = msg.replace('@_', '@{ulon}')
#     msg = msg.replace('@|', '@{reset}')
#     t = ColorTemplate(msg)
#     return t.substitute(_ansi) + (ansi('reset') if reset else '')
# 
# Path: catkin_tools/terminal_color.py
# def set_color(state):
#     """Sets the global colorization setting.
# 
#     Setting this to False will cause all ansi colorization sequences to get
#     replaced with empty strings.
# 
#     :parma state: colorization On or Off, True or False respectively
#     :type state: bool
#     """
#     global _color_on
#     if state:
#         enable_ANSI_colors()
#         _color_on = True
#     else:
#         disable_ANSI_colors()
#         _color_on = False
# 
# Path: catkin_tools/terminal_color.py
# def test_colors():
#     def cprint(msg):
#         print(fmt(msg))
# 
#     cprint("| @{kf}Black      @|| @!@{kf}Black Bold")
#     cprint("| @{rf}Red        @|| @!@{rf}Red Bold")
#     cprint("| @{gf}Green      @|| @!@{gf}Green Bold")
#     cprint("| @{yf}Yellow     @|| @!@{yf}Yellow Bold")
#     cprint("| @{bf}Blue       @|| @!@{bf}Blue Bold")
#     cprint("| @{pf}Purple     @|| @!@{pf}Purple Bold")
#     cprint("| @{cf}Cyan       @|| @!@{cf}Cyan Bold")
#     cprint("| White      | @!White Bold")


import argparse
import os
import pkg_resources
import sys
from datetime import date
from shlex import quote as cmd_quote
from catkin_tools.common import is_tty
from catkin_tools.config import get_verb_aliases
from catkin_tools.config import initialize_config
from catkin_tools.terminal_color import fmt
from catkin_tools.terminal_color import set_color
from catkin_tools.terminal_color import test_colors
        if 'argument_preprocessor' in desc:
            argument_preprocessors[verb] = desc['argument_preprocessor']
        else:
            argument_preprocessors[verb] = default_argument_preprocessor

    return argument_preprocessors


def expand_one_verb_alias(sysargs, verb_aliases, used_aliases):
    """Iterate through sysargs looking for expandable verb aliases.

    When a verb alias is found, sysargs is modified to effectively expand the alias.
    The alias is removed from verb_aliases and added to used_aliases.
    After finding and expanding an alias, this function returns True.
    If no alias is found to be expanded, this function returns False.
    """
    cmd = os.path.basename(sys.argv[0])
    for index, arg in enumerate(sysargs):
        if arg.startswith('-'):
            # Not a verb, continue through the arguments
            continue
        if arg in used_aliases:
            print(fmt(
                "@!@{gf}==>@| Expanding alias '@!@{yf}" + arg +
                "@|' was previously expanded, ignoring this time to prevent infinite recursion."
            ))
        if arg in verb_aliases:
            before = [] if index == 0 else sysargs[:index - 1]
            after = [] if index == len(sysargs) else sysargs[index + 1:]
            sysargs[:] = before + verb_aliases[arg] + after

# Path: catkin_tools/common.py
# def is_tty(stream):
#     """Returns True if the given stream is a tty, else False"""
#     return hasattr(stream, 'isatty') and stream.isatty()
# 
# Path: catkin_tools/config.py
# def get_verb_aliases(path=catkin_config_path):
#     if not os.path.isdir(path):
#         raise RuntimeError(
#             "Cannot get verb aliases because the catkin config path ('{0}') does not exist or is a file."
#             .format(path))
#     verb_aliases_path = os.path.join(path, 'verb_aliases')
#     if not os.path.isdir(verb_aliases_path):
#         raise RuntimeError(
#             "Cannot get verb aliases because the verb aliases config path ('{0}') does not exist or is a file."
#             .format(verb_aliases_path))
#     verb_aliases = {}
#     for file_name in sorted(os.listdir(verb_aliases_path)):
#         if file_name.endswith('.yaml'):
#             full_path = os.path.join(verb_aliases_path, file_name)
#             with open(full_path, 'r') as f:
#                 yaml_dict = yaml.safe_load(f)
#             if yaml_dict is None:
#                 continue
#             if not isinstance(yaml_dict, dict):
#                 raise RuntimeError("Invalid alias file ('{0}'), expected a dict but got a {1}"
#                                    .format(full_path, type(yaml_dict)))
#             for key, value in yaml_dict.items():
#                 if not isinstance(key, str):
#                     raise RuntimeError("Invalid alias in file ('{0}'), expected a string but got '{1}' of type {2}"
#                                        .format(full_path, key, type(key)))
#                 parsed_value = None
#                 if isinstance(value, str):
#                     # Parse using shlex
#                     parsed_value = cmd_split(value)
#                 elif isinstance(value, list) or isinstance(value, type(None)):
#                     # Take plainly
#                     parsed_value = value
#                 else:
#                     raise RuntimeError(
#                         "Invalid alias expansion in file ('{0}'), expected a string or a list but got '{1}' of type {2}"
#                         .format(full_path, value, type(value)))
#                 verb_aliases[key] = parsed_value
#     for alias, value in dict(verb_aliases).items():
#         if not value:
#             del verb_aliases[alias]
#     return verb_aliases
# 
# Path: catkin_tools/config.py
# def initialize_config(path=catkin_config_path):
#     # Assert that the config path exists, otherwise try to create it
#     if not os.path.isdir(path):
#         if os.path.isfile(path):
#             raise RuntimeError("The catkin config directory ('{0}') exists, but is a file."
#                                .format(path))
#         os.makedirs(path)
#     # Initialize the verbs
#     initialize_verb_aliases(path)
# 
# Path: catkin_tools/terminal_color.py
# def fmt(msg, reset=True):
#     """Replaces color annotations with ansi escape sequences"""
#     global _ansi
#     msg = msg.replace('@!', '@{boldon}')
#     msg = msg.replace('@/', '@{italicson}')
#     msg = msg.replace('@_', '@{ulon}')
#     msg = msg.replace('@|', '@{reset}')
#     t = ColorTemplate(msg)
#     return t.substitute(_ansi) + (ansi('reset') if reset else '')
# 
# Path: catkin_tools/terminal_color.py
# def set_color(state):
#     """Sets the global colorization setting.
# 
#     Setting this to False will cause all ansi colorization sequences to get
#     replaced with empty strings.
# 
#     :parma state: colorization On or Off, True or False respectively
#     :type state: bool
#     """
#     global _color_on
#     if state:
#         enable_ANSI_colors()
#         _color_on = True
#     else:
#         disable_ANSI_colors()
#         _color_on = False
# 
# Path: catkin_tools/terminal_color.py
# def test_colors():
#     def cprint(msg):
#         print(fmt(msg))
# 
#     cprint("| @{kf}Black      @|| @!@{kf}Black Bold")
#     cprint("| @{rf}Red        @|| @!@{rf}Red Bold")
#     cprint("| @{gf}Green      @|| @!@{gf}Green Bold")
#     cprint("| @{yf}Yellow     @|| @!@{yf}Yellow Bold")
#     cprint("| @{bf}Blue       @|| @!@{bf}Blue Bold")
#     cprint("| @{pf}Purple     @|| @!@{pf}Purple Bold")
#     cprint("| @{cf}Cyan       @|| @!@{cf}Cyan Bold")
#     cprint("| White      | @!White Bold")


# Path: catkin_tools/commands/catkin.py
import argparse
import os
import pkg_resources
import sys
from datetime import date
from shlex import quote as cmd_quote
from catkin_tools.common import is_tty
from catkin_tools.config import get_verb_aliases
from catkin_tools.config import initialize_config
from catkin_tools.terminal_color import fmt
from catkin_tools.terminal_color import set_color
from catkin_tools.terminal_color import test_colors

        if 'argument_preprocessor' in desc:
            argument_preprocessors[verb] = desc['argument_preprocessor']
        else:
            argument_preprocessors[verb] = default_argument_preprocessor

    return argument_preprocessors


def expand_one_verb_alias(sysargs, verb_aliases, used_aliases):
    """Iterate through sysargs looking for expandable verb aliases.

    When a verb alias is found, sysargs is modified to effectively expand the alias.
    The alias is removed from verb_aliases and added to used_aliases.
    After finding and expanding an alias, this function returns True.
    If no alias is found to be expanded, this function returns False.
    """
    cmd = os.path.basename(sys.argv[0])
    for index, arg in enumerate(sysargs):
        if arg.startswith('-'):
            # Not a verb, continue through the arguments
            continue
        if arg in used_aliases:
            print(fmt(
                "@!@{gf}==>@| Expanding alias '@!@{yf}" + arg +
                "@|' was previously expanded, ignoring this time to prevent infinite recursion."
            ))
        if arg in verb_aliases:
            before = [] if index == 0 else sysargs[:index - 1]
            after = [] if index == len(sysargs) else sysargs[index + 1:]
            sysargs[:] = before + verb_aliases[arg] + after

            print(fmt(