add list workspace
This commit is contained in:
parent
f94f3a7c43
commit
9c9d7dc14b
2 changed files with 30 additions and 4 deletions
|
@ -437,6 +437,26 @@ class Terraform:
|
||||||
global_opts = self._generate_default_general_options(False)
|
global_opts = self._generate_default_general_options(False)
|
||||||
return self.cmd(global_opts, "workspace", "show", **kwargs)
|
return self.cmd(global_opts, "workspace", "show", **kwargs)
|
||||||
|
|
||||||
|
def list_workspace(self) -> List[str]:
|
||||||
|
"""List of workspaces
|
||||||
|
|
||||||
|
:return: workspaces
|
||||||
|
:example:
|
||||||
|
>>> tf = Terraform()
|
||||||
|
>>> tf.list_workspace()
|
||||||
|
['default', 'test']
|
||||||
|
"""
|
||||||
|
global_opts = self._generate_default_general_options(False)
|
||||||
|
return list(
|
||||||
|
filter(
|
||||||
|
lambda workspace: len(workspace) > 0,
|
||||||
|
map(
|
||||||
|
lambda workspace: workspace.strip('*').strip(),
|
||||||
|
(self.cmd(global_opts, "workspace", "list")[1] or '').split()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
def _generate_default_args(self, dir_or_plan: Optional[str]) -> Sequence[str]:
|
def _generate_default_args(self, dir_or_plan: Optional[str]) -> Sequence[str]:
|
||||||
if (self.terraform_version < 1.0 and dir_or_plan):
|
if (self.terraform_version < 1.0 and dir_or_plan):
|
||||||
return [dir_or_plan]
|
return [dir_or_plan]
|
||||||
|
|
|
@ -529,3 +529,9 @@ class TestTerraform:
|
||||||
in caplog.messages
|
in caplog.messages
|
||||||
)
|
)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def test_list_workspace(self):
|
||||||
|
tf = Terraform(working_dir=current_path)
|
||||||
|
workspaces = tf.list_workspace()
|
||||||
|
assert len(workspaces) > 0
|
||||||
|
assert 'default' in workspaces
|
||||||
|
|
Loading…
Reference in a new issue