Example #1
0
def stack_auto_complete(ctx, args, incomplete):
    """Autocomplete for --stack

    By default, returns qualified names start with qualified stack

    """
    import argparse
    # use argparse to extract config file name
    parser = argparse.ArgumentParser()
    parser.add_argument('--file', '-f', default=None)
    (namespace, remain) = parser.parse_known_args(args)
    config_filename = find_default_config(namespace.file)

    try:
        deployments = load_config(config_filename)
    except ConfigError as e:
        # ignore any config parsing errors
        return list()

    # get a sorted list of qualified names

    stack_names = sorted(d.stack_key.qualified_name
                         for d in deployments.query_stacks())

    # remove meta chars
    incomplete = incomplete.lower().translate({'*': '', '?': ''})
    return list((s.stack_key.qualified_name, s.parameters.StackName)
                for s in deployments.query_stacks()
                if s.stack_key.qualified_name.lower().startswith(incomplete))
def test_default_config_dir1(tmp_path):
    d = tmp_path / "config"
    d.mkdir()
    f = d / "cfn-cli.yaml"
    f.touch()
    os.chdir(tmp_path)
    assert find_default_config("config") == "config/cfn-cli.yaml"
def test_default_config_file3(tmp_path):
    f1 = tmp_path / "cfn-cli.yaml"
    f1.touch()
    f2 = tmp_path / "cfn-cli.yml"
    f2.touch()
    os.chdir(tmp_path)
    assert find_default_config() == "cfn-cli.yaml"
Example #4
0
    def build(self) -> Context:
        config_filename = find_default_config(self._opt.config_filename)

        stack_selector = StackSelector(self._opt.stack_selector)

        boto3_profile = Boto3Profile(profile_name=self._opt.profile_name,
                                     region_name=self._opt.region_name)

        pretty_printer = StackPrettyPrinter(verbosity=self._opt.verbosity)

        context = Context(
            config_filename=config_filename,
            stack_selector=stack_selector,
            boto3_profile=boto3_profile,
            pretty_printer=pretty_printer,
            artifact_store=self._opt.artifact_store,
            builder=self)

        return context
def test_default_config_empty(tmp_path):
    os.chdir(tmp_path)
    # Current behaviour is return "cfn-cli.yml" when the file does not exist.
    assert find_default_config() == "cfn-cli.yml"
def test_default_config_file2(tmp_path):
    f = tmp_path / "cfn-cli.yml"
    f.touch()
    os.chdir(tmp_path)
    assert find_default_config() == "cfn-cli.yml"