import re
from typing import Dict, List
from dataclasses import dataclass


def get_values(output_str: str) -> Dict[str, str]:
    """
    Get the dictionary representing actual value passed to the function
    """
    res_d = {}
    for line in output_str.splitlines():
        m = re.match(r'(\w+)=(.+)', line.strip())
        assert m is not None
        res_d[m.group(1)] = m.group(2)
    return res_d


@dataclass(frozen=True)
class HelpOption:
    name: str
    line: str


def get_options(help_str: str) -> List[HelpOption]:
    """
    Get the option names obtained from the help generated by glacier.

    The output will be as follows

    Options:
      --name TEXT                     Name of this operation.  [required]
      --env [development|production]  Specifying this operation is for whether dev or prod.  [required]  # noqa
      --verbose                       Verbose output will be shown if set.
      -h, --help                      Show this message and exit.
    """
    options_found = False
    res: List[HelpOption] = []
    for line in help_str.splitlines():
        if line.startswith('Options'):
            options_found = True
            continue
        if options_found:
            if line.startswith('  '):
                m = re.search(r'^  --([\w-]+)', line)
                if m is None:
                    continue
                option_name = m.group(1)
                res.append(
                    HelpOption(
                        name=option_name,
                        line=line.strip(),
                    )
                )
            else:
                options_found = False
    return res
