# Path: catkin_tools/common.py
# def format_env_dict(environ, human_readable=True):
#     """Format an environment dict for printing to console similarly to `typeset` builtin."""
# 
#     if human_readable:
#         separator = '\n'
#     else:
#         separator = '\x00'
#     return separator.join([
#         '{}={}'.format(k, v)
#         for k, v in environ.items()
#     ])
# 
# Path: catkin_tools/common.py
# def parse_env_str(environ_str):
#     """Parse a quoted environment string generated by format_env_dict, or `typeset` builtin.
# 
#     environ_str must be encoded in utf-8
#     """
#     variables = environ_str.decode().rstrip('\x00').split('\x00')
#     environment = {}
#     for v in variables:
#         try:
#             key, value = v.split('=', 1)
#             environment[key] = value
#         except ValueError:
#             print('WARNING: Could not parse env string: `{}`'.format(v),
#                   file=sys.stderr)
#     return environment


import os
import re
import sys
from osrf_pycommon.process_utils import execute_process
from catkin_tools.common import format_env_dict
from catkin_tools.common import parse_env_str
        env_match = re.match('(.+?)=(.+)', arg)
        if env_match is not None and len(env_match.groups()) == 2:
            envs.update(dict([env_match.groups()]))
            raw_args.pop(0)
        else:
            # Done parsing envs
            break

    # Get command
    cmd = raw_args

    extras = {
        'envs': envs,
        'cmd': cmd,
    }

    return args, extras


def main(opts):

    environ = {}

    # Get the initial environment
    if not opts.ignore_environment:
        environ.update(os.environ)

    # Update environment from stdin
    if opts.stdin:
        input_env_str = sys.stdin.read().strip()

# Path: catkin_tools/common.py
# def format_env_dict(environ, human_readable=True):
#     """Format an environment dict for printing to console similarly to `typeset` builtin."""
# 
#     if human_readable:
#         separator = '\n'
#     else:
#         separator = '\x00'
#     return separator.join([
#         '{}={}'.format(k, v)
#         for k, v in environ.items()
#     ])
# 
# Path: catkin_tools/common.py
# def parse_env_str(environ_str):
#     """Parse a quoted environment string generated by format_env_dict, or `typeset` builtin.
# 
#     environ_str must be encoded in utf-8
#     """
#     variables = environ_str.decode().rstrip('\x00').split('\x00')
#     environment = {}
#     for v in variables:
#         try:
#             key, value = v.split('=', 1)
#             environment[key] = value
#         except ValueError:
#             print('WARNING: Could not parse env string: `{}`'.format(v),
#                   file=sys.stderr)
#     return environment


# Path: catkin_tools/verbs/catkin_env/cli.py
import os
import re
import sys
from osrf_pycommon.process_utils import execute_process
from catkin_tools.common import format_env_dict
from catkin_tools.common import parse_env_str

        env_match = re.match('(.+?)=(.+)', arg)
        if env_match is not None and len(env_match.groups()) == 2:
            envs.update(dict([env_match.groups()]))
            raw_args.pop(0)
        else:
            # Done parsing envs
            break

    # Get command
    cmd = raw_args

    extras = {
        'envs': envs,
        'cmd': cmd,
    }

    return args, extras


def main(opts):

    environ = {}

    # Get the initial environment
    if not opts.ignore_environment:
        environ.update(os.environ)

    # Update environment from stdin
    if opts.stdin:
        input_env_str = sys.stdin.read().strip()

        environ.update(parse_env_str(input_env_str.encode()))