class Command(object):
    def execute(self, stack_name, iam_capability=False, session=None):
        self.process()
        params = self.params_args_dict
        self._runner = Runner(self.template, stack_name=stack_name,
                params=params, iam_capability=iam_capability, session=session)
        self._runner.perform()

    @property
    def parser(self):
        if not hasattr(self, "_parser"):
            self._parser = argparse.ArgumentParser(description=self.template.description)
        return self._parser

    @parser.setter
    def parser(self, value):
        self._parser = value

    @property
    def parsed_args(self):
        self.set_params_args_in_parser()
        return vars(self.parser.parse_args())

    @property
    def params_args_dict(self):
        result = {}
        for (k,v) in self.parsed_args.items():
            altk = re.sub("_","-",k)
            title = self.args_to_params.get(altk, None)
            if title:
                result[title] = v
        return result

    @staticmethod
    def param_to_dict(p):
        default = p.properties.get("Default", None)
        required = not bool(default)
        help=p.properties["Description"]
        return dict(default=p.properties.get("Default", None),
                required=not(bool(default)),
                help=help)

    def set_params_args_in_parser(self):
        if not getattr(self, "args_to_params", None):
            self.args_to_params = {}

        for p in self.cfparams:
            dashed = camelcase_to_dashed(p.title)
            self.args_to_params[dashed]=p.title
            dashed_arg = "--{}".format(dashed)
            self.parser.add_argument(dashed_arg, **self.param_to_dict(p))
class Command(object):
    def execute(self, stack_name, iam_capability=False):
        self.process()
        params = self.parse_args()
        self._runner = Runner(self.template, stack_name=stack_name,
                params=params, iam_capability=iam_capability)
        self._runner.perform()

    def parse_args(self):
        self.args_to_params = {}
        parser = argparse.ArgumentParser(description=self.template.description)
        for p in self.cfparams:
            dashed = camelcase_to_dashed(p.title)
            self.args_to_params[dashed]=p.title
            default = p.properties.get("Default", None)
            required = not bool(default)
            dashed_arg = "--{}".format(dashed)
            parser.add_argument(dashed_arg, help=p.properties["Description"],
                    required=required, default=default)
        args = vars(parser.parse_args())
        return {self.args_to_params[re.sub("_","-",k)]: v for (k,v) in args.items()}